summaryrefslogtreecommitdiff
path: root/md2mb
diff options
context:
space:
mode:
Diffstat (limited to 'md2mb')
-rwxr-xr-xmd2mb61
1 files changed, 61 insertions, 0 deletions
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 <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: