Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcaf2ec

Browse files
committed
#12586: Fix a small oversight in the new email policy header setting code.
This is a danger of focusing on unit tests: sometimes you forget to do the integration tests.
1 parent b526763 commit dcaf2ec

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/email/policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def header_store_parse(self, name, value):
104104
"""
105105
if hasattr(value, 'name') and value.name.lower() == name.lower():
106106
return (name, value)
107-
if len(value.splitlines())>1:
107+
if isinstance(value, str) and len(value.splitlines())>1:
108108
raise ValueError("Header values may not contain linefeed "
109109
"or carriage return characters")
110110
return (name, self.header_factory(name, value))

Lib/test/test_email/test__headerregistry.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
from email import errors
55
from email import policy
6+
from email.message import Message
67
from test.test_email import TestEmailBase
78
from email import _headerregistry
89
# Address and Group are public but I'm not sure where to put them yet.
@@ -168,6 +169,12 @@ def test_datetime_read_only(self):
168169
with self.assertRaises(AttributeError):
169170
h.datetime = 'foo'
170171

172+
def test_set_date_header_from_datetime(self):
173+
m = Message(policy=policy.default)
174+
m['Date'] = self.dt
175+
self.assertEqual(m['Date'], self.datestring)
176+
self.assertEqual(m['Date'].datetime, self.dt)
177+
171178

172179
class TestAddressHeader(TestHeaderBase):
173180

@@ -625,6 +632,20 @@ def test_display_name_blanks_not_quoted(self):
625632
self.assertEqual(g.addresses, tuple())
626633
self.assertEqual(str(g), 'foo bar:;')
627634

635+
def test_set_message_header_from_address(self):
636+
a = Address('foo', 'bar', 'example.com')
637+
m = Message(policy=policy.default)
638+
m['To'] = a
639+
self.assertEqual(m['to'], 'foo <[email protected]>')
640+
self.assertEqual(m['to'].addresses, (a,))
641+
642+
def test_set_message_header_from_group(self):
643+
g = Group('foo bar')
644+
m = Message(policy=policy.default)
645+
m['To'] = g
646+
self.assertEqual(m['to'], 'foo bar:;')
647+
self.assertEqual(m['to'].addresses, g.addresses)
648+
628649

629650
class TestFolding(TestHeaderBase):
630651

@@ -713,5 +734,6 @@ def test_fold_date_header(self):
713734
'Date: Sat, 02 Feb 2002 17:00:06 -0800\n')
714735

715736

737+
716738
if __name__ == '__main__':
717739
unittest.main()

0 commit comments

Comments
 (0)