Skip to content

Instantly share code, notes, and snippets.

@joestump
Created May 16, 2010 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joestump/402594 to your computer and use it in GitHub Desktop.
Save joestump/402594 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 __del__(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