From 5dfe5a2831adbe3ec129d2ede1d9039739e98b71 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 30 Jan 2021 13:33:27 +0100 Subject: 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. --- alot/account.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'alot/account.py') 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' % \ -- cgit v1.2.3