diff options
author | Peter Palfrader <peter@palfrader.org> | 2010-09-17 12:43:08 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2010-09-17 12:43:08 +0000 |
commit | 1d715168d9e5ecded541bd7b030cf3ef2b0e91fe (patch) | |
tree | 9905ebe01e94664fe0c863badc73606a99e5de81 | |
parent | c40e34a9e351ba5bd855df2649f1d864bb2a48d6 (diff) |
add md2mb
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@455 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-x | md2mb | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -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 <maildir> [...]") +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: |