1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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:
|