]> git.sommitrealweird.co.uk Git - rss2maildir.git/commitdiff
Much better filename creation for the tmp file
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 20 Dec 2007 01:14:02 +0000 (01:14 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Thu, 20 Dec 2007 01:14:02 +0000 (01:14 +0000)
rss2maildir.py

index a735d3af1ef349f302cd0467f44b710ca452573d..b48498efd49801f4cee0554e7c2b3b06e7eed986 100755 (executable)
@@ -11,6 +11,8 @@ import feedparser
 import email
 
 import datetime
+import random
+import string
 
 from optparse import OptionParser
 from ConfigParser import SafeConfigParser
@@ -30,13 +32,15 @@ def parse_and_deliver(maildir, url, statedir):
         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"))
+        # 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')
+        fn = os.path.join(maildir, "tmp", fname)
         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"))
+        newfn = os.path.join(maildir, "new", fname)
         os.link(fn, newfn)
         os.unlink(fn)