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:55:43 -0500
commit855249595ee15894d2c407457b77780611969f9d (patch)
treefbd76e56651580b04c7c33da3de6c70fed98fcc9
parent07c988b2217ac42c7e29cfd321d68c45a4e4b3ef (diff)
downloadb4-855249595ee15894d2c407457b77780611969f9d.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 459fb9a..226303e 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -532,23 +532,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)