Updated docs, Mailbox class and example@
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -33,3 +33,4 @@ nosetests.xml
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
example.py
|
||||
|
||||
20
README.md
20
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()
|
||||
|
||||
|
||||
13
example.py
Normal file
13
example.py
Normal 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
12
mailbox/__init__.py
Normal 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
24
mailbox/imap.py
Normal 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()
|
||||
|
||||
Reference in New Issue
Block a user