fixed link to the projects/source page and docs on sending patches
[gmail-maildir-counter] / count_gmail.py
1 #!/usr/bin/env python
2
3 import mailbox
4 import rfc822
5 import email.utils
6 import time
7 import sys
8 import os.path
9
10 md_name = os.path.expanduser(sys.argv[1])
11
12 inbox = mailbox.Maildir(md_name, factory=None)
13
14 for msg in inbox:
15     flags = msg.get_flags()
16     #date = msg.get_date()
17     date = msg.get("Date")
18
19     if date == None:
20         continue
21     else:
22         date = email.utils.parsedate(date)
23         if date == None:
24             continue
25         else:
26             date = time.mktime(date)
27
28     precedence = msg.get("Precedence")
29     if precedence == None:
30         precedence = "NA"
31     
32     google = "FALSE"
33     recvd_list = msg.get_all("Received")
34
35     # skip this message if there are no received headers (malformed?)
36     if recvd_list == None:
37         continue
38
39     # if there is a list of received headers, skip
40     for recvd in recvd_list:
41         if "google.com" in recvd or "gmail.com" in recvd or "googlemail.com" in recvd:
42             google = "TRUE"
43
44     # put it together and output        
45     print("\t".join([flags, str(date), precedence, google]))
46
47

Benjamin Mako Hill || Want to submit a patch?