Updated docs, Mailbox class and example@

This commit is contained in:
Martin Rusev
2013-07-23 11:08:12 +03:00
parent 7ca2122c5e
commit 760153d12e
6 changed files with 69 additions and 1 deletions

1
.gitignore vendored
View File

@@ -33,3 +33,4 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject
example.py

View File

@@ -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()

13
example.py Normal file
View File

@@ -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()

12
mailbox/__init__.py Normal file
View File

@@ -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 {}

24
mailbox/imap.py Normal file
View File

@@ -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()

0
setup.py Normal file
View File