From a1c7677a1139fb95af89b3cc8aef0eb24207d42f Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Fri, 5 Apr 2013 12:04:35 -0700 Subject: [PATCH] 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 --- rss2email/email.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) 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) -- 2.26.2