diff options
author | R. David Murray <rdmurray@bitdance.com> | 2011-01-07 21:57:25 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2011-01-07 21:57:25 (GMT) |
commit | 6f0022d84af15d51ffa1606991f2b6e9e56448ed (patch) | |
tree | a47fdc84c7487741c7f07b3612f96e70facd677f /Lib/email/header.py | |
parent | 7088abdca6c3e1285c66f51fe907e6c3446773ed (diff) | |
download | cpython-6f0022d84af15d51ffa1606991f2b6e9e56448ed.zip cpython-6f0022d84af15d51ffa1606991f2b6e9e56448ed.tar.gz cpython-6f0022d84af15d51ffa1606991f2b6e9e56448ed.tar.bz2 |
Fix formatting of values with embedded newlines when rfc2047 encoding
Before this patch if a value being encoded had an embedded newline,
the line following the newline would have no leading whitespace,
and the whitespace it did have was encoded into the word. Now
the existing whitespace gets turned into a blank, the way it does
in other header reformatting, and the _continuation_ws gets added
at the beginning of the encoded line.
Diffstat (limited to 'Lib/email/header.py')
-rw-r--r-- | Lib/email/header.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/email/header.py b/Lib/email/header.py index 94eb1a9..d462bf0 100644 --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -305,10 +305,15 @@ class Header: self._continuation_ws, splitchars) for string, charset in self._chunks: lines = string.splitlines() - for line in lines: + formatter.feed(lines[0], charset) + for line in lines[1:]: + formatter.newline() + if charset.header_encoding is not None: + formatter.feed(self._continuation_ws, USASCII) + line = ' ' + line.lstrip() formatter.feed(line, charset) - if len(lines) > 1: - formatter.newline() + if len(lines) > 1: + formatter.newline() formatter.add_transition() return formatter._str(linesep) |