Decode byte pattern into string using proper encoding
The IMAP response is `str` and a `re.match()` needs to use a `str` type pattern. Depending on the encoding supported by the IMAP response, the literal patterns need to be decoded using the correct (supported) encoding. Signed-off-by: Nicolas Bock <nicolasbock@gmail.com>
This commit is contained in:
parent
564930725e
commit
94b5e357c1
|
@ -435,8 +435,8 @@ class IMAP4(object):
|
||||||
self.utf8_enabled = False
|
self.utf8_enabled = False
|
||||||
self._encoding = 'ascii'
|
self._encoding = 'ascii'
|
||||||
if bytes != str:
|
if bytes != str:
|
||||||
self.literal_cre = re.compile(self._literal, re.ASCII)
|
self.literal_cre = re.compile(self._literal.decode("ASCII"), re.ASCII)
|
||||||
self.untagged_status_cre = re.compile(self._untagged_status, re.ASCII)
|
self.untagged_status_cre = re.compile(self._untagged_status.decode("ASCII"), re.ASCII)
|
||||||
else:
|
else:
|
||||||
self.literal_cre = re.compile(self._literal)
|
self.literal_cre = re.compile(self._literal)
|
||||||
self.untagged_status_cre = re.compile(self._untagged_status)
|
self.untagged_status_cre = re.compile(self._untagged_status)
|
||||||
|
@ -446,8 +446,8 @@ class IMAP4(object):
|
||||||
self.utf8_enabled = True
|
self.utf8_enabled = True
|
||||||
self._encoding = 'utf-8'
|
self._encoding = 'utf-8'
|
||||||
if bytes != str:
|
if bytes != str:
|
||||||
self.literal_cre = re.compile(self._literal)
|
self.literal_cre = re.compile(self._literal.decode(self._encoding))
|
||||||
self.untagged_status_cre = re.compile(self._untagged_status)
|
self.untagged_status_cre = re.compile(self._untagged_status.decode(self._encoding))
|
||||||
else:
|
else:
|
||||||
self.literal_cre = re.compile(self._literal, re.UNICODE)
|
self.literal_cre = re.compile(self._literal, re.UNICODE)
|
||||||
self.untagged_status_cre = re.compile(self._untagged_status, re.UNICODE)
|
self.untagged_status_cre = re.compile(self._untagged_status, re.UNICODE)
|
||||||
|
|
Loading…
Reference in New Issue