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
|
import time
import email, re, string
import getpass, imaplib
M = imaplib.IMAP4_SSL(IMAPSERVER)
M.login("notifier",PASSWD)
M.select()
typ, data = M.search(None, '(SUBJECT "xxx")')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
message = email.message_from_string(data[0][1])
tos = message.get_all("To") or []
ccs = message.get_all("Cc") or []
body = message.get_all("BODY") or [] ## marche pas
subject = message.get_all("Subject") or []
msgdate = time.strftime('%Y_%m_%d.%T', email.Utils.parsedate(message['date']))
print "SUBJECT :" + str(subject)
print "DATE :" + str(msgdate)
all_recipients = email.Utils.getaddresses(tos + ccs)
recipients=[]
for realname, addr in all_recipients:
recipients.append(addr)
print "RECIPIENTS : %s" % recipients[0]
print "body", repr(message.get_payload()) # ne me retourne pas ce que je veux : UNIQUEMENT le texte du corps du message
# print "BODY :\n" + str(body) #retourne [] donc rien! |