diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-30 13:33:27 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-30 13:33:27 +0100 |
commit | 5dfe5a2831adbe3ec129d2ede1d9039739e98b71 (patch) | |
tree | bf54920d084544c2e12cd532c94cf3bdcaa37f95 /alot/account.py | |
parent | 27e9478faefecf5b290c0fbd3df5b1fe9e18c97f (diff) |
db/envelope: switch to the "new" (EmailMessage) python API
email.mime is a part of the old API, which does not mix well with the
new one (i.e. when email.policy.SMTP is used), specifically when
non-ASCII headers are used.
Additionally, clean the APIs that accept either EmailMessage or a str to
only expect EmailMessage. Supporting both just adds confusion and
complexity.
Diffstat (limited to 'alot/account.py')
-rw-r--r-- | alot/account.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/alot/account.py b/alot/account.py index 1db65a5f..87c71390 100644 --- a/alot/account.py +++ b/alot/account.py @@ -5,6 +5,7 @@ # For further details see the COPYING file import abc import asyncio +from email import policy import glob import logging import mailbox @@ -305,7 +306,7 @@ class Account: def store_sent_mail(self, mail): """ - stores mail (:class:`email.message.Message` or str) in send-store if + stores mail (:class:`email.message.EmailMessage`) in send-store if :attr:`sent_box` is set. """ if self.sent_box is not None: @@ -313,7 +314,7 @@ class Account: def store_draft_mail(self, mail): """ - stores mail (:class:`email.message.Message` or str) as draft if + stores mail (:class:`email.message.EmailMessage`) as draft if :attr:`draft_box` is set. """ if self.draft_box is not None: @@ -325,7 +326,7 @@ class Account: sends given mail :param mail: the mail to send - :type mail: :class:`email.message.Message` or string + :type mail: :class:`email.message.EmailMessage` :raises SendingMailFailed: if sending fails """ pass @@ -347,13 +348,14 @@ class SendmailAccount(Account): """Pipe the given mail to the configured sendmail command. Display a short message on success or a notification on error. :param mail: the mail to send out - :type mail: bytes + :type mail: email.message.EmailMessage :raises: class:`SendingMailFailed` if sending failes """ - P = asyncio.subprocess.PIPE + data = mail.as_bytes() + P = asyncio.subprocess.PIPE child = await asyncio.create_subprocess_shell(self.cmd, P, P, P) - out, err = await child.communicate(mail) + out, err = await child.communicate(data) if child.returncode != 0: msg = 'Calling sendmail command %s failed with code %s' % \ |