'be-mbox-to-xml' -> 'be-mail-to-xml' + support for several formats.
authorW. Trevor King <wking@drexel.edu>
Wed, 20 Jan 2010 20:22:28 +0000 (15:22 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 20 Jan 2010 20:22:28 +0000 (15:22 -0500)
NEWS
misc/xml/be-mail-to-xml [moved from misc/xml/be-mbox-to-xml with 85% similarity]

diff --git a/NEWS b/NEWS
index 99d5bca27cd80e9246c99c42a0a30221abd5af00..17d5aee88d4188132d53b1697f3b3da009e9204b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+January 20, 2010
+ * Renamed 'be-mbox-to-xml' -> 'be-mail-to-xml' and added support for
+   several mailbox formats.
+
 January 3, 2010
  * Changed `be list --uuids` -> `be list --ids`
    Instead of UUIDs, it now outputs user ids: BUGDIR/BUG
similarity index 85%
rename from misc/xml/be-mbox-to-xml
rename to misc/xml/be-mail-to-xml
index 1fc41e0fcb6eb0a3e4e9bfad7960ac2236fdfa65..2add0652ac49c098ba0618653b025713d99a86c8 100755 (executable)
@@ -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)