@@ -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):
@@ -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)
@@ -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
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(+)