From 709f7d15b733e3ca579b8371e0ebe021dfcef139 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 18 Jul 2021 00:34:06 -0400 Subject: 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 Link: https://lore.kernel.org/tools/20210717164836-mutt-send-email-mst@kernel.org/ Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3