mailping (0.0.4-2) MailPing/incoming.py

Summary

 MailPing/incoming.py |   32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

    
download this patch

Patch contents

--- mailping-0.0.4.orig/MailPing/incoming.py
+++ mailping-0.0.4/MailPing/incoming.py
@@ -1,31 +1,31 @@
-import os
+import os, shutil
 from MailPing import mail, maildir, fileutil
 
 def process(statedir):
     def _processEmail(subdir, filename):
         ident = mail.getID(os.path.join(subdir, filename))
         if ident is None:
-            maildir.create(os.path.join(subdir, '..', '..', 'junk'))
-            os.rename(os.path.join(subdir, filename),
-                      os.path.join(subdir, '..', '..', 'junk', 'new', filename))
+            maildir.create(os.path.normpath(os.path.join(subdir, '..', '..', 'junk')))
+            shutil.move(os.path.join(subdir, filename),
+                      os.path.normpath(os.path.join(subdir, '..', '..', 'junk', 'new', filename)))
         else:
-            pending = os.path.join(subdir,
+            pending = os.path.normpath(os.path.join(subdir,
                                    '..', '..',
-                                   'pending', ident)
+                                   'pending', ident))
             timestamp = fileutil.getTime(pending)
             if timestamp < 0:
-                maildir.create(os.path.join(subdir, '..', '..', 'broken'))
-                os.rename(os.path.join(subdir, filename),
-                          os.path.join(subdir, '..', '..', 'broken', 'new', filename))
+                maildir.create(os.path.normpath(os.path.join(subdir, '..', '..', 'broken')))
+                shutil.move(os.path.join(subdir, filename),
+                          os.path.normpath(os.path.join(subdir, '..', '..', 'broken', 'new', filename)))
             else:
-                lastSuccess = fileutil.getTime(os.path.join(subdir,
+                lastSuccess = fileutil.getTime(os.path.normpath(os.path.join(subdir,
                                                             '..', '..',
-                                                            'success'))
+                                                            'success')))
                 if timestamp > lastSuccess:
-                    os.rename(os.path.join(subdir, filename),
-                              os.path.join(subdir, '..', '..', 'success.msg'))
-                    os.rename(pending,
-                              os.path.join(subdir, '..', '..', 'success'))
+                    shutil.move(os.path.join(subdir, filename),
+                              os.path.normpath(os.path.join(subdir, '..', '..', 'success.msg')))
+                    shutil.move(pending,
+                              os.path.normpath(os.path.join(subdir, '..', '..', 'success')))
 
                     deliveryTime = maildir.getTimeFromFilename(filename)
                     if isinstance(deliveryTime, int):
@@ -39,7 +39,7 @@
                         # to do probe sending before incoming processing.
                         timestamp = int(timestamp)
                     if deliveryTime is not None and deliveryTime >= timestamp:
-                        fileutil.writeFile(os.path.join(subdir, '..', '..', 'latency'),
+                        fileutil.writeFile(os.path.normpath(os.path.join(subdir, '..', '..', 'latency')),
                                            '%f\n' % (deliveryTime - timestamp))
                 else:
                     os.unlink(os.path.join(subdir, filename))