Skip to content

Instantly share code, notes, and snippets.

@benatkin
Forked from joestump/gist:402594
Created May 16, 2010 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benatkin/402692 to your computer and use it in GitHub Desktop.
Save benatkin/402692 to your computer and use it in GitHub Desktop.
import oauth2.clients.imap as imaplib
import email
class Mailbox(object):
def __init__(self, conn):
self.conn = conn
self.total = self.conn.select('INBOX')[1][0]
self.current = 1
def __iter__(self):
return self
def next(self):
if self.current > self.total:
raise StopIteration()
typ, data = self.conn.fetch(self.current, '(RFC822)')
self.current += 1
return email.message_from_string(data[0][1])
def __exit__(self):
self.conn.close()
self.conn.logout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment