diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-02-27 10:27:02 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-03-01 10:34:56 -0800 |
commit | fc065b41795dff3bf68617429ff08bf7d89de415 (patch) | |
tree | 83ebed60ba77474bc0ac14f55481ac6ed29daa2d /alot | |
parent | 29fe4c2f6f7a9d3f5e4b5e9818c26075ec263156 (diff) |
fix base64, 8bit, and quoted-printable properly.
Diffstat (limited to 'alot')
-rw-r--r-- | alot/db/utils.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py index 3244be13..c2eea105 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -352,7 +352,16 @@ def extract_body(mail, types=None, field_key='copiousoutput'): continue enc = part.get_content_charset() or 'ascii' - raw_payload = part.get_payload(decode=True).decode(enc) + raw_payload = part.get_payload(decode=True) + try: + raw_payload = raw_payload.decode(enc) + except UnicodeDecodeError: + # If the message is not formatted ascii then get_payload with + # decode=True will convert to raw-unicode-escape. if the encoding + # that the message specifies doesn't work try this. It might be + # better to handle the base64 and quoted-printable oursevles + # instead of having to clean up like this. + raw_payload = raw_payload.decode('raw-unicode-escape') if ctype == 'text/plain': body_parts.append(string_sanitize(raw_payload)) |