* [PATCH] mbox: Add the --pipe-each-message argument
@ 2022-11-15 3:24 Palmer Dabbelt
2022-11-15 14:48 ` Konstantin Ryabitsev
0 siblings, 1 reply; 2+ messages in thread
From: Palmer Dabbelt @ 2022-11-15 3:24 UTC (permalink / raw)
To: tools; +Cc: Palmer Dabbelt
I've got an oddball mailbox format, so rather than trying to directly
encode it into b4 this just lets b4 pipe each message into a command
that sorts things out.
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
This seems excessively ugly, I couldn't quite figure out why just
` save_git_am_mbox(list(msg))` wasn't doing it so I gave up. Happy to
go do it right, but this works for me.
Also: this is on top of the patch stack I sent up earlier, sorry if
there's some conflicts. I haven't jumped to a newer master yet...
---
b4/command.py | 2 ++
b4/mbox.py | 13 +++++++++++++
man/b4.5.rst | 2 ++
3 files changed, 17 insertions(+)
diff --git a/b4/command.py b/b4/command.py
index b68cf72..c32be13 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -36,6 +36,8 @@ def cmd_mbox_common_opts(sp):
help='Filename to name the mbox destination')
sp.add_argument('-M', '--save-as-maildir', dest='maildir', action='store_true', default=False,
help='Save as maildir (avoids mbox format ambiguities)')
+ sp.add_argument('--pipe-each-message', dest='pipe_each_message', default=None,
+ help='Pipe each message to an instance of the given command')
def cmd_am_common_opts(sp):
diff --git a/b4/mbox.py b/b4/mbox.py
index 5842bf9..88a7667 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -20,6 +20,7 @@ import pathlib
import tempfile
import io
import shlex
+import subprocess
import argparse
import urllib.parse
@@ -819,6 +820,18 @@ def main(cmdargs):
logger.info('Saved maildir %s', savename)
return
+ if cmdargs.pipe_each_message:
+ for msg in msgs:
+ proc = subprocess.Popen(cmdargs.pipe_each_message,
+ stdin=subprocess.PIPE,
+ encoding='utf8')
+ gen = email.generator.Generator(proc.stdin)
+ gen.flatten(msg)
+ gen.write("\n")
+ proc.stdin.close()
+ proc.wait()
+ return
+
with open(savename, 'w') as fh:
b4.save_git_am_mbox(msgs, fh)
diff --git a/man/b4.5.rst b/man/b4.5.rst
index dfe52e4..5126abf 100644
--- a/man/b4.5.rst
+++ b/man/b4.5.rst
@@ -89,6 +89,8 @@ options:
Save as maildir (avoids mbox format ambiguities)
-f, --filter-dupes
When adding messages to existing maildir, filter out duplicates
+ --pipe-each-message
+ Pipe each message to an instance of the given command
*Example*: b4 mbox 20200313231252.64999-1-keescook@chromium.org
--
2.38.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mbox: Add the --pipe-each-message argument
2022-11-15 3:24 [PATCH] mbox: Add the --pipe-each-message argument Palmer Dabbelt
@ 2022-11-15 14:48 ` Konstantin Ryabitsev
0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Ryabitsev @ 2022-11-15 14:48 UTC (permalink / raw)
To: Palmer Dabbelt; +Cc: tools
On Mon, Nov 14, 2022 at 07:24:39PM -0800, Palmer Dabbelt wrote:
> I've got an oddball mailbox format, so rather than trying to directly
> encode it into b4 this just lets b4 pipe each message into a command
> that sorts things out.
I'm not sure I want to go that route -- formail already exists and does it
better, e.g.:
b4 -q mbox -o- 20221115144005.2478-1-johan+linaro@kernel.org | formail -ds grep '^Subject'
Would that be a suitable approach?
-K
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-15 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 3:24 [PATCH] mbox: Add the --pipe-each-message argument Palmer Dabbelt
2022-11-15 14:48 ` Konstantin Ryabitsev
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).