]> code.delx.au - offlineimap/commitdiff
Fix md5 import error
authorPaul Hinze <paul.t.hinze@gmail.com>
Wed, 24 Dec 2008 18:22:10 +0000 (12:22 -0600)
committerJohn Goerzen <jgoerzen@complete.org>
Fri, 9 Jan 2009 21:46:38 +0000 (15:46 -0600)
Paul Hinze <paul.t.hinze@gmail.com> on 2008-12-22 at 19:16:
> I did a bit of debugging and asking around in #python and it turns out
> that because Maildir.py uses a conditional import of md5 from either
> hashlib or the md5 module, the md5.new() call is not always correct.
> The attached patch should fix this problem.

Thanks to Daniel Rall for pointing out that the attachment got stripped
off my last message.  Patch follows.

Paul

----

From e01fdfbf62c61c31b514e826e6cc00fb98d88808 Mon Sep 17 00:00:00 2001
From: Paul Hinze <paul.t.hinze@gmail.com>
Date: Mon, 22 Dec 2008 18:42:44 -0600
Subject: [PATCH] Fixing md5 import when hashlib is available

Thanks to habnabit and Rhamphoryncus in #python for help debugging

offlineimap/folder/Maildir.py

index d1d5077a903a35e23000be270446378e5ae23f52..937500f0b7e9f28ddf5ad33bbc36565cc68eec11 100644 (file)
@@ -25,7 +25,7 @@ from threading import Lock
 try:
     from hashlib import md5
 except ImportError:
-    import md5
+    from md5 import md5
 
 uidmatchre = re.compile(',U=(\d+)')
 flagmatchre = re.compile(':.*2,([A-Z]+)')
@@ -84,7 +84,7 @@ class MaildirFolder(BaseFolder):
         files = []
         nouidcounter = -1               # Messages without UIDs get
                                         # negative UID numbers.
-        foldermd5 = md5.new(self.getvisiblename()).hexdigest()
+        foldermd5 = md5(self.getvisiblename()).hexdigest()
         folderstr = ',FMD5=' + foldermd5
         for dirannex in ['new', 'cur']:
             fulldirname = os.path.join(self.getfullname(), dirannex)
@@ -177,7 +177,7 @@ class MaildirFolder(BaseFolder):
                            os.getpid(),
                            socket.gethostname(),
                            uid,
-                           md5.new(self.getvisiblename()).hexdigest())
+                           md5(self.getvisiblename()).hexdigest())
             if os.path.exists(os.path.join(tmpdir, messagename)):
                 time.sleep(2)
                 attempts += 1