diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-12-21 11:55:43 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-12-21 11:55:43 -0500 |
commit | 855249595ee15894d2c407457b77780611969f9d (patch) | |
tree | fbd76e56651580b04c7c33da3de6c70fed98fcc9 | |
parent | 07c988b2217ac42c7e29cfd321d68c45a4e4b3ef (diff) | |
download | b4-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.py | 48 |
1 files changed, 31 insertions, 17 deletions
@@ -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) |