email: small fixes for using imap as a backend
authorArun Persaud <apersaud@lbl.gov>
Fri, 5 Apr 2013 19:04:35 +0000 (12:04 -0700)
committerW. Trevor King <wking@tremily.us>
Fri, 5 Apr 2013 20:30:33 +0000 (16:30 -0400)
* 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 <apersaud@lbl.gov>
rss2email/email.py

index 33d8ff06cc01aada36987ba46521a4dbc4cfb799..f7a503c09ee7235ae755c470bd714f757af720db 100644 (file)
@@ -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)