+
+def parse_and_deliver(maildir, url, statedir):
+ md = mailbox.Maildir(maildir)
+ fp = feedparser.parse(url)
+ for item in fp["items"]:
+ # things that we need in the message
+ msg = email.message_from_string("")
+ msg.add_header("Subject", item["title"])
+ msg.set_unixfrom("Brett Parker <iDunno@sommitrealweird.co.uk>")
+ msg.add_header("Date", datetime.datetime(*item["created_parsed"][0:6]).strftime("%a, %e %b %Y %T -0000"))
+ msg.add_header("To", url)
+ msg.set_payload(item["content"][0]["value"])
+ msg.set_charset("utf8")
+ msg.set_default_type("text/plain")
+
+ # open a temporary file in the maildir
+ fn = os.tempnam(os.path.join(maildir, "tmp"))
+ fh = open(fn, "w")
+ fh.write(msg.as_string())
+ fh.close()
+ # now move it in to the new directory
+ newfn = os.tempnam(os.path.join(maildir, "new"))
+ os.link(fn, newfn)
+ os.unlink(fn)
+