summaryrefslogtreecommitdiff
path: root/maildir2rss.py
diff options
context:
space:
mode:
Diffstat (limited to 'maildir2rss.py')
-rwxr-xr-x[-rw-r--r--]maildir2rss.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/maildir2rss.py b/maildir2rss.py
index 563a48f..b50beef 100644..100755
--- a/maildir2rss.py
+++ b/maildir2rss.py
@@ -1,37 +1,38 @@
+#!/usr/bin/python
import datetime
import PyRSS2Gen
from mailbox import Maildir
import os,sys
-maildir=Maildir(os.path.dirname(os.path.abspath(__file__)) + "/Maildir")
+def genItems():
+ maildir=Maildir(os.path.dirname(os.path.abspath(__file__)) + "/Maildir")
-items=[]
-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
- )
- items.append(item)
- sys.stderr.write( "processed %s\n" % key)
- except Exception,e:
- sys.stderr.write("skip %s: %s\n" % (key,str(e)))
+ 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=items
+ items=list(genItems())
)
rss.write_xml(sys.stdout)