[PATCH] Encode utf-8 argument for md5 function

Nicolas Sebrecht nicolas.s-dev at laposte.net
Tue May 17 00:01:39 BST 2016

From: Łukasz Żarnowiecki <dolohow at outlook.com>

Python3 accepts binary input for md5 function.

This patch is known to break setups using folder names not strictly conforming
the IMAP UTF-7 encoding. We always made it clear that such setup is unsupported
and might be broken at some point in time. See documentation about
'decodefoldernames' in the provided configuration file. This is why this patch
is considered introducing no regression for this use case.

Patches to support both Python 3 and Python 2 by re-encoding the MD5 in the
filenames are welcome. This likely requires a new CLI option to allow
backporting the feature for users downgrading or changing of Python environment.

Signed-off-by: Łukasz Żarnowiecki <dolohow at outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
 offlineimap/folder/Maildir.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index bf40194..58e4cad 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -71,7 +71,7 @@ class MaildirFolder(BaseFolder):
         # Everything up to the first comma or colon (or ! if Windows):
         self.re_prefixmatch = re.compile('([^'+ self.infosep + ',]*)')
         # folder's md, so we can match with recorded file md5 for validity.
-        self._foldermd5 = md5(self.getvisiblename()).hexdigest()
+        self._foldermd5 = md5(self.getvisiblename().encode('utf-8')).hexdigest()
         # Cache the full folder path, as we use getfullname() very often.
         self._fullname = os.path.join(self.getroot(), self.getname())
         # Modification time from 'Date' header.

More information about the OfflineIMAP-project mailing list