diff -Nru alot-0.9.1/debian/changelog alot-0.9.1/debian/changelog --- alot-0.9.1/debian/changelog 2020-07-05 08:19:27.000000000 +0000 +++ alot-0.9.1/debian/changelog 2020-07-10 12:06:29.000000000 +0000 @@ -1,3 +1,12 @@ +alot (0.9.1-2) unstable; urgency=medium + + * Backport two commits from upstream + - Fix utf8 encoding with a text/plain mailcap entry (closes: #964391) + - Fix mailcap rendering for e-mails without `Content-Type` header + (closes: #964501) + + -- Johannes 'josch' Schauer Fri, 10 Jul 2020 14:06:29 +0200 + alot (0.9.1-1) unstable; urgency=medium [ Jordan Justen ] diff -Nru alot-0.9.1/debian/patches/0001-Fix-mailcap-rendering-for-e-mails-without-Content-Ty.patch alot-0.9.1/debian/patches/0001-Fix-mailcap-rendering-for-e-mails-without-Content-Ty.patch --- alot-0.9.1/debian/patches/0001-Fix-mailcap-rendering-for-e-mails-without-Content-Ty.patch 1970-01-01 00:00:00.000000000 +0000 +++ alot-0.9.1/debian/patches/0001-Fix-mailcap-rendering-for-e-mails-without-Content-Ty.patch 2020-07-10 12:06:29.000000000 +0000 @@ -0,0 +1,65 @@ +From 2348014eb6d654ef123c6c353d2dc4306f226305 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20Ma=C4=8Ds?= +Date: Tue, 19 May 2020 13:48:17 +0300 +Subject: [PATCH 1/9] Fix mailcap rendering for e-mails without `Content-Type` + header + +`get_params()` returns `None` when the header is missing. Use `failobj` +argument to mitigate that. + +Fixes #1512 +--- + alot/db/utils.py | 2 +- + tests/db/test_utils.py | 10 ++++++++++ + tests/static/mail/basic.eml | 5 +++++ + 3 files changed, 16 insertions(+), 1 deletion(-) + create mode 100644 tests/static/mail/basic.eml + +diff --git a/alot/db/utils.py b/alot/db/utils.py +index 27c85942..e55768b1 100644 +--- a/alot/db/utils.py ++++ b/alot/db/utils.py +@@ -365,7 +365,7 @@ def render_part(part, field_key='copiousoutput'): + stdin = raw_payload + + # read parameter, create handler command +- parms = tuple('='.join(p) for p in part.get_params()) ++ parms = tuple('='.join(p) for p in part.get_params(failobj=[])) + + # create and call external command + cmd = mailcap.subst(entry['view'], ctype, +diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py +index 36ce77cf..40c2fb91 100644 +--- a/tests/db/test_utils.py ++++ b/tests/db/test_utils.py +@@ -762,6 +762,16 @@ class TestExtractBodyPart(unittest.TestCase): + + self.assertEqual(actual, expected) + ++ @mock.patch('alot.db.utils.settings.mailcap_find_match', ++ mock.Mock(return_value=(None, {'view': 'cat'}))) ++ def test_plaintext_mailcap_wo_content_type(self): ++ with open('tests/static/mail/basic.eml') as fp: ++ mail = email.message_from_file(fp, ++ _class=email.message.EmailMessage) ++ body_part = utils.get_body_part(mail) ++ actual = utils.extract_body_part(body_part) ++ expected = 'test body\n' ++ self.assertEqual(actual, expected) + + class TestRemoveCte(unittest.TestCase): + +diff --git a/tests/static/mail/basic.eml b/tests/static/mail/basic.eml +new file mode 100644 +index 00000000..95f15693 +--- /dev/null ++++ b/tests/static/mail/basic.eml +@@ -0,0 +1,5 @@ ++From: me@localhost ++To: you@localhost ++Subject: test subject ++ ++test body +-- +2.27.0 + diff -Nru alot-0.9.1/debian/patches/0001-Fix-utf8-encoding-with-a-text-plain-mailcap-entry.patch alot-0.9.1/debian/patches/0001-Fix-utf8-encoding-with-a-text-plain-mailcap-entry.patch --- alot-0.9.1/debian/patches/0001-Fix-utf8-encoding-with-a-text-plain-mailcap-entry.patch 1970-01-01 00:00:00.000000000 +0000 +++ alot-0.9.1/debian/patches/0001-Fix-utf8-encoding-with-a-text-plain-mailcap-entry.patch 2020-07-10 12:06:29.000000000 +0000 @@ -0,0 +1,63 @@ +From 37395809db473fb9a4157084a5b1ea3165914556 Mon Sep 17 00:00:00 2001 +From: ryneeverett +Date: Sun, 14 Jun 2020 18:40:54 +0000 +Subject: [PATCH 1/6] Fix utf8 encoding with a text/plain mailcap entry. + +This seems to essentially revert 777823f414aab5dfa130174dc7c80cda8036d13f, +the reasoning of which I don't yet follow. + +This may resolve the issue in #1522. +--- + alot/db/utils.py | 6 +----- + tests/db/test_utils.py | 18 ++++++++++++++++++ + 2 files changed, 19 insertions(+), 5 deletions(-) + +diff --git a/alot/db/utils.py b/alot/db/utils.py +index e55768b1..892bc287 100644 +--- a/alot/db/utils.py ++++ b/alot/db/utils.py +@@ -429,11 +429,7 @@ def remove_cte(part, as_string=False): + # decoding into a str is done at the end if requested + elif '8bit' in cte: + logging.debug('assuming Content-Transfer-Encoding: 8bit') +- # Python's mail library may decode 8bit as raw-unicode-escape, so +- # we need to encode that back to bytes so we can decode it using +- # the correct encoding, or it might not, in which case assume that +- # the str representation we got is correct. +- bp = payload.encode('raw-unicode-escape') ++ bp = payload.encode('utf8') + + elif 'quoted-printable' in cte: + logging.debug('assuming Content-Transfer-Encoding: quoted-printable') +diff --git a/tests/db/test_utils.py b/tests/db/test_utils.py +index 40c2fb91..d649166c 100644 +--- a/tests/db/test_utils.py ++++ b/tests/db/test_utils.py +@@ -748,6 +748,24 @@ class TestExtractBodyPart(unittest.TestCase): + + self.assertEqual(actual, expected) + ++ @mock.patch('alot.db.utils.settings.mailcap_find_match', ++ mock.Mock(return_value=( ++ None, {'view': 'sed "s/!/?/"'}))) ++ def test_utf8_plaintext_mailcap(self): ++ """ ++ Handle unicode correctly in the presence of a text/plain mailcap entry. ++ ++ https://github.com/pazz/alot/issues/1522 ++ """ ++ mail = email.message_from_binary_file( ++ open('tests/static/mail/utf8.eml', 'rb'), ++ _class=email.message.EmailMessage) ++ body_part = utils.get_body_part(mail) ++ actual = utils.extract_body_part(body_part) ++ expected = "Liebe Grüße?\n" ++ ++ self.assertEqual(actual, expected) ++ + @mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True)) + @mock.patch('alot.db.utils.settings.mailcap_find_match', + mock.Mock(return_value=( +-- +2.27.0 + diff -Nru alot-0.9.1/debian/patches/series alot-0.9.1/debian/patches/series --- alot-0.9.1/debian/patches/series 2020-05-31 09:21:48.000000000 +0000 +++ alot-0.9.1/debian/patches/series 2020-07-10 12:06:29.000000000 +0000 @@ -3,3 +3,5 @@ 0003-alot-UnicodeEncodeError-for-search-queries-with-non-.patch 0004-tests-crypto_test.py-Use-gpg-rather-than-gpg2.patch 0005-add-patch-that-fixes-a-race-condition-in-tests-close.patch +0001-Fix-mailcap-rendering-for-e-mails-without-Content-Ty.patch +0001-Fix-utf8-encoding-with-a-text-plain-mailcap-entry.patch