Skip to content

Commit

Permalink
Initial IMAP transport; needs error condition handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice Bevan-McGregor committed Apr 5, 2011
1 parent 9ab8ae2 commit 1b0a49f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
38 changes: 27 additions & 11 deletions marrow/mailer/transport/imap.py
@@ -1,19 +1,35 @@
# encoding: utf-8

import imaplib

from datetime import datetime


__all__ = ['IMAPTransport']

log = __import__('logging').getLogger(__name__)



class IMAPTransport(object):
def __init__(self, **kw):
self.config = kw

def startup(self):
pass

def __call__(self, message):
pass # Deliver the message.

def shutdown(self):
pass
def __init__(self, config):
self.host = config.get('host', None)
self.ssl = config.get('ssl', False)
self.port = config.get('port', 993 if self.ssl else 143)
self.username = config.get('username', None)
self.password = config.get('password', None)
self.folder = config.get('folder', "INBOX")

def startup(self):
Protocol = imaplib.IMAP4_SSL if self.ssl else imaplib.IMAP4
self.connection = Protocol(self.host, self.port)

if self.username:
result = self.connection.login(self.username, self.password)
log.debug("Response: %r", result)

def __call__(self, message):
self.connection.append(self.folder, '', message.date if message.date else datetime.now(), bytes(message))

def shutdown(self):
self.connection.logout()
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -67,6 +67,7 @@
"mailbox = marrow.mailer.transport.mbox:MailboxTransport",
"maildir = marrow.mailer.transport.maildir:MaildirTransport",
"sendmail = marrow.mailer.transport.sendmail:SendmailTransport",
"imap = marrow.mailer.transport.imap:IMAPTransport",
]
}
)

0 comments on commit 1b0a49f

Please sign in to comment.