diff --git a/.gitignore b/.gitignore index d2d6f36..724510c 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ nosetests.xml .mr.developer.cfg .project .pydevproject +example.py diff --git a/README.md b/README.md index 5d9a7c3..79bcdb2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,22 @@ -mailbox +Mailbox ======= Small Python library for reading IMAP email boxes and parsing the content to JSON + + +Usage +===== + + + from mailbox import MailBox + + mailbox = MailBox('imap.gmail.com', + username='username', + password='password', + ssl=True) + + unread = mailbox.get_unread() + + for message in unread: + print message.json() + diff --git a/example.py b/example.py new file mode 100644 index 0000000..f5ce304 --- /dev/null +++ b/example.py @@ -0,0 +1,13 @@ +import sys +sys.path.insert(0, '/home/martin/mailbox') + +from mailbox import MailBox + +mailbox = MailBox('imap.gmail.com', + username='username', + password='password') + +unread = mailbox.get_unread() + +for message in unread: + print message.json() \ No newline at end of file diff --git a/mailbox/__init__.py b/mailbox/__init__.py new file mode 100644 index 0000000..7c9d82d --- /dev/null +++ b/mailbox/__init__.py @@ -0,0 +1,12 @@ +from mailbox.imap import ImapTransport + +class MailBox(object): + + def __init__(self, hostname, username=None, password=None, ssl=True): + + server = ImapTransport(hostname, ssl=ssl) + self.connection = server.connect(username, password) + + + def get_unread(self): + return {} \ No newline at end of file diff --git a/mailbox/imap.py b/mailbox/imap.py new file mode 100644 index 0000000..05c4a4f --- /dev/null +++ b/mailbox/imap.py @@ -0,0 +1,24 @@ +import email +from imaplib import IMAP4, IMAP4_SSL + + +class ImapTransport(object): + + def __init__(self, hostname, port=None, ssl=False): + self.hostname = hostname + self.port = port + + if ssl: + self.transport = IMAP4_SSL + if not self.port: + self.port = 993 + else: + self.transport = IMAP4 + if not self.port: + self.port = 143 + + def connect(self, username, password): + self.server = self.transport(self.hostname, self.port) + typ, msg = self.server.login(username, password) + self.server.select() + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e69de29