Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial IMAP transport; needs error condition handling.
- Loading branch information
Alice Bevan-McGregor
committed
Apr 5, 2011
1 parent
9ab8ae2
commit 1b0a49f
Showing
2 changed files
with
28 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters