summaryrefslogtreecommitdiff
path: root/alot/commands/thread.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-08-01 11:14:52 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-08-02 10:51:09 -0700
commit293bf7ad89c837d6a2ee9e08443c00703172d953 (patch)
tree8927a34a5b8aca0287e385f834457258cadfc8c4 /alot/commands/thread.py
parent834a658dfbe25707eebed34d5f5fdd10e1fddd60 (diff)
helper: replace email_as_* with email builtins
Python 3.3 added a new feature to the email module, policies (https://docs.python.org/3.5/library/email.policy.html). Policy objects allow precise control over how numerous features work when converting to and from str or bytes. With the `email.policy.SMTP` the behavior of email_as_bytes and email_as_string can be achieved using the builtin `.as_string()` and `.as_bytes()` methods, without custom code or the need to test it. Additionally these methods handle corner cases that we don't currently handle, such as multi-part messages with different encodings. Fixes #1257
Diffstat (limited to 'alot/commands/thread.py')
-rw-r--r--alot/commands/thread.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 801ce2f0..6513872c 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -9,6 +9,8 @@ import os
import re
import subprocess
import tempfile
+import email
+import email.policy
from email.utils import getaddresses, parseaddr, formataddr
from email.message import Message
@@ -34,7 +36,6 @@ from ..db.errors import DatabaseROError
from ..settings.const import settings
from ..helper import parse_mailcap_nametemplate
from ..helper import split_commandstring
-from ..helper import email_as_string
from ..utils import argparse as cargparse
from ..widgets.globals import AttachmentWidget
@@ -382,7 +383,7 @@ class ForwardCommand(Command):
original_mail = Message()
original_mail.set_type('message/rfc822')
original_mail['Content-Disposition'] = 'attachment'
- original_mail.set_payload(email_as_string(mail))
+ original_mail.set_payload(mail.as_string(policy=email.policy.SMTP))
envelope.attach(Attachment(original_mail))
# copy subject