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]: def utf7m_decode(binary: bytes) -> Tuple[str, int]:
r = [] r = []
decode = [] decode = []
for c in binary.decode(): for c in binary:
if c == '&' and not decode: if c == ord('&') and not decode:
decode.append('&') decode.append('&')
elif c == '-' and decode: elif c == ord('-') and decode:
if len(decode) == 1: if len(decode) == 1:
r.append('&') r.append('&')
else: else:
r.append(modified_unbase64(''.join(decode[1:]))) r.append(modified_unbase64(''.join(decode[1:])))
decode = [] decode = []
elif decode: elif decode:
decode.append(c) decode.append(chr(c))
else: else:
r.append(c) r.append(chr(c))
if decode: if decode:
r.append(modified_unbase64(''.join(decode[1:]))) r.append(modified_unbase64(''.join(decode[1:])))