1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import imaplib
import email
imaplib.IMAP4.debug = imaplib.IMAP4_SSL.debug = 1
username,passwd = ('usuario','password')
con = imaplib.IMAP4_SSL('host',993)
con.login(username, passwd)
con.select()
typ, data = con.search(None, '(UNSEEN)')
c = 0
for num in data[0].split():
typ, data = con.fetch(num, '(RFC822)')
c +=1
text = data[0][1]
msg = email.message_from_string(text)
for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
filename = part.get_filename()
data = part.get_payload(decode=True)
if not data:
continue
f = open(os.join(os.environ['HOME'],filename), 'w')
f.write(data)
f.close()
con.close()
con.logout() |
Partager