All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	tools@linux.kernel.org, users@linux.kernel.org
Subject: [PATCH b4 2/2] Parse just headers when extracting message ID from stdin mbox
Date: Sun, 18 Jul 2021 00:34:06 -0400	[thread overview]
Message-ID: <20210718043406.26727-3-kyle@kyleam.com> (raw)
In-Reply-To: <20210718043406.26727-1-kyle@kyleam.com>

When the pr, 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>
---

  Note: I've tested only `b4 am/mbox' with the reproducer message
  mentioned in upthread; I haven't tested `b4 pr'.

 b4/__init__.py | 4 +++-
 b4/pr.py       | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/b4/__init__.py b/b4/__init__.py
index 5b32fb4..4722826 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1948,7 +1948,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
 
diff --git a/b4/pr.py b/b4/pr.py
index fbb2a71..e52c2ab 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -433,7 +433,10 @@ def main(cmdargs):
 
     if not sys.stdin.isatty():
         logger.debug('Getting PR message from stdin')
-        msg = email.message_from_bytes(sys.stdin.buffer.read())
+        from email.parser import BytesHeaderParser
+        from email.parser import BytesHeaderParser
+        msg = BytesParser().parsebytes(
+            sys.stdin.buffer.read(), headersonly=True)
         msgid = b4.LoreMessage.get_clean_msgid(msg)
         lmsg = parse_pr_data(msg)
     else:
-- 
2.32.0


  parent reply	other threads:[~2021-07-18  4:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-17 20:50 utf-8 issues on b4 master Michael S. Tsirkin
2021-07-17 21:21 ` Kyle Meyer
2021-07-18  1:39   ` Michael S. Tsirkin
2021-07-18  4:34     ` [PATCH b4 0/2] Avoid decoding errors when extracting message ID from stdin Kyle Meyer
2021-07-18  4:34       ` [PATCH b4 1/2] " Kyle Meyer
2021-07-18  4:34       ` Kyle Meyer [this message]
2021-07-18  4:45         ` [PATCH b4 2/2] Parse just headers when extracting message ID from stdin mbox Kyle Meyer
2021-08-03 16:03       ` [PATCH b4 0/2] Avoid decoding errors when extracting message ID from stdin Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210718043406.26727-3-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=mst@redhat.com \
    --cc=tools@linux.kernel.org \
    --cc=users@linux.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.