"""
import base64
+import codecs
import email.utils
-from libbe.encoding import get_encoding, set_IO_stream_encodings
-from libbe.utility import time_to_str
-from mailbox import mbox, Message # the mailbox people really want an on-disk copy
+from libbe.util.encoding import get_output_encoding
+from libbe.util.utility import time_to_str
+import mailbox # the mailbox people really want an on-disk copy
+import optparse
+import sys
from time import asctime, gmtime, mktime
import types
from xml.sax.saxutils import escape
-DEFAULT_ENCODING = get_encoding()
-set_IO_stream_encodings(DEFAULT_ENCODING)
+DEFAULT_ENCODING = get_output_encoding()
+sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout)
KNOWN_IDS = []
lines.append(u"</comment>")
return u'\n'.join(lines)
-def main(mbox_filename):
- mb = mbox(mbox_filename)
+def main(argv):
+ parser = optparse.OptionParser(usage='%prog [options] mailbox')
+ formats = ['mbox', 'Maildir', 'MH', 'Babyl', 'MMDF']
+ parser.add_option('-f', '--format', type='choice', dest='format',
+ help="Select the mailbox format from %s. See the mailbox module's documention for descriptions of these formats." \
+ % ', '.join(formats),
+ default='mbox', choices=formats)
+ options,args = parser.parse_args(argv)
+ mailbox_file = args[1]
+ reader = getattr(mailbox, options.format)
+ mb = reader(mailbox_file, factory=None)
print u'<?xml version="1.0" encoding="%s" ?>' % DEFAULT_ENCODING
print u"<be-xml>"
for message in mb:
if __name__ == "__main__":
import sys
- main(sys.argv[1])
+ main(sys.argv)