From: Arun Persaud Date: Fri, 5 Apr 2013 19:04:35 +0000 (-0700) Subject: email: small fixes for using imap as a backend X-Git-Tag: v3.4~3^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a1c7677a1139fb95af89b3cc8aef0eb24207d42f;p=rss2email.git email: small fixes for using imap as a backend * fixed two typos in "def send" * removed some unecessary calls to imap.connect and imap.close (which seems to be only needed in case you open a mailbox, which we don't) Signed-off-by: Arun Persaud --- diff --git a/rss2email/email.py b/rss2email/email.py index 33d8ff0..f7a503c 100644 --- a/rss2email/email.py +++ b/rss2email/email.py @@ -176,12 +176,6 @@ def imap_send(message, config=None, section='DEFAULT'): imap = _imaplib.IMAP4_SSL(server, port) else: imap = _imaplib.IMAP4(server, port) - try: - imap.connect(server) - except KeyboardInterrupt: - raise - except Exception as e: - raise _error.IMAPConnectionError(server=server) from e try: if config.getboolean(section, 'imap-auth'): username = config.get(section, 'imap-username') @@ -200,10 +194,6 @@ def imap_send(message, config=None, section='DEFAULT'): message_bytes = _flatten(message) imap.append(mailbox, None, date, message_bytes) finally: - try: - imap.close() - except Exception as e: - _LOG.error(e) imap.logout() def _decode_header(header): @@ -341,10 +331,10 @@ def sendmail_send(sender, recipient, message, config=None, section='DEFAULT'): raise _error.SendmailError() from e def send(sender, recipient, message, config=None, section='DEFAULT'): - protocol = config.get(section, 'email-protocol'): + protocol = config.get(section, 'email-protocol') if protocol == 'smtp': smtp_send(sender, recipient, message) elif protocol == 'imap': - smtp_send(message) + imap_send(message) else: sendmail_send(sender, recipient, message)