a little OT: how to handle this email list?

Gerrit Holl gerrit at nl.linux.org
Tue Sep 23 16:53:09 CEST 2003


Matthew Wilson wrote:
> I subscribe to the python mailing list with an IMAP mailbox.  I use
> squirrelmail to check my mail.  This is a great list, but it is definitely
> high volume.  My python folder fills up with several hundred emails every
> day.  How do the rest of you handle all the traffic on this list?  Do you
> delete everything at the end of every day?
> 
> All insights are welcomed.

I use a python script :)
This python script is called by procmail, a mail filtering program (Linux).
The first argument is the file in which it should be redirected, the input
is the e-mail message. It reads the e-mail, checks the DATE header and
throws the e-mail into the mailbox for this week. Every week, I start a new
mailbox.

#!/usr/bin/env python

"""Appends email message from standard input to mailbox argv[1] in the correct date"""

import os
import sys
import email
import email.Utils
import time

MAILDIR = "/home/gerrit/email"

def getdestfromdate(d):
    timetuple = email.Utils.parsedate(d)
    print d, "=>", timetuple
    timetuple = time.localtime(time.mktime(timetuple))
    subfile = sys.argv[1]
    jaar = time.strftime("%Y", timetuple)
    week = time.strftime("%U", timetuple)
    dest = os.path.join(MAILDIR, jaar, week, subfile)
    return dest

def main():
    message = email.message_from_file(sys.stdin)
    dest = getdestfromdate(message["Date"])
    print "Appending to", dest
    if not os.path.exists(os.path.dirname(dest)):
        print "creating dir for", dest
        os.makedirs(os.path.dirname(dest))
    fp = open(dest, "a")
    fp.write(str(message))
    fp.close()

if __name__ == "__main__":
    main()

Note that this may not run with Python prior to 2.3.

Gerrit.

-- 
220. If he had opened a tumor with the operating knife, and put out his
eye, he shall pay half his value.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list