MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
September
Sun Mon Tue Wed Thu Fri Sat
   
12
     
2015
Months
Sep


Sat, Sep 12, 2015 10:32 pm

Find email messages in a mbox file using python

I wanted to locate messages from any sender at a particular domain name in the mailbox for an account on a Linux system. The server where the acount resides uses sendmail and dovecot for email and the mailbox file for the account was in mbox format. When email is stored in mbox format, all email messages in the inbox are stored in the same text file. The beginning of each email message is indicated by a line whose first five characters consist of "From" followed by a space (the so named "From_ line" or "'From ' line" or simply "From line") followed by the sender's e-mail address.

In this case, the mailbox was huge with tens of thousands of messages in a file 24 GB in size and I wanted to extract just a few pertinent messages. So I created find-email.py, which can be run in either "brief" or "full" mode by changing the value of a variable named brief in the script. In brief mode, the script will just print the "from" line for any message where a sender's email address matches the specified address followed by the subject of the message and then the date the message was sent. When all messages in the file have been processed, it will print the number of matching messages found. In "full" mode, the script will print the entire email message whenever a match is found.

[/languages/python] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo