From 6f0022d84af15d51ffa1606991f2b6e9e56448ed Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Fri, 7 Jan 2011 21:57:25 +0000 Subject: [PATCH] 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. --- Lib/email/header.py | 11 ++++++++--- Lib/email/test/test_email.py | 13 +++++++++++++ Misc/NEWS | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Lib/email/header.py b/Lib/email/header.py index 94eb1a94aa..d462bf008f 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) diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index e7fcee3b6d..4855371d1b 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -968,6 +968,19 @@ List: List-Unsubscribe: = 1000 otherwise. The year range @@ -47,7 +52,6 @@ Library dependent, but ``time.mktime`` will now accept full range supported by the OS. Conversion of 2-digit years to 4-digit is deprecated. - - Issue #7858: Raise an error properly when os.utime() fails under Windows on an existing file. -- 2.40.0