Merge of the folding-reimpl-branch. Specific changes,
_max_append(): Change the comparison so that the new string is concatenated if it's less than or equal to the max length. header_encode(): Allow for maxlinelen == None to mean, don't do any line splitting. This is because this module is mostly used by higher level abstractions (Header.py) which already ensures line lengths. We do this in a cheapo way by setting the max_encoding to some insanely <100k wink> large number.
This commit is contained in:
parent
e8577b7298
commit
0ed81c35a7
|
@ -82,7 +82,7 @@ def body_quopri_len(str):
|
||||||
def _max_append(L, s, maxlen, extra=''):
|
def _max_append(L, s, maxlen, extra=''):
|
||||||
if not L:
|
if not L:
|
||||||
L.append(s.lstrip())
|
L.append(s.lstrip())
|
||||||
elif len(L[-1]) + len(s) < maxlen:
|
elif len(L[-1]) + len(s) <= maxlen:
|
||||||
L[-1] += extra + s
|
L[-1] += extra + s
|
||||||
else:
|
else:
|
||||||
L.append(s.lstrip())
|
L.append(s.lstrip())
|
||||||
|
@ -116,7 +116,8 @@ def header_encode(header, charset="iso-8859-1", keep_eols=False,
|
||||||
=?charset?q?Silly_=C8nglish_Kn=EEghts?="
|
=?charset?q?Silly_=C8nglish_Kn=EEghts?="
|
||||||
|
|
||||||
with each line wrapped safely at, at most, maxlinelen characters (defaults
|
with each line wrapped safely at, at most, maxlinelen characters (defaults
|
||||||
to 76 characters).
|
to 76 characters). If maxlinelen is None, the entire string is encoded in
|
||||||
|
one chunk with no splitting.
|
||||||
|
|
||||||
End-of-line characters (\\r, \\n, \\r\\n) will be automatically converted
|
End-of-line characters (\\r, \\n, \\r\\n) will be automatically converted
|
||||||
to the canonical email line separator \\r\\n unless the keep_eols
|
to the canonical email line separator \\r\\n unless the keep_eols
|
||||||
|
@ -134,9 +135,13 @@ def header_encode(header, charset="iso-8859-1", keep_eols=False,
|
||||||
header = fix_eols(header)
|
header = fix_eols(header)
|
||||||
|
|
||||||
# Quopri encode each line, in encoded chunks no greater than maxlinelen in
|
# Quopri encode each line, in encoded chunks no greater than maxlinelen in
|
||||||
# lenght, after the RFC chrome is added in.
|
# length, after the RFC chrome is added in.
|
||||||
quoted = []
|
quoted = []
|
||||||
max_encoded = maxlinelen - len(charset) - MISC_LEN
|
if maxlinelen is None:
|
||||||
|
# An obnoxiously large number that's good enough
|
||||||
|
max_encoded = 100000
|
||||||
|
else:
|
||||||
|
max_encoded = maxlinelen - len(charset) - MISC_LEN - 1
|
||||||
|
|
||||||
for c in header:
|
for c in header:
|
||||||
# Space may be represented as _ instead of =20 for readability
|
# Space may be represented as _ instead of =20 for readability
|
||||||
|
|
Loading…
Reference in New Issue