blog-agent

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit ded452d165e5462423ef775fef79dcfc7f3fff13
parent 6d02bcf72f56e9b781ea6ae7394173654f42553c
Author: dankert <devnull@localhost>
Date:   Sat, 11 Jan 2014 01:58:06 +0100

Abspeichern der Mail-Bestandteile

Diffstat:
abholer.py | 39++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/abholer.py b/abholer.py @@ -2,19 +2,31 @@ # E-Mail-Abholer # # -import imaplib,email +import imaplib,email,datetime,os,base64,quopri M = imaplib.IMAP4("mail.jdhh.de") -M.login("blog@jandankert.de", "blogmaschine") +M.login("blog@jandankert.de", "") M.select("INBOX") typ, data = M.search(None, 'ALL') + for num in data[0].split(): + + now = datetime.datetime.now() + dir = os.path.dirname( os.path.realpath( __file__ ) )+'/../blog/'+str(now)+'/' + os.mkdir(dir) + + f = open(dir+'title', 'w') typ, data = M.fetch(num, '(RFC822)') - print 'Message #'+num; + #print 'Message #'+num; src = data[0][1] msg = email.message_from_string(src) print "Subject: "+msg["Subject"] + f.write(msg["Subject"]) + + f = open(dir+'sender','w') + #print "From: "+msg["From"] + f.write(msg["From"]) #for pl in get_flat_parts(msg): @@ -22,12 +34,21 @@ for num in data[0].split(): if part.is_multipart(): continue - - print " Typ:"+part.get_content_type() - print " Inhalt:"+part.get_payload() - #print "Filename:"+part.get_filename() - print "\n" - print "\n\n" + + + #print " Typ:"+part.get_content_type() + #print " Inhalt:"+part.get_payload() + + if part.get_content_type() == "text/plain": + f= open(dir+'text','w') + f.write( quopri.decodestring(part.get_payload()) ) + elif part.get_content_type()[:6] == "image/": + f = open( dir + 'attachment-'+part.get_filename(),'w' ) + f.write( base64.decodestring( part.get_payload() ) ) + else: + print "Unbekannter Typ: "+part.get_content_type() + #print "\n" + #print "\n\n" M.copy(num,"Archiv") M.store(num, '+FLAGS', r'(\Deleted)')