Well, I will show you how to do something like these.
Scenario: An chronological script will download new e-mails, then a Python script will process on these e-mails.
For downloading e-mails, I used getmail4. The best tutorial for it can be found here.
For my case, /home/manchurian/.getmail/getmailrc looks like this:
[retriever] type = SimplePOP3Retriever server = [my_mail_server] username = [my_mail] password = [my_mail_password] [destination] type = Mboxrd path = /home/manchurian/inbox
Make the mail downloading automatic using crontab -e:
* * * * * getmail -n
-n is for retrieving new mails only.
Now it is time to process the downloaded mails anyway you want:
import mailbox
mails = mailbox.mbox("/home/manchurian/inbox")
mails.lock()
try:
for m in mailbox:
if m['from'] == 'abc@abc.org':
print m['subject']
finally:
mails.unlock()
Cheers,