-        # 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()) + "." + 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)