From 3c84b49725fd430ec71c5dc1b8ae0fb069fe6e53 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sat, 25 May 2019 20:30:14 +0100 Subject: do not remove quotes around realname parts when decoding headers containing email addresses; Some MUAs (exchange) will add headers in the form: To: "Last, First" Prior to this commit, alot would remove the quotes (apparently they violate RFC 2047). However, this then would lead to problems where the additional comma is interpreted as separator between several recipients. This commit causes alot to not remove the quotes. --- alot/db/utils.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/alot/db/utils.py b/alot/db/utils.py index 94886148..75fc0178 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -526,15 +526,9 @@ def decode_header(header, normalize=False): :type normalize: bool :rtype: str """ - # some mailers send out incorrectly escaped headers - # and double quote the escaped realname part again. remove those - # RFC: 2047 - regex = r'"(=\?.+?\?.+?\?[^ ?]+\?=)"' - value = re.sub(regex, r'\1', header) - logging.debug("unquoted header: |%s|", value) - - # otherwise we interpret RFC2822 encoding escape sequences - valuelist = email.header.decode_header(value) + logging.debug("unquoted header: |%s|", header) + + valuelist = email.header.decode_header(header) decoded_list = [] for v, enc in valuelist: v = string_decode(v, enc) -- cgit v1.2.3 From 72306c65a9ab423c089c2a77569b6f549a1ab58c Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Mon, 27 May 2019 10:29:49 +0100 Subject: tests: add case for exchange formatted realnames --- tests/db/test_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py index f6249542..1e230aef 100644 --- a/tests/db/test_utils.py +++ b/tests/db/test_utils.py @@ -272,6 +272,12 @@ class TestDecodeHeader(unittest.TestCase): expected = u'first\nsecond third fourth fifth' actual = utils.decode_header(text, normalize=True) self.assertEqual(actual, expected) + + def test_exchange_quotes_remain(self): + # issue #1347 + expected = u'"Mouse, Michaƫl" ' + text = self._quote(expected, 'utf-8') + self._test(text, expected) class TestAddSignatureHeaders(unittest.TestCase): -- cgit v1.2.3