summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-07-18 00:34:06 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-08-03 11:47:42 -0400
commit709f7d15b733e3ca579b8371e0ebe021dfcef139 (patch)
treedbc1a3d5d238cdfc858201ac1bb15b4cd564b6ab
parent50dd627b9658081b8f9ddf2466ebb4b174684a55 (diff)
downloadb4-709f7d15b733e3ca579b8371e0ebe021dfcef139.tar.gz
Parse just headers when extracting message ID from stdin mbox
When the mbox and am subcommands grab a message ID from the mbox on stdin, they call message_from_bytes(), which in turn calls BytesParser().parsebytes(s). parsebytes() has a headersonly parameter that can be used to tell it to stop parsing after reading the headers. The headers are all that's needed here, so use BytesParser directly and set headersonly. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Link: https://lore.kernel.org/tools/20210717164836-mutt-send-email-mst@kernel.org/ Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index bc05dcd..745485e 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2075,7 +2075,9 @@ def get_requests_session():
def get_msgid_from_stdin():
if not sys.stdin.isatty():
- message = email.message_from_bytes(sys.stdin.buffer.read())
+ from email.parser import BytesParser
+ message = BytesParser().parsebytes(
+ sys.stdin.buffer.read(), headersonly=True)
return message.get('Message-ID', None)
return None