# Path: alot/helper.py
# async def call_cmd_async(cmdlist, stdin=None, env=None):
#     """Given a command, call that command asynchronously and return the output.
# 
#     This function only handles `OSError` when creating the subprocess, any
#     other exceptions raised either durring subprocess creation or while
#     exchanging data with the subprocess are the caller's responsibility to
#     handle.
# 
#     If such an `OSError` is caught, then returncode will be set to 1, and the
#     error value will be set to the str() value of the exception.
# 
#     :type cmdlist: list of str
#     :param stdin: string to pipe to the process
#     :type stdin: str
#     :return: Tuple of stdout, stderr, returncode
#     :rtype: tuple[str, str, int]
#     """
#     termenc = urwid.util.detected_encoding
#     cmdlist = [s.encode(termenc) for s in cmdlist]
# 
#     environment = os.environ.copy()
#     if env is not None:
#         environment.update(env)
#     logging.debug('ENV = %s', environment)
#     logging.debug('CMD = %s', cmdlist)
#     try:
#         proc = await asyncio.create_subprocess_exec(
#             *cmdlist,
#             env=environment,
#             stdout=asyncio.subprocess.PIPE,
#             stderr=asyncio.subprocess.PIPE,
#             stdin=asyncio.subprocess.PIPE if stdin else None)
#     except OSError as e:
#         return ('', str(e), 1)
#     out, err = await proc.communicate(stdin.encode(termenc) if stdin else None)
#     return (out.decode(termenc), err.decode(termenc), proc.returncode)
# 
# Path: alot/helper.py
# def split_commandstring(cmdstring):
#     """
#     split command string into a list of strings to pass on to subprocess.Popen
#     and the like. This simply calls shlex.split but works also with unicode
#     bytestrings.
#     """
#     assert isinstance(cmdstring, str)
#     return shlex.split(cmdstring)


import abc
import glob
import logging
import mailbox
import operator
import os
import re
from .helper import call_cmd_async
from .helper import split_commandstring
        :param mail: the mail to send
        :type mail: :class:`email.message.Message` or string
        :raises SendingMailFailed: if sending fails
        """
        pass


class SendmailAccount(Account):
    """:class:`Account` that pipes a message to a `sendmail` shell command for
    sending"""

    def __init__(self, cmd, **kwargs):
        """
        :param cmd: sendmail command to use for this account
        :type cmd: str
        """
        super(SendmailAccount, self).__init__(**kwargs)
        self.cmd = cmd

    async def send_mail(self, mail):
        """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
        :raises: class:`SendingMailFailed` if sending failes
        """
        cmdlist = split_commandstring(self.cmd)

        try:
            # make sure self.mail is a string

# Path: alot/helper.py
# async def call_cmd_async(cmdlist, stdin=None, env=None):
#     """Given a command, call that command asynchronously and return the output.
# 
#     This function only handles `OSError` when creating the subprocess, any
#     other exceptions raised either durring subprocess creation or while
#     exchanging data with the subprocess are the caller's responsibility to
#     handle.
# 
#     If such an `OSError` is caught, then returncode will be set to 1, and the
#     error value will be set to the str() value of the exception.
# 
#     :type cmdlist: list of str
#     :param stdin: string to pipe to the process
#     :type stdin: str
#     :return: Tuple of stdout, stderr, returncode
#     :rtype: tuple[str, str, int]
#     """
#     termenc = urwid.util.detected_encoding
#     cmdlist = [s.encode(termenc) for s in cmdlist]
# 
#     environment = os.environ.copy()
#     if env is not None:
#         environment.update(env)
#     logging.debug('ENV = %s', environment)
#     logging.debug('CMD = %s', cmdlist)
#     try:
#         proc = await asyncio.create_subprocess_exec(
#             *cmdlist,
#             env=environment,
#             stdout=asyncio.subprocess.PIPE,
#             stderr=asyncio.subprocess.PIPE,
#             stdin=asyncio.subprocess.PIPE if stdin else None)
#     except OSError as e:
#         return ('', str(e), 1)
#     out, err = await proc.communicate(stdin.encode(termenc) if stdin else None)
#     return (out.decode(termenc), err.decode(termenc), proc.returncode)
# 
# Path: alot/helper.py
# def split_commandstring(cmdstring):
#     """
#     split command string into a list of strings to pass on to subprocess.Popen
#     and the like. This simply calls shlex.split but works also with unicode
#     bytestrings.
#     """
#     assert isinstance(cmdstring, str)
#     return shlex.split(cmdstring)


# Path: alot/account.py
import abc
import glob
import logging
import mailbox
import operator
import os
import re
from .helper import call_cmd_async
from .helper import split_commandstring

        :param mail: the mail to send
        :type mail: :class:`email.message.Message` or string
        :raises SendingMailFailed: if sending fails
        """
        pass


class SendmailAccount(Account):
    """:class:`Account` that pipes a message to a `sendmail` shell command for
    sending"""

    def __init__(self, cmd, **kwargs):
        """
        :param cmd: sendmail command to use for this account
        :type cmd: str
        """
        super(SendmailAccount, self).__init__(**kwargs)
        self.cmd = cmd

    async def send_mail(self, mail):
        """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
        :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))