document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import sys
  2. import os
  3. import time
  4. import getopt
  5. import shutil
  6.  
  7. INDENT = \'   \'
  8.  
  9. help_message = \'\'\'
  10. ./mail_info.py --maildir <mail dir>
  11.  
  12.    Looks at OSX local users mail store and reports some stats
  13.    
  14.    --maildir - point to an imap folder for your email account
  15.    
  16.    i.e.
  17.        ./mail_info.py --maildir "/Users/rob/Library/Mail/IMAP-rob@foo.com"
  18. \'\'\'
  19.  
  20. class Usage(Exception):
  21.     def __init__(self, msg):
  22.         self.msg = msg
  23.  
  24. def splitthousands(s, sep=\',\'):
  25.     if len(s) <= 3:
  26.         return s
  27.     return splitthousands(s[:-3], sep) + sep + s[-3:]
  28.  
  29.  
  30. def main(argv=None):
  31.     version = None
  32.    
  33.     if argv is None:
  34.         argv = sys.argv
  35.     try:
  36.         try:
  37.             opts, args = getopt.getopt(argv[1:], "hm:", ["help", "maildir="])
  38.         except getopt.error, msg:
  39.             raise Usage(msg)
  40.    
  41.         maildir = None
  42.        
  43.         # option processing
  44.         for option, value in opts:
  45.             if option in ("-h", "--help"):
  46.                 raise Usage(help_message)
  47.             if option in ("-m", "--maildir"):
  48.                 maildir = value
  49.  
  50.     except Usage, err:
  51.         print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
  52.         print >> sys.stderr, "\\t for help use --help"
  53.         return 2
  54.    
  55.     if not maildir:
  56.         raise Usage("--maildir required")
  57.  
  58.     emails_processed = 0
  59.     iphone_emails = 0
  60.     mime_version = 0
  61.     email_to = 0
  62.     for root, dirs, files in os.walk(os.path.join(maildir, "Sent Messages.imapmbox","Messages")):
  63.         for afile in files:
  64.             emails_processed += 1
  65.             email_to_found = False
  66.             for line in open(os.path.join(root, afile), \'r\'):
  67.                 if not email_to_found:
  68.                     if line.find("To: ") != -1:
  69.                         email_to += 1
  70.                         email_to_found = True
  71.                 if line.find("Mime-Version") != -1:
  72.                     mime_version += 1
  73.                     if line.find(\'iPhone Mail\') != -1:
  74.                         iphone_emails += 1
  75.                     continue
  76.                    
  77.     print "Emails Sent:",splitthousands(str(emails_processed))
  78.     print "iPhone Emails:",splitthousands(str(iphone_emails)),"(%.2f%%)" % ((100.0*iphone_emails)/emails_processed)
  79.    
  80. if __name__ == \'__main__\':
  81.     main()
');