Mail Collector: Difference between revisions
Marie Wocher (talk | contribs) (Created page with "A little script to collect all Mails from a gmail label <source lang="python"> #!/usr/bin/env python #-*- coding:utf-8 -*- from password import password import imaplib impor...") |
Marie Wocher (talk | contribs) No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 13: | Line 13: | ||
mail = imaplib.IMAP4_SSL('imap.gmail.com') | mail = imaplib.IMAP4_SSL('imap.gmail.com') | ||
mail.login(' | mail.login('name@gmail.com', password) | ||
mail.list() | mail.list() | ||
mail.select(" | mail.select("Label") # connect to folder with matching label | ||
result, data = mail.uid('Search', None, "ALL") # search and return uids instead | result, data = mail.uid('Search', None, "ALL") # search and return uids instead | ||
i = len(data[0].split()) | i = len(data[0].split()) | ||
myfile = open(" | myfile = open("allemails.txt", 'w') | ||
for x in range(i): | for x in range(i): | ||
latest_email_uid = data[0].split()[x] | latest_email_uid = data[0].split()[x] |
Latest revision as of 21:45, 18 January 2012
A little script to collect all Mails from a gmail label
<source lang="python">
- !/usr/bin/env python
- -*- coding:utf-8 -*-
from password import password
import imaplib import email import codecs
mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login('name@gmail.com', password) mail.list() mail.select("Label") # connect to folder with matching label
result, data = mail.uid('Search', None, "ALL") # search and return uids instead i = len(data[0].split()) myfile = open("allemails.txt", 'w') for x in range(i): latest_email_uid = data[0].split()[x] result, email_data = mail.uid('fetch', latest_email_uid, '(RFC822)') raw_email = email_data[0][1] email_message = str(email.message_from_string(raw_email)).decode("quoted-printable") myfile.write(email_message) print x print "of" print i myfile.close()