From cd032bca1c4b062e2ef660e77d438a15d58e891e Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Aug 2018 11:16:20 -0700 Subject: Set the policy for email.message_from_* Otherwise they default to the Compat32 policy, which isn't want we want, since we end up with a mixture of new and old types. Fixes: #1292 --- alot/db/message.py | 4 +++- alot/db/utils.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'alot/db') diff --git a/alot/db/message.py b/alot/db/message.py index b53ec6c0..3c860cac 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -3,6 +3,7 @@ # For further details see the COPYING file import email import email.charset as charset +import email.policy import functools from datetime import datetime @@ -103,7 +104,8 @@ class Message(object): with open(path, 'rb') as f: self._email = utils.decrypted_message_from_bytes(f.read()) except IOError: - self._email = email.message_from_string(warning) + self._email = email.message_from_string( + warning, policy=email.policy.SMTP) return self._email def get_date(self): diff --git a/alot/db/utils.py b/alot/db/utils.py index eda03051..4c72bb7a 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -209,7 +209,7 @@ def _handle_encrypted(original, message): if malformed: msg = u'Malformed OpenPGP message: {0}'.format(malformed) - content = email.message_from_string(msg) + content = email.message_from_string(msg, policy=email.policy.SMTP) content.set_charset('utf-8') original.attach(content) @@ -291,7 +291,8 @@ def decrypted_message_from_bytes(bytestring): :param bytes bytestring: an email message as raw bytes """ - return decrypted_message_from_message(email.message_from_bytes(bytestring)) + return decrypted_message_from_message( + email.message_from_bytes(bytestring, policy=email.policy.SMTP)) def extract_headers(mail, headers=None): -- cgit v1.2.3