diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-12-25 11:03:30 +0100 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-12-25 15:38:19 +0100 |
commit | 141573771b9a36718346265c9aaca3f0a80c0396 (patch) | |
tree | c64e57d86a4a1c79dd4eaa5ababeb1968c0cd25f | |
parent | c97257fc02e5b0ac84f006f2187fed753358dcb7 (diff) |
Use exceptions for error handling in SendmailAccount.send_mail
-rw-r--r-- | alot/account.py | 7 | ||||
-rw-r--r-- | alot/commands/envelope.py | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/alot/account.py b/alot/account.py index 6eb9f099..8d76a60b 100644 --- a/alot/account.py +++ b/alot/account.py @@ -10,6 +10,7 @@ from urlparse import urlparse import helper +class SendingMailFailed(RuntimeError): pass class Account(object): """ @@ -121,8 +122,7 @@ class Account(object): :param mail: the mail to send :type mail: :class:`email.message.Message` or string - :returns: None if successful and a string with the reason - for failure otherwise. + :raises: :class:`alot.account.SendingMailFailed` if an error occured """ return 'not implemented' @@ -143,9 +143,8 @@ class SendmailAccount(Account): cmdlist = shlex.split(self.cmd.encode('utf-8', errors='ignore')) out, err, retval = helper.call_cmd(cmdlist, stdin=mail.as_string()) if err: - return err + '. sendmail_cmd set to: %s' % self.cmd + raise SendingMailFailed('%s. sendmail_cmd set to: %s' % (err, self.cmd)) self.store_sent_mail(mail) - return None class AccountManager(object): diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 21b6aa26..5e54b63f 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -8,6 +8,7 @@ from twisted.internet.defer import inlineCallbacks import threading import datetime +from alot.account import SendingMailFailed from alot import buffers from alot import commands from alot.commands import Command, registerCommand @@ -129,7 +130,12 @@ class SendCommand(Command): def thread_code(): mail = envelope.construct_mail() - os.write(write_fd, account.send_mail(mail) or 'success') + try: + account.send_mail(mail) + except SendingMailFailed as e: + os.write(write_fd, unicode(e)) + else: + os.write(write_fd, 'success') thread = threading.Thread(target=thread_code) thread.start() |