aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-21 11:55:43 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-12-21 11:58:38 -0500
commit10af809c0c75f6b229f72356eca07d19a4f24480 (patch)
treed14a0ff4a3f37c2c1a579c10c899d86753199bcb
parent6edf1732c1d68dcb88ab816c43a338a6ffd7e0f7 (diff)
downloadb4-10af809c0c75f6b229f72356eca07d19a4f24480.tar.gz
Check if -o is a maildir
When -o is a valid maildir, then instead of saving an .mbox file add messages to the maildir instead. This should allow "b4 mbox" to quickly add threads to existing mail spools. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/mbox.py48
1 files changed, 31 insertions, 17 deletions
diff --git a/b4/mbox.py b/b4/mbox.py
index 200cf1c..eeca363 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -537,23 +537,37 @@ def main(cmdargs):
if cmdargs.subcmd == 'am':
mbox_to_am(threadfile, cmdargs)
os.unlink(threadfile)
- else:
- mbx = mailbox.mbox(threadfile)
- logger.critical('%s messages in the thread', len(mbx))
- mbx.close()
- if cmdargs.outdir == '-':
- logger.info('---')
- with open(threadfile, 'rb') as fh:
- shutil.copyfileobj(fh, sys.stdout.buffer)
- os.unlink(threadfile)
- return
+ return
- if cmdargs.wantname:
- savefile = os.path.join(cmdargs.outdir, cmdargs.wantname)
- else:
- msgid = b4.get_msgid(cmdargs)
- savefile = os.path.join(cmdargs.outdir, '%s.mbx' % msgid)
+ mbx = mailbox.mbox(threadfile)
+ logger.info('%s messages in the thread', len(mbx))
+ if cmdargs.outdir == '-':
+ mbx.close()
+ logger.info('---')
+ with open(threadfile, 'rb') as fh:
+ shutil.copyfileobj(fh, sys.stdout.buffer)
+ os.unlink(threadfile)
+ return
- shutil.copy(threadfile, savefile)
- logger.info('Saved %s', savefile)
+ # Check if outdir is a maildir
+ if (os.path.isdir(os.path.join(cmdargs.outdir, 'new'))
+ and os.path.isdir(os.path.join(cmdargs.outdir, 'cur'))
+ and os.path.isdir(os.path.join(cmdargs.outdir, 'tmp'))):
+ mdr = mailbox.Maildir(cmdargs.outdir)
+ for msg in mbx:
+ mdr.add(msg)
+ logger.info('Added to maildir %s', cmdargs.outdir)
+ mbx.close()
os.unlink(threadfile)
+ return
+
+ if cmdargs.wantname:
+ savefile = os.path.join(cmdargs.outdir, cmdargs.wantname)
+ else:
+ msgid = b4.get_msgid(cmdargs)
+ savefile = os.path.join(cmdargs.outdir, '%s.mbx' % msgid)
+
+ mbx.close()
+ shutil.copy(threadfile, savefile)
+ logger.info('Saved %s', savefile)
+ os.unlink(threadfile)