Commit Graph

25 Commits

Author SHA1 Message Date
Jan Engelhardt
d296c2d1d5
vmime: prevent loss of a space during text::createFromString (#306)
```
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: #283, #284

Co-authored-by: Vincent Richard <vincent@vincent-richard.net>
2024-05-21 15:55:06 +02: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
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
b55bdc9c0b Code style and clarity. 2018-09-05 23:54:48 +02:00
Vincent Richard
abba40e97d Added unit test related to PR #192. 2018-03-12 20:33:27 +01:00
Vincent Richard
f9913fa28a Boost/C++11 shared pointers. 2013-11-21 22:16:57 +01:00
Vincent Richard
32a80f6c1e Fixed mailbox and mailbox group parsing. Added unit tests. 2013-03-11 10:05:09 +01:00
Vincent Richard
1df8c6cd0e Refactored unit tests. 2013-03-08 08:19:55 +01:00
Vincent Richard
0c5d4a10e6 Message generation/parsing context. Charset conversion options. Preliminary implementation of RFC-6532. 2013-02-24 16:28:13 +01:00
Vincent Richard
ad9bef78c4 Updated copyright year and maintainer email address. 2013-01-10 17:30:31 +01:00
Vincent Richard
4f9dc93200 Added support for mailboxes that specify an (encoded) full name with an empty email address, set by a <> marker (Zarafa). 2011-06-19 18:49:55 +00:00
Vincent Richard
a5d258dc72 Relicensed VMime under the GNU GPL version 3. Changed copyright year to 2009. 2009-09-06 12:02:10 +00:00
Vincent Richard
0c30c298da Changed copyright year to 2008. 2008-01-04 18:07:40 +00:00
Vincent Richard
d284cfa729 Changed copyright year to 2007. 2007-01-01 20:55:15 +00:00
Vincent Richard
63d21f7a09 Changed copyright year to 2006. 2006-02-05 10:22:59 +00:00
Vincent Richard
cbd1110a4b Updated FSF address. 2005-09-17 10:10:29 +00:00
Vincent Richard
5d18fce959 Moved to CppUnit for unit tests framework. 2005-08-25 21:25:45 +00:00
Vincent Richard
0e5e375cef Added unit tests. 2005-06-17 11:27:26 +00:00
Vincent Richard
b3af751a92 Updated VMime website URL. 2005-03-18 21:33:11 +00:00
Vincent Richard
51c199723c Changed year to 2005 in copyright header. 2005-01-03 12:26:48 +00:00
Vincent Richard
da55bd2c26 Autotools and libtool support. 2004-12-30 09:32:32 +00:00
Vincent Richard
4ce991d3b1 Moved all header files to 'vmime/' directory. 2004-12-26 20:23:29 +00:00
Vincent Richard
460cae786a Default platform handlers (currently only POSIX). 2004-12-18 01:57:39 +00:00
Vincent Richard
418c0c1456 New build system for unit tests. 2004-11-06 10:48:58 +00:00