summaryrefslogtreecommitdiff
path: root/alot/account.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-26 11:38:03 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-26 11:38:03 +0100
commitdae098901104de7027c48dae2b9da08be2a17fac (patch)
treed432fc4ce4fdd2cbed835175f89b0fe48364319d /alot/account.py
parent5cb88d559ae462dad80d346d44f12dcc9eb3ec10 (diff)
account: stop using call_cmd_async() to run sendmail
It does not actually save any code. The new code also uses a shell as is documented. Remove call_cmd_async(), as it no longer has any callers.
Diffstat (limited to 'alot/account.py')
-rw-r--r--alot/account.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/alot/account.py b/alot/account.py
index 4112ce53..1db65a5f 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -4,6 +4,7 @@
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import abc
+import asyncio
import glob
import logging
import mailbox
@@ -11,9 +12,7 @@ import operator
import os
import re
-from .helper import call_cmd_async
-from .helper import split_commandstring
-
+from urwid.util import detected_encoding
class Address:
@@ -348,20 +347,22 @@ 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: :class:`email.message.Message` or string
+ :type mail: bytes
:raises: class:`SendingMailFailed` if sending failes
"""
- cmdlist = split_commandstring(self.cmd)
-
- try:
- # make sure self.mail is a string
- out, err, code = await call_cmd_async(cmdlist, stdin=str(mail))
- if code != 0:
- msg = 'The sendmail command {} returned with code {}{}'.format(
- self.cmd, code, ':\n' + err.strip() if err else '.')
- raise Exception(msg)
- except Exception as e:
- logging.error(str(e))
- raise SendingMailFailed(str(e))
- logging.info('sent mail successfully')
- logging.info(out)
+ P = asyncio.subprocess.PIPE
+
+ child = await asyncio.create_subprocess_shell(self.cmd, P, P, P)
+ out, err = await child.communicate(mail)
+
+ if child.returncode != 0:
+ msg = 'Calling sendmail command %s failed with code %s' % \
+ (self.cmd, child.returncode)
+ if err:
+ msg += '; stderr:\n %s' % \
+ err.decode(detected_encoding, errors = 'backslashreplace')
+ raise SendingMailFailed(msg)
+
+ if out:
+ logging.info('sendmail output:\n%s',
+ out.decode(detected_encoding, errors = 'backslashreplace'))