PopChecker
Aus DebianforumWiki
| |
Review: Dieser Artikel ist für das Review freigegeben.
|
Dieses Skript holt bestimmte Headerzeilen von allen E-Mails eines POP3-Accounts und gibt diese zusammen mit der Größe der E-Mails auf stdout aus. Es wäre sehr schön und sinnvoll, wenn dieses Skript auch eine Interaktion ermöglichen würde, um E-Mails selektiv herunter zu laden oder zu löschen, allerdings hatte ich dazu bisher noch keine Lust gehabt.
#!/usr/bin/env python """\ This program checks for mail in a pop account and displays some header information of it and which size the mail has. """ import sys import getpass import poplib # used variables messages= [] # ask for popserver, username and password and delete the newline char print "popserver: ", popserver= sys.stdin.readline()[:-1] print "username: ", username= sys.stdin.readline()[:-1] password= getpass.getpass("password: ") # open the popserver pop= poplib.POP3(popserver) # enter the server pop.apop(username, password) # for every message for i in range(0, len(pop.list()[1])): # this is one message(-header) msg= pop.top(i+1,0)[1] # these are the needed fields h_from= '' h_date= '' h_to= '' h_subject='' size= '' # fill the fields for line in msg: if line[:5] == 'From:': h_from= line if line[:5] == 'Date:': h_date= line if line[:3] == 'To:': h_to= line if line[:8] == 'Subject:': h_subject= line size= pop.top(i+1,0)[2] messages.append({'from':h_from, 'date':h_date, 'to': h_to, 'subject':h_subject, 'size':size}) print print messages[i]['from'] print messages[i]['date'] print messages[i]['to'] print messages[i]['subject'] print 'Size:',messages[i]['size'], 'octets' pop.quit()
| |
Lizenz: Dieser Artikel lässt keine offenen Lizenzfragen. D.h. er kann ohne Bedenken migriert werden. |