1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-04 10:24:41 +02:00

as per review

This commit is contained in:
Florent Daigniere 2024-09-07 19:03:02 +02:00
parent d70e82765f
commit 2b9ba9ba3a

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import base64 import binascii
import time import time
import os import os
from pathlib import Path from pathlib import Path
@ -34,20 +34,18 @@ poll "{host}" proto {protocol} port {port}
""" """
def imaputf7encode(s): def imaputf7encode(s):
""""Encode a string into RFC2060 aka IMAP UTF7""" """Encode a string into RFC2060 aka IMAP UTF7"""
s=s.replace('&','&-') out = ''
iters=iter(s) enc = ''
unipart=out='' for c in s.replace('&','&-') + 'X':
for c in s: if '\x20' <= c <= '\x7f':
if 0x20<=ord(c)<=0x7f : if enc:
if unipart!='' : out += f'&{binascii.b2a_base64(enc.encode("utf-16-be")).rstrip(b"\n=").replace(b"/", b",").decode("ascii")}-'
out+='&'+base64.b64encode(unipart.encode('utf-16-be')).decode('ascii').rstrip('=')+'-' enc = ''
unipart='' out += c
out+=c else:
else : unipart+=c enc += c
if unipart!='' : return out[:-1]
out+='&'+base64.b64encode(unipart.encode('utf-16-be')).decode('ascii').rstrip('=')+'-'
return out
def escape_rc_string(arg): def escape_rc_string(arg):
return "".join("\\x%2x" % ord(char) for char in arg) return "".join("\\x%2x" % ord(char) for char in arg)