summaryrefslogtreecommitdiff
path: root/maildir2rss.py
blob: b50beefb90b33c16dda8e0d13896744fe75c3d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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)