@@ -140,6 +140,39 @@ def test_flatten_linesep_overrides_policy(self):
140140 g .flatten (msg , linesep = '\n ' )
141141 self .assertEqual (s .getvalue (), self .typ (expected ))
142142
143+ def test_flatten_linesep (self ):
144+ source = 'Subject: one\n two\r three\r \n four\r \n \r \n test body\r \n '
145+ msg = self .msgmaker (self .typ (source ))
146+ self .assertEqual (msg ['Subject' ], 'one two three four' )
147+
148+ expected = 'Subject: one\n two\n three\n four\n \n test body\n '
149+ s = self .ioclass ()
150+ g = self .genclass (s )
151+ g .flatten (msg )
152+ self .assertEqual (s .getvalue (), self .typ (expected ))
153+
154+ expected = 'Subject: one two three four\n \n test body\n '
155+ s = self .ioclass ()
156+ g = self .genclass (s , policy = self .policy .clone (refold_source = 'all' ))
157+ g .flatten (msg )
158+ self .assertEqual (s .getvalue (), self .typ (expected ))
159+
160+ def test_flatten_control_linesep (self ):
161+ source = 'Subject: one\v two\f three\x1c four\x1d five\x1e six\r \n \r \n test body\r \n '
162+ msg = self .msgmaker (self .typ (source ))
163+ self .assertEqual (msg ['Subject' ], 'one\v two\f three\x1c four\x1d five\x1e six' )
164+
165+ expected = 'Subject: one\v two\f three\x1c four\x1d five\x1e six\n \n test body\n '
166+ s = self .ioclass ()
167+ g = self .genclass (s )
168+ g .flatten (msg )
169+ self .assertEqual (s .getvalue (), self .typ (expected ))
170+
171+ s = self .ioclass ()
172+ g = self .genclass (s , policy = self .policy .clone (refold_source = 'all' ))
173+ g .flatten (msg )
174+ self .assertEqual (s .getvalue (), self .typ (expected ))
175+
143176 def test_set_mangle_from_via_policy (self ):
144177 source = textwrap .dedent ("""\
145178 Subject: test that
@@ -224,6 +257,22 @@ class TestGenerator(TestGeneratorBase, TestEmailBase):
224257 ioclass = io .StringIO
225258 typ = str
226259
260+ def test_flatten_unicode_linesep (self ):
261+ source = 'Subject: one\x85 two\u2028 three\u2029 four\r \n \r \n test body\r \n '
262+ msg = self .msgmaker (self .typ (source ))
263+ self .assertEqual (msg ['Subject' ], 'one\x85 two\u2028 three\u2029 four' )
264+
265+ expected = 'Subject: =?utf-8?b?b25lwoUgdHdv4oCoIHRocmVl4oCp?= four\n \n test body\n '
266+ s = self .ioclass ()
267+ g = self .genclass (s )
268+ g .flatten (msg )
269+ self .assertEqual (s .getvalue (), self .typ (expected ))
270+
271+ s = self .ioclass ()
272+ g = self .genclass (s , policy = self .policy .clone (refold_source = 'all' ))
273+ g .flatten (msg )
274+ self .assertEqual (s .getvalue (), self .typ (expected ))
275+
227276
228277class TestBytesGenerator (TestGeneratorBase , TestEmailBase ):
229278
0 commit comments