From 1d715168d9e5ecded541bd7b030cf3ef2b0e91fe Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 17 Sep 2010 12:43:08 +0000 Subject: add md2mb git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@455 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- md2mb | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 md2mb diff --git a/md2mb b/md2mb new file mode 100755 index 0000000..4120df4 --- /dev/null +++ b/md2mb @@ -0,0 +1,61 @@ +#!/usr/bin/python2.5 + +# converts a mailbox in Maildir format to one in mbox +# well, copies actually + +# Copyright (c) 2010 Peter Palfrader + +import mailbox +import optparse +import os +import sys + +parser = optparse.OptionParser() +parser.set_usage("%prog [...]") +parser.add_option("-s", "--skip-leading-dot", dest="dodot", action="store_true", + help="remove leading dot from mbox filenames.") +parser.add_option("-v", "--verbose", dest="verbose", action="store_true", + help="be verbose.") +parser.add_option("-d", "--dir", dest="dir", metavar="dstdir", default='.', + help="directory to create mbox file in.") + +(options, args) = parser.parse_args() +if len(args) == 0: + parser.print_help() + sys.exit(1) + +for f in args: + f = f.rstrip('/') + if options.dodot: + m = f.lstrip('.') + else: + m = f + dp = os.path.join(options.dir, "%s.mbox"%(m)) + + if not os.path.isdir(f): + print >> sys.stderr, "%s does not exist or is not a directory, skipping."%(f) + continue + + if os.path.exists(dp): + print >> sys.stderr, "%s already exists, skipping."%(dp) + continue + + if options.verbose: + print "Copying %s to %s"%(f, dp), + + src = mailbox.Maildir(f, factory=None) + dst = mailbox.mbox(dp) + keys = src.keys() + keys.sort() + for k in keys: + m = src[k] + dst.add(m) + if options.verbose: + sys.stdout.write(".") + sys.stdout.flush() + if options.verbose: + print + +# vim:set et: +# vim:set ts=4: +# vim:set shiftwidth=4: -- cgit v1.2.3