Created
May 16, 2010 02:38
-
-
Save joestump/402594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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