You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/06/05 20:21:12 UTC
[allura] 01/01: [#8289] fix decoding of multipart emails too
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/8289b
in repository https://gitbox.apache.org/repos/asf/allura.git
commit ca09eca40887ed63c17bc004cbb66b81ce2698a5
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Jun 5 16:20:59 2019 -0400
[#8289] fix decoding of multipart emails too
---
Allura/allura/lib/mail_util.py | 3 ++-
Allura/allura/tests/test_mail_util.py | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index 7fbace5..f1de6de 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -150,7 +150,8 @@ def parse_message(data):
filename=part.get_filename(None),
payload=part.get_payload(decode=True))
charset = part.get_content_charset()
- if charset:
+ # payload is sometimes already unicode (due to being saved in mongo?)
+ if isinstance(dpart['payload'], six.binary_type) and charset:
dpart['payload'] = dpart['payload'].decode(charset)
result['parts'].append(dpart)
else:
diff --git a/Allura/allura/tests/test_mail_util.py b/Allura/allura/tests/test_mail_util.py
index 4f99840..8568191 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -149,6 +149,38 @@ programmed or èrogrammed ?
assert isinstance(msg['payload'], unicode)
assert_in(u'èrogrammed', msg['payload'])
+ def test_more_encodings_multipart(self):
+ # these are unicode strings to reflect behavior after loading 'route_email' tasks from mongo
+ s_msg = u"""Date: Sat, 25 May 2019 09:32:00 +1000
+From: <fo...@bar.com>
+To: <38...@bugs.proj.localhost>
+Subject: bugs
+Content-Type: multipart/alternative; boundary="===============7387203749754534836=="
+
+--===============7387203749754534836==
+Content-Type: text/plain; charset="utf-8"
+
+> Status: closed
+> Created: Thu May 23, 2019 09:24 PM UTC by admin1
+> Attachments:
+>
+> • foo.txt (1.0 kB; text/plain)
+>
+
+
+--===============7387203749754534836==
+Content-Type: text/html; charset="utf-8"
+
+<html><head>... blah blah
+...
+> • foo.txt (1.0 kB; text/plain)
+"""
+ msg = parse_message(s_msg)
+ assert isinstance(msg['parts'][1]['payload'], unicode)
+ assert isinstance(msg['parts'][2]['payload'], unicode)
+ assert_in(u'• foo', msg['parts'][1]['payload'])
+ assert_in(u'• foo', msg['parts'][2]['payload'])
+
def test_unicode_complex_message(self):
charset = 'utf-8'
p1 = MIMEText(u'''По оживлённым берегам