archive mirror
 help / color / mirror / Atom feed
From: Morten Linderud <>
Cc: Morten Linderud <>
Subject: b4: Ensure we read threadfile for message-id
Date: Wed, 21 Apr 2021 22:29:42 +0200	[thread overview]
Message-ID: <> (raw)

This fixes a bug where reading from `get_msgid_from_stdin` couldn't grab
the message-id when we collect a thread from stdin.

This is mainly because there is no good way to override `sys.stdin`
(from what I can see) and it probably makes more sense to try fetch
message-ids from files instead. This allows us to replace the default
file "sys.stdin" with the thread file whenever we need.

No patch:

    $ curl -s "" | b4 mbox
    Looking up
    Grabbing thread from
    272 messages in the thread
    Unable to find a valid message-id in stdin.

With patch:

    $ curl -s "" | .4 mbox
    Looking up
    Grabbing thread from
    272 messages in the thread
    Saved ./

Signed-off-by: Morten Linderud <>
 b4/ | 8 ++++----
 b4/     | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/b4/ b/b4/
index 32b5c02..e81d395 100644
--- a/b4/
+++ b/b4/
@@ -2179,18 +2179,18 @@ def get_requests_session():
     return REQSESSION
-def get_msgid_from_stdin():
+def get_msgid_from_file(file):
     if not sys.stdin.isatty():
-        message = email.message_from_string(
+        message = email.message_from_string(
         return message.get('Message-ID', None)
     logger.error('Error: pipe a message or pass msgid as parameter')
-def get_msgid(cmdargs):
+def get_msgid(cmdargs, file=sys.stdin):
     if not cmdargs.msgid:
         logger.debug('Getting Message-ID from stdin')
-        msgid = get_msgid_from_stdin()
+        msgid = get_msgid_from_file(file)
         if msgid is None:
             logger.error('Unable to find a valid message-id in stdin.')
diff --git a/b4/ b/b4/
index d3bde25..791f545 100644
--- a/b4/
+++ b/b4/
@@ -566,7 +566,7 @@ def main(cmdargs):
     if cmdargs.wantname:
         savefile = os.path.join(cmdargs.outdir, cmdargs.wantname)
-        msgid = b4.get_msgid(cmdargs)
+        msgid = b4.get_msgid(cmdargs, file=open(threadfile))
         savefile = os.path.join(cmdargs.outdir, '%s.mbx' % msgid)

             reply	other threads:[~2021-04-21 20:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 20:29 Morten Linderud [this message]
2021-04-21 23:33 ` b4: Ensure we read threadfile for message-id Kyle Meyer
2021-05-14 20:55   ` 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:

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

  git send-email \ \ \ \

* 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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).