Skip to content

Commit

Permalink
Set the policy for email.message_from_*
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dcbaker authored and pazz committed Aug 6, 2018
1 parent ec3e9ea commit cd032bc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion alot/commands/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ async def apply(self, ui):
# determine account to use for sending
msg = self.mail
if not isinstance(msg, email.message.Message):
msg = email.message_from_string(self.mail)
msg = email.message_from_string(
self.mail, policy=email.policy.SMTP)
address = msg.get('From', '')
logging.debug("FROM: \"%s\"" % address)
try:
Expand Down
4 changes: 3 additions & 1 deletion alot/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -103,7 +104,8 @@ def get_email(self):
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):
Expand Down
5 changes: 3 additions & 2 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit cd032bc

Please sign in to comment.