#!/usr/bin/python import datetime import PyRSS2Gen from mailbox import Maildir import os,sys def genItems(): maildir=Maildir(os.path.dirname(os.path.abspath(__file__)) + "/Maildir") for key in maildir.keys(): msg = maildir[key] try: subject = msg['subject'] author=msg['from'] msg.rewindbody() description = msg.fp.read() rfcdate = msg.getdate('date') date=datetime.datetime(*rfcdate[:-2]) item=PyRSS2Gen.RSSItem( title=subject, author=author, link="http://xapek.org", description=description, pubDate=date ) yield item sys.stderr.write( "processed %s\n" % key) except Exception,e: sys.stderr.write("skip %s: %s\n" % (key,str(e))) rss = PyRSS2Gen.RSS2( title = "Spamfeed", link = "http://www.xapek.org/~yvesf/spam", description = "Spam spam spam", lastBuildDate = datetime.datetime.now(), items=list(genItems()) ) rss.write_xml(sys.stdout)