aboutsummaryrefslogtreecommitdiffstats
path: root/misc/xml
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-20 15:22:28 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-20 15:22:28 -0500
commitc8985785eb741ff646082879f1ca5e9cfe3873b0 (patch)
tree9e4b45e90217689746aad0e2e03aa98af5f38032 /misc/xml
parentfdc203bdae26aecb475a03c3da17cd44ee376a9c (diff)
downloadbugseverywhere-c8985785eb741ff646082879f1ca5e9cfe3873b0.tar.gz
'be-mbox-to-xml' -> 'be-mail-to-xml' + support for several formats.
Diffstat (limited to 'misc/xml')
-rwxr-xr-xmisc/xml/be-mail-to-xml (renamed from misc/xml/be-mbox-to-xml)28
1 files changed, 20 insertions, 8 deletions
diff --git a/misc/xml/be-mbox-to-xml b/misc/xml/be-mail-to-xml
index 1fc41e0..2add065 100755
--- a/misc/xml/be-mbox-to-xml
+++ b/misc/xml/be-mail-to-xml
@@ -23,16 +23,19 @@ followed by a blank line.
"""
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 = []
@@ -140,8 +143,17 @@ def comment_message_to_xml(message, fields=None):
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:
@@ -151,4 +163,4 @@ def main(mbox_filename):
if __name__ == "__main__":
import sys
- main(sys.argv[1])
+ main(sys.argv)