Commit Graph

241 Commits

Author SHA1 Message Date
Jan Engelhardt
aa60d00496
Fix a test failure in testNewFromString ()
Fixes an oversight in d296c2d1.
2024-06-11 20:47:53 +02:00
Jan Engelhardt
d296c2d1d5
vmime: prevent loss of a space during text::createFromString ()
```
mailbox(text("Test München West", charsets::UTF_8), "a@b.de").generate();
```

produces

```
=?us-ascii?Q?Test_?= =?utf-8?Q?M=C3=BCnchen?= =?us-ascii?Q?West?= <test@example.com>
```

The first space between ``Test`` and ``München`` is encoded as an
underscore along with the first word: ``Test_``. The second space
between ``München`` and ``West`` is encoded with neither of the two
words and thus lost. Decoding the text results in ``Test
MünchenWest`` instead of ``Test München West``.

This is caused by how ``vmime::text::createFromString()`` handles
transitions between 7-bit and 8-bit words: If an 8-bit word follows a
7-bit word, a space is appended to the previous word. The opposite
case of a 7-bit word following an 8-bit word *misses* this behaviour.

When one fixes this problem, a follow-up issue appears:

``text::createFromString("a b\xFFc d")`` tokenizes the input into
``m_words={word("a "), word("b\xFFc ", utf8), word("d")}``. This
"right-side alignment" nature of the whitespace is a problem for
word::generate():

As per RFC 2047, spaces between adjacent encoded words are just
separators but not meant to be displayed. A space between an encoded
word and a regular ASCII text is not just a separator but also meant
to be displayed.

When word::generate() outputs the b-word, it would have to strip one
space, but only when there is a transition from encoded-word to
unencoded word. word::generate() does not know whether d will be
encoded or unencoded.

The idea now is that we could change the tokenization of
``text::createFromString`` such that whitespace is at the *start* of
words rather than at the end. With that, word::generate() need not
know anything about the next word, but rather only the *previous*
one.

Thus, in this patch,

1. The tokenization of ``text::createFromString`` is changed to
   left-align spaces and the function is fixed to account for
   the missing space on transition.
2. ``word::generate`` learns how to steal a space character.
3. Testcases are adjusted to account for the shifted
   position of the space.

Fixes: , 

Co-authored-by: Vincent Richard <vincent@vincent-richard.net>
2024-05-21 15:55:06 +02:00
Jan Engelhardt
c105165c6e
tests: switch a byte sequence in textTest ()
Switch out the byte sequence by one that is simiarly random, but one
which happens to decode as valid UTF-8, such that the expected and
actual strings are shown with reasonable characters on a terminal.
2024-05-21 15:48:26 +02:00
Jan Engelhardt
b447adbe37
Fixes/comments for guessBestEncoding ()
* tests: add case for getRecommendedEncoding

* vmime: avoid integer multiply wraparound in wordEncoder::guessBestEncoding

If the input string is 42949673 characters long or larger, there will
be integer overflow on 32-bit platforms when multiplying by 100.
Switch that one computation to floating point.

* vmime: update comment in wordEncoder::guessBestEncoding
2024-05-21 15:47:05 +02:00
Jan Engelhardt
97d15b8cd7
vmime: avoid changing SEVEN_BIT when encoding::decideImpl sees U+007F ()
* vmime: avoid changing SEVEN_BIT when encoding::decideImpl sees U+007F

Do not switch to QP/B64 when encountering U+007F.
U+007F is part of ASCII just as much as U+0001 is.

---------

Co-authored-by: Vincent Richard <vincent@vincent-richard.net>
2024-05-21 15:45:29 +02:00
Jan Engelhardt
0ce327abee
url: strip leading slash from url-path () 2024-03-04 11:46:03 +01:00
Jan Engelhardt
c6b01fcc32
url: repair off-by-one bug in extractHost ()
`hostPart[len]` is pointing to `]`, but we need to check the
char after that.

Fixes: v0.9.2-187-g874a1d8c
2024-03-04 11:45:49 +01:00
Jan Engelhardt
874a1d8c33
url: support IPv6 literals (RFC 2732) () 2024-01-30 12:38:41 +01:00
vincent-richard
561746081f Fixed possible recursion crash when parsing mailbox groups. 2022-01-25 10:28:20 +01:00
Vincent Richard
23ab2a6a3c Fixed Cppcheck issues. 2021-11-25 21:57:07 +01:00
ibanic
5d78d879bb Prevent accessing empty buffer 2021-05-15 22:32:24 +02:00
vincent-richard
c86e4bcd3a Workaround for bad SEARCH response with AOL IMAP server 2021-05-11 08:31:03 +02:00
vincent-richard
c6904bd7cf SMTP/DSN refactoring. 2021-04-03 11:21:50 +02:00
vincent-richard
e5186e6710 Fixed parsing of IMAP astring. 2021-03-24 21:04:01 +01:00
vincent-richard
47c6f35f5a Fixed unquoted mailbox name 2021-02-05 18:28:20 +01:00
Vincent Richard
13ca7fa6e5 Fixed implicit declarations and misc warnings. 2021-01-11 22:34:59 +01:00
Jan Engelhardt
f4c611b736 Avoid force-encoding display names that fit within qcontent
When the display name contains an At sign, or anything of the sort,
libvmime would forcibly encode this to =?...?=, even if the line
is fine ASCII which only needs quoting.

rspamd takes excessive quoting as a sign of spam and penalizes
such mails by raising the score (rule/match: TO_EXCESS_QP et al.)
2020-12-11 23:10:39 +01:00
vincent-richard
9205c9d0ab Fixed unit test for DSN support. 2020-09-02 19:57:42 +02:00
vincent-richard
5c00f7867a Fixed whitespace between encoded words 2020-06-16 19:47:33 +02:00
vincent-richard
9a10a839ec Added test. 2020-06-02 18:13:34 +02:00
vincent-richard
fe5492ceb3 Fixed false positives in tests. 2020-04-06 18:20:03 +02:00
vincent-richard
6d90a15bc5 Map '*' to '\*' in non-strict mode. 2020-04-06 18:12:41 +02:00
vincent-richard
f23cc90a6d Added support for pipelined and out-of-order replies. 2020-04-05 11:13:04 +02:00
Jan Engelhardt
b06e9e6f86 Skip delimiter lines that are not exactly equal to the boundary
There is crap software out there that generates mails violating the
prefix ban clause from RFC 2046 §5.1 ¶2.

Switch vmime from a prefix match to an equality match, similar to
what Alpine and Thunderbird do too.
2019-10-05 11:37:09 +02:00
Jan Engelhardt
df32418df5 Disregard whitespace between leading boundary hyphens and marker
The way I read the RFC is that whitespace is not allowed before the
boundary marker, only afterwards, so the checks for leading WS are
removed, and the missing check for trailing WS is added.

See RFC 2046 §5.1.1: """The boundary delimiter line is then defined
as a line consisting entirely of two hyphen characters ("-", decimal
value 45) followed by the boundary parameter value from the
Content-Type header field, optional linear whitespace, and a
terminating CRLF."""
2019-10-05 11:31:51 +02:00
Vincent Richard
e2fc1911f1 Merge branch 'master' of https://github.com/kisli/vmime 2019-04-18 11:29:28 +02:00
Vincent Richard
b59e97d0a7 Add support for invalid empty () in FETCH body structure (non-strict) 2019-04-18 11:28:48 +02:00
Jan Engelhardt
d1190b496f Improve address parser for malformed mailbox specifications
Spammers use "Name <addr> <addr>" to trick some parsers.
My expectations as to what the outcome should be is presented
in the updated mailboxTest.cpp.

The DFA in mailbox::parseImpl is hereby redone so as to pick the
rightmost address-looking portion as the address, rather than
something in between. While doing so, it will also no longer mangle
the name part anymore (it does this by keeping a "as_if_name"
variable around until the end).
2019-01-25 08:11:07 +01:00
Jan Engelhardt
cc18aa39c1 tests: add more malformation tests to mailboxTest 2019-01-24 13:17:52 +01:00
Vincent Richard
df135b5a8b Removed 'stringProxy' since COW std::string is no longer valid in C++11. 2018-09-15 07:41:26 +02:00
Vincent Richard
cfd4492915 More tests. 2018-09-06 00:22:34 +02:00
Vincent Richard
7e29cf01fa Fixed bug in implementation of isStringEqualNoCase(). 2018-09-06 00:16:48 +02:00
Vincent Richard
b55bdc9c0b Code style and clarity. 2018-09-05 23:54:48 +02:00
Vincent Richard
f173b0a535 Avoid copy by passing shared_ptr<> with const reference. 2018-08-18 16:08:25 +02:00
Vincent Richard
abba40e97d Added unit test related to PR . 2018-03-12 20:33:27 +01:00
Vincent Richard
d7a1b5817e Issue : SMTPUTF8 is not an argument to RCPT + UTF8 in recipient address must switch the whole message to SMTPUTF8. 2017-12-14 22:11:58 +01:00
Vincent Richard
1592cccb61 Fixed : use SMTPUTF8 only when needed. 2017-12-14 21:39:29 +01:00
Vincent Richard
604b713562 Issue : multiple sequences of 'LF..' not replaced correctly. 2017-03-28 22:31:04 +02:00
Vincent Richard
9a3d6880e8 Fixed issue : invalid characters in hostname. 2017-02-10 21:20:22 +01:00
Vincent Richard
e973619d7e Issue : default encoder (fallback). 2017-02-08 21:27:10 +01:00
Vincent Richard
ec5f4370b6 Fixed : parsing error on invalid FETCH BODYSTRUCTURE response. 2017-01-18 21:10:10 +01:00
Vincent Richard
c53e914ea5 Always ignore newlines between words. 2017-01-02 21:40:38 +01:00
Vincent Richard
5424aa2381 Fixed : don't loose charset when fixing invalid broken words. 2016-11-05 13:31:54 +01:00
Vincent Richard
b1c2d4b61e Clarified object construction where 'enabled_shared_from_this' is used. Use it only where it is needed. 2016-04-05 22:11:47 +02:00
Vincent Richard
12781598bd Fixed special value 'last' in message sets. 2016-03-24 20:34:27 +01:00
Vincent Richard
b03c398b47 Fixed types. 2016-03-23 20:32:13 +01:00
Vincent Richard
4b62ae4174 Issue : fixed warnings about sign mismatch. 2016-03-23 20:05:59 +01:00
Vincent Richard
4fd8976515 Issue : more warnings fixed. 2016-03-13 20:15:22 +01:00
Vincent Richard
3dd5975422 Fixed possible endless loop with some buffer sizes (thanks to John van der Kamp). 2015-06-11 20:03:38 +02:00
Vincent Richard
c446afddd4 Estimate generated size of parameterized field. 2015-06-07 21:32:44 +02:00