diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-04-24 09:16:03 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-04-24 09:16:03 -0700 |
commit | 3360b12fa4af565d71d851fb4021a8bdbff3fb6d (patch) | |
tree | fce084541e76cdcb59a4def0aa30c00c5cc73131 /alot | |
parent | 6e08521c42008b4a378088df1174ba44c600eb8d (diff) |
db/utils: correctly handle 8bit encoded mail
Diffstat (limited to 'alot')
-rw-r--r-- | alot/db/utils.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py index ba32b832..88e2b0f2 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -358,17 +358,7 @@ def extract_body(mail, types=None, field_key='copiousoutput'): enc = part.get_content_charset() or 'ascii' cte = str(part.get('content-transfer-encoding', '7bit')).lower() payload = part.get_payload() - if cte not in ['7bit', '8bit']: - if cte == 'quoted-printable': - raw_payload = quopri.decodestring(payload.encode('ascii')) - elif cte == 'base64': - raw_payload = base64.b64decode(payload) - else: - raise Exception('Unknown Content-Transfer-Encoding {}'.format(cte)) - # message.get_payload(decode=True) also handles a number of unicode - # encodindigs. maybe those are useful? - payload = raw_payload.decode(enc) - elif cte == '8bit': + if cte == '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 @@ -378,6 +368,16 @@ def extract_body(mail, types=None, field_key='copiousoutput'): payload = raw_payload.decode(enc) except UnicodeDecodeError: pass + elif cte != '7bit': + if cte == 'quoted-printable': + raw_payload = quopri.decodestring(payload.encode('ascii')) + elif cte == 'base64': + raw_payload = base64.b64decode(payload) + else: + raise Exception('Unknown Content-Transfer-Encoding {}'.format(cte)) + # message.get_payload(decode=True) also handles a number of unicode + # encodindigs. maybe those are useful? + payload = raw_payload.decode(enc) if ctype == 'text/plain': body_parts.append(string_sanitize(payload)) |