From: Brett Parker <iDunno@sommitrealweird.co.uk>
Date: Thu, 20 Dec 2007 14:14:51 +0000 (+0000)
Subject: Add a Message-ID header and set the type to the type of the content in the rss
X-Git-Url: https://git.sommitrealweird.co.uk/rss2maildir.git/commitdiff_plain/e4e1e5427c6afcedb1876b15694e5f473272e164?hp=2dd1439185d4b897f44f2689fb730df54075b302

Add a Message-ID header and set the type to the type of the content in the rss
feed.
---

diff --git a/rss2maildir.py b/rss2maildir.py
index b48498e..968c647 100755
--- a/rss2maildir.py
+++ b/rss2maildir.py
@@ -14,9 +14,13 @@ import datetime
 import random
 import string
 
+import socket
+
 from optparse import OptionParser
 from ConfigParser import SafeConfigParser
 
+from base64 import b64encode
+
 
 def parse_and_deliver(maildir, url, statedir):
     md = mailbox.Maildir(maildir)
@@ -24,17 +28,21 @@ def parse_and_deliver(maildir, url, statedir):
     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.set_unixfrom("\"%s\" <rss2maildir@localhost>" %(url))
+        msg.add_header("From", "\"%s\" <rss2maildir@localhost>" %(item["author"]))
+        msg.add_header("To", "\"%s\" <rss2maildir@localhost>" %(url))
         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.add_header("Subject", item["title"])
         msg.set_charset("utf8")
-        msg.set_default_type("text/plain")
+        msg.set_default_type(item["content"][0]["type"])
+        msg.set_type(item["content"][0]["type"])
+        msg.set_payload(b64encode(item["content"][0]["value"]))
+
+        msg.add_header("Message-ID", "<" + datetime.datetime.now().strftime("%Y%m%d%H%M") + "." + "".join([random.choice(string.ascii_letters + string.digits) for a in range(0,6)]) + "@" + socket.gethostname() + ">")
 
         # start by working out the filename we should be writting to, we do
         # this following the normal maildir style rules
-        fname = str(os.getpid()) + "".join([random.choice(string.ascii_letters + string.digits) for a in range(0,10)]) + datetime.datetime.now().strftime('%s')
+        fname = str(os.getpid()) + "." + socket.gethostname() + "." + "".join([random.choice(string.ascii_letters + string.digits) for a in range(0,10)]) + "." + datetime.datetime.now().strftime('%s')
         fn = os.path.join(maildir, "tmp", fname)
         fh = open(fn, "w")
         fh.write(msg.as_string())