File tree 2 files changed +19
-5
lines changed
2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -429,11 +429,7 @@ def remove_cte(part, as_string=False):
429
429
# decoding into a str is done at the end if requested
430
430
elif '8bit' in cte :
431
431
logging .debug ('assuming Content-Transfer-Encoding: 8bit' )
432
- # Python's mail library may decode 8bit as raw-unicode-escape, so
433
- # we need to encode that back to bytes so we can decode it using
434
- # the correct encoding, or it might not, in which case assume that
435
- # the str representation we got is correct.
436
- bp = payload .encode ('raw-unicode-escape' )
432
+ bp = payload .encode ('utf8' )
437
433
438
434
elif 'quoted-printable' in cte :
439
435
logging .debug ('assuming Content-Transfer-Encoding: quoted-printable' )
Original file line number Diff line number Diff line change @@ -748,6 +748,24 @@ def test_simple_utf8_file(self):
748
748
749
749
self .assertEqual (actual , expected )
750
750
751
+ @mock .patch ('alot.db.utils.settings.mailcap_find_match' ,
752
+ mock .Mock (return_value = (
753
+ None , {'view' : 'sed "s/!/?/"' })))
754
+ def test_utf8_plaintext_mailcap (self ):
755
+ """
756
+ Handle unicode correctly in the presence of a text/plain mailcap entry.
757
+
758
+ https://github.com/pazz/alot/issues/1522
759
+ """
760
+ mail = email .message_from_binary_file (
761
+ open ('tests/static/mail/utf8.eml' , 'rb' ),
762
+ _class = email .message .EmailMessage )
763
+ body_part = utils .get_body_part (mail )
764
+ actual = utils .extract_body_part (body_part )
765
+ expected = "Liebe Grüße?\n "
766
+
767
+ self .assertEqual (actual , expected )
768
+
751
769
@mock .patch ('alot.db.utils.settings.get' , mock .Mock (return_value = True ))
752
770
@mock .patch ('alot.db.utils.settings.mailcap_find_match' ,
753
771
mock .Mock (return_value = (
You can’t perform that action at this time.
0 commit comments