Last active
December 18, 2015 08:29
-
-
Save mmautner/5754284 to your computer and use it in GitHub Desktop.
a short script to demonstrate pulling down your google talk history
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
#!/usr/bin/env python | |
# Download your chat history | |
# http://stackoverflow.com/questions/8146970/accessing-chat-folder-in-python-using-imaplib | |
import imaplib | |
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993) | |
conn.login("[email protected]", "password") | |
lb_list = conn.list() | |
print lb_list | |
conn.select("[Gmail]/Chats", True) | |
conn.search(None, '(ALL)') | |
resp, data = conn.fetch('1:*', '(RFC822)') | |
with open('chats.log', 'w') as f: | |
f.write(data) | |
# inspect 'em | |
import email | |
from xml.etree import cElementTree as ET | |
import quopri | |
with open('chats.log') as f: | |
raw_chats = eval(f.readline()) | |
chats = [] | |
for i, val in enumerate(raw_chats): | |
if i % 2 == 1: | |
continue | |
em = email.message_from_string(val[1]) | |
em1 = em.get_payload()[0] | |
em2 = em.get_payload()[1] | |
xmpp = quopri.decodestring(em1.get_payload()) | |
xm = ET.fromstring(xmpp) | |
for child in xm.getchildren(): | |
print 'from:\t', child.attrib['from'], '\tto:\t', child.attrib['to'] | |
if child.text: | |
print '\t', child.text | |
for child2 in child.getchildren(): | |
if child2.text: | |
print '\t\t', child2.text | |
chats.append(xm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment