From: Brett Parker Date: Thu, 20 Dec 2007 01:14:02 +0000 (+0000) Subject: Much better filename creation for the tmp file X-Git-Url: https://git.sommitrealweird.co.uk/rss2maildir.git/commitdiff_plain/2dd1439185d4b897f44f2689fb730df54075b302?ds=inline Much better filename creation for the tmp file --- diff --git a/rss2maildir.py b/rss2maildir.py index a735d3a..b48498e 100755 --- a/rss2maildir.py +++ b/rss2maildir.py @@ -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)