Risolto,
import poplib, mimetypes, email, os ServerPop = poplib.POP3('pop.tiscali.it') ServerPop.user("x...@tiscali.it") ServerPop.pass_("xxx") Cartella = '.' # directory where to save attachments (default: current) NumeroMessaggi = len(ServerPop.list()[1]) for Messaggio in range(NumeroMessaggi): MessaggioCompleto = email.message_from_string('\r\n'.join(ServerPop.retr(Messaggio+1)[1])) print "-"*30 #print MessaggioCompleto print "-"*30 if MessaggioCompleto.get_content_maintype() != 'multipart': continue print "["+MessaggioCompleto["From"]+"] :" + MessaggioCompleto["Subject"] print "Inviato da: " + MessaggioCompleto["From"] print "Oggetto: " +MessaggioCompleto["Subject"] # for part in MessaggioCompleto.walk(): # multipart are just containers, so we skip them if part.get_content_maintype() == 'multipart': continue if part.get('Content-Disposition') is None: continue filename = part.get_filename() counter = 1 if not filename: filename = 'part-%03d%s' % (counter, 'bin') counter += 1 att_path = os.path.join(Cartella, filename) if not os.path.isfile(att_path) : # finally write the stuff fp = open(att_path, 'wb') fp.write(part.get_payload(decode=True)) fp.close() if (raw_input("Cancello? (S/N) ") == "S"): #ServerPop.dele(Messaggio) print "Prossimo messaggio" ServerPop.quit()
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python