Encode utf-8 argument for md5 function

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@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Łukasz Żarnowiecki 2016-05-17 00:44:02 +02:00 committed by Nicolas Sebrecht
parent 2465e1ce6a
commit 23f96ba880

View File

@ -71,7 +71,7 @@ class MaildirFolder(BaseFolder):
# Everything up to the first comma or colon (or ! if Windows): # Everything up to the first comma or colon (or ! if Windows):
self.re_prefixmatch = re.compile('([^'+ self.infosep + ',]*)') self.re_prefixmatch = re.compile('([^'+ self.infosep + ',]*)')
# folder's md, so we can match with recorded file md5 for validity. # 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. # Cache the full folder path, as we use getfullname() very often.
self._fullname = os.path.join(self.getroot(), self.getname()) self._fullname = os.path.join(self.getroot(), self.getname())
# Modification time from 'Date' header. # Modification time from 'Date' header.