diff options
Diffstat (limited to 'misc/xml/be-xml-to-mbox')
-rwxr-xr-x | misc/xml/be-xml-to-mbox | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/misc/xml/be-xml-to-mbox b/misc/xml/be-xml-to-mbox index 34d0aa3..81741bf 100755 --- a/misc/xml/be-xml-to-mbox +++ b/misc/xml/be-xml-to-mbox @@ -25,10 +25,9 @@ followed by a blank line. """ #from mailbox import mbox, Message # the mailbox people really want an on-disk copy -import codecs import email.utils -from libbe.encoding import get_encoding, set_IO_stream_encodings -from libbe.utility import str_to_time as rfc2822_to_gmtime_integer +from libbe.util.encoding import get_output_encoding +from libbe.util.utility import str_to_time as rfc2822_to_gmtime_integer from time import asctime, gmtime import types try: # import core module, Python >= 2.5 @@ -40,8 +39,7 @@ from xml.sax.saxutils import unescape DEFAULT_DOMAIN = "invalid.com" DEFAULT_EMAIL = "dummy@" + DEFAULT_DOMAIN -DEFAULT_ENCODING = get_encoding() -set_IO_stream_encodings(DEFAULT_ENCODING) +DEFAULT_ENCODING = get_output_encoding() def rfc2822_to_asctime(rfc2822_string): """Convert an RFC 2822-fomatted string into a asctime string. @@ -124,6 +122,11 @@ class Bug (LimitedAttrDict): else: self[field.tag] = text +def wrap_id(id): + if "@" not in id: + return "<%s@%s>" % (id, DEFAULT_DOMAIN) + return id + class Comment (LimitedAttrDict): _attrs = [u"uuid", u"alt-id", @@ -144,7 +147,9 @@ class Comment (LimitedAttrDict): elif "alt-id" in self: id = self["alt-id"] else: id = None if id != None: - print "Message-id: <%s@%s>" % (id, DEFAULT_DOMAIN) + print "Message-id: %s" % wrap_id(id) + if "alt-id" in self: + print "Alt-id: %s" % wrap_id(self["alt-id"]) print "Date: %s" % self["date"] print "From: %s" % self["author"] subject = "" @@ -157,7 +162,7 @@ class Comment (LimitedAttrDict): print "Subject: %s" % subject if "in-reply-to" not in self.keys(): self["in-reply-to"] = bug["uuid"] - print "In-Reply-To: <%s@%s>" % (self["in-reply-to"], DEFAULT_DOMAIN) + print "In-Reply-To: %s" % wrap_id(self["in-reply-to"]) if "extra-strings" in self: for estr in self["extra_strings"]: print "X-Extra-String: %s" % estr @@ -197,7 +202,11 @@ def print_to_mbox(element): print_to_mbox(elt) if __name__ == "__main__": + import codecs import sys + + sys.stdin = codecs.getreader(DEFAULT_ENCODING)(sys.stdin) + sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout) if len(sys.argv) == 1: # no filename given, use stdin xml_unicode = sys.stdin.read() |