Merge pull request #114 from lilydjwg/master

fix imap4-utf-7 decoding errors
This commit is contained in:
Rodolfo García Peñas (kix) 2022-03-25 11:36:27 +01:00 committed by GitHub
commit 6cec099e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -403,19 +403,19 @@ def modified_unbase64(s):
def utf7m_decode(binary: bytes) -> Tuple[str, int]:
r = []
decode = []
for c in binary.decode():
if c == '&' and not decode:
for c in binary:
if c == ord('&') and not decode:
decode.append('&')
elif c == '-' and decode:
elif c == ord('-') and decode:
if len(decode) == 1:
r.append('&')
else:
r.append(modified_unbase64(''.join(decode[1:])))
decode = []
elif decode:
decode.append(c)
decode.append(chr(c))
else:
r.append(c)
r.append(chr(c))
if decode:
r.append(modified_unbase64(''.join(decode[1:])))