-
-
Save benatkin/402692 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 __exit__(self): | |
| self.conn.close() | |
| self.conn.logout() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/865115/how-do-i-correctly-clean-up-a-python-object