lines = line.splitlines()
return zip(lines, [charset]*len(lines))
- def _encode_chunks(self, newchunks):
+ def _encode_chunks(self, newchunks, maxlinelen):
# MIME-encode a header with many different charsets and/or encodings.
#
# Given a list of pairs (string, charset), return a MIME-encoded
s = header
else:
s = charset.header_encode(header)
- _max_append(chunks, s, self._maxlinelen, ' ')
+ _max_append(chunks, s, maxlinelen, ' ')
joiner = NL + self._continuation_ws
return joiner.join(chunks)
newchunks += self._split(s, charset, targetlen, splitchars)
lastchunk, lastcharset = newchunks[-1]
lastlen = lastcharset.encoded_header_len(lastchunk)
- return self._encode_chunks(newchunks)
+ return self._encode_chunks(newchunks, maxlinelen)
\f
def _split_ascii(s, firstlen, restlen, continuation_ws, splitchars):
+ linejoiner = '\n' + continuation_ws
lines = []
maxlen = firstlen
for line in s.splitlines():
# splitting on whitespace, try to recursively split this line
# on whitespace.
if partlen > maxlen and ch <> ' ':
- this = [_split_ascii(part, maxlen, restlen,
- continuation_ws, ' ')]
+ subs = _split_ascii(part, maxlen, restlen,
+ continuation_ws, ' ')
+ subl = re.split(linejoiner, subs)
+ lines.extend(subl[:-1])
+ this = [subl[-1]]
else:
this = [part]
- linelen = wslen + partlen
+ linelen = wslen + len(this[-1])
maxlen = restlen
else:
this.append(part)
# Put any left over parts on a line by themselves
if this:
lines.append(joiner.join(this))
- linejoiner = '\n' + continuation_ws
return linejoiner.join(lines)