aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-03-19 11:47:04 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-03-19 11:47:04 -0400
commit2e024fa130e5491e6db5ee3759d12e1786430928 (patch)
tree792d2249662bb73f33f6637330775fd9017890f8
parentcf5f35d6760b7b1d7187edadbfabcb02882fc676 (diff)
downloadb4-2e024fa130e5491e6db5ee3759d12e1786430928.tar.gz
send-receive: use our own emlpolicy when parsing messages
Avoid triggering more python email bugs by not using the SMTP policy when parsing messages. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--misc/send-receive.py2
-rw-r--r--src/tests/test___init__.py13
2 files changed, 13 insertions, 2 deletions
diff --git a/misc/send-receive.py b/misc/send-receive.py
index cbd8aa8..edbbb07 100644
--- a/misc/send-receive.py
+++ b/misc/send-receive.py
@@ -431,7 +431,7 @@ class SendReceiveListener(object):
self.send_error(resp, message='We only support a single signing identity across patch series.')
return
- msg = email.message_from_bytes(bdata, policy=email.policy.SMTP)
+ msg = email.message_from_bytes(bdata, policy=emlpolicy)
logger.debug('Checking sanity on message: %s', msg.get('Subject'))
# Some quick sanity checking:
# - Subject has to start with [PATCH
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index bf5e9b5..a43d308 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -169,9 +169,20 @@ def test_followup_trailers(sampledir, source, serargs, amargs, reference, b4cfg)
('foo@example.com, Foo Bar <bar@example.com>, =?utf-8?q?Qu=C3=BBx=2C_Foo?= <quux@example.com>',
'foo@example.com, Foo Bar <bar@example.com>, \n "Quûx, Foo" <quux@example.com>',
'decode'),
+ # Test short message-id
+ ('Message-ID: <20240319-short-message-id@example.com>', '<20240319-short-message-id@example.com>', 'encode'),
+ # Test long message-id
+ ('Message-ID: <20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', # noqa
+ '<20240319-very-long-message-id-that-spans-multiple-lines-for-sure-because-longer-than-75-characters-abcde123456@longdomain.example.com>', # noqa
+ 'encode'),
])
def test_header_wrapping(sampledir, hval, verify, tr):
- hname = 'To' if '@' in hval else "X-Header"
+ if ':' in hval:
+ chunks = hval.split(':', maxsplit=1)
+ hname = chunks[0].strip()
+ hval = chunks[1].strip()
+ else:
+ hname = 'To' if '@' in hval else "X-Header"
wrapped = b4.LoreMessage.wrap_header((hname, hval), transform=tr)
assert wrapped.decode() == f'{hname}: {verify}'
wname, wval = wrapped.split(b':', maxsplit=1)