Created
August 16, 2012 16:00
-
-
Save jleedev/3371328 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 email | |
import email.parser | |
import imaplib | |
import getpass | |
login = raw_input("Gmail address: ") | |
password = getpass.getpass() | |
sock = imaplib.IMAP4_SSL("imap.gmail.com", 993) | |
sock.login(login, password) | |
ok, _ = sock.select("[Gmail]/Chats", readonly=True) | |
if ok == 'NO': | |
sock.select("[Google Mail]/Chats", readonly=True) | |
ok, [ids] = sock.search(None, '(ALL)') | |
ids = ids.split() | |
msg_id = ids[-1] | |
resp, data = sock.fetch(msg_id, '(RFC822)') | |
msg = email.parser.Parser().parsestr(data[0][1]) | |
for part in msg.walk(): | |
if part.get_content_type() != 'text/html': | |
continue | |
print part.get_payload(decode=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment