From 0ed81c35a79209405df249921b3382ddef6284ff Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 6 Mar 2003 05:14:20 +0000 Subject: 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. --- Lib/email/quopriMIME.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/email/quopriMIME.py b/Lib/email/quopriMIME.py index 18ddd89..67369b5 100644 --- a/Lib/email/quopriMIME.py +++ b/Lib/email/quopriMIME.py @@ -82,7 +82,7 @@ def body_quopri_len(str): def _max_append(L, s, maxlen, extra=''): if not L: L.append(s.lstrip()) - elif len(L[-1]) + len(s) < maxlen: + elif len(L[-1]) + len(s) <= maxlen: L[-1] += extra + s else: 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?=" 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 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) # 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 = [] - 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: # Space may be represented as _ instead of =20 for readability -- cgit v0.12