aboutsummaryrefslogtreecommitdiffstats
path: root/xml/be-mbox-to-xml
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-12 13:56:05 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-12 13:56:05 -0400
commit37c4e7f0f0d012e8df88b94022bc9a9d75373831 (patch)
tree009ffafad4ade518ee0cf14ab67c2268ba37602e /xml/be-mbox-to-xml
parentd49efee62f70c9f49a5236719fd8c52dabd37dae (diff)
downloadbugseverywhere-37c4e7f0f0d012e8df88b94022bc9a9d75373831.tar.gz
be-mbox-to-xml passes attributes on to each part of multipart messages.
Previously "message[<some-attr>]" just returned None if it wasn't set for that message part, which overwrote anything passed in through fields. "from" and "date" added to list of attributes passed along. For be-xml-to-mbox, "alt-id" was added to Comment._attrs, and Comment.print_to_mbox was adjusted to handle the case where we have no information about the parent bug. With all of this, I can complete the loop be-mbox-to-xml example.mbox | be-xml-to-mbox > example2.mbox without errors :p. Finally, be-xml-to-mbox has been adjusted to also work on files (it had previously only handled data via stdin). We can't add stdin handling to be-mbox-to-xml though, because the mailbox package needs an actual file to work on, and I haven't setup a tmpfile workaround yet...
Diffstat (limited to 'xml/be-mbox-to-xml')
-rwxr-xr-xxml/be-mbox-to-xml30
1 files changed, 20 insertions, 10 deletions
diff --git a/xml/be-mbox-to-xml b/xml/be-mbox-to-xml
index e9077b1..9054cfd 100755
--- a/xml/be-mbox-to-xml
+++ b/xml/be-mbox-to-xml
@@ -22,13 +22,12 @@ Messages begin with a a From_ line, followed by RFC 822 email,
followed by a blank line.
"""
-from mailbox import mbox, Message # the mailbox people really want an on-disk copy
-import email.utils
-import types
-
import base64
+import email.utils
from libbe.encoding import get_encoding, set_IO_stream_encodings
+from mailbox import mbox, Message # the mailbox people really want an on-disk copy
from time import asctime, gmtime
+import types
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from xml.sax.saxutils import escape
@@ -39,21 +38,32 @@ set_IO_stream_encodings(DEFAULT_ENCODING)
def comment_message_to_xml(message, fields=None):
if fields == None:
fields = {}
- fields[u'alt-id'] = message[u'message-id']
- fields[u'in-reply-to'] = message[u'in-reply-to']
- fields[u'from'] = message[u'from']
- fields[u'date'] = message[u'date']
- fields[u'content-type'] = message.get_content_type()
- for k,v in fields.items():
+ new_fields = {}
+ new_fields[u'alt-id'] = message[u'message-id']
+ new_fields[u'in-reply-to'] = message[u'in-reply-to']
+ new_fields[u'from'] = message[u'from']
+ new_fields[u'date'] = message[u'date']
+ new_fields[u'content-type'] = message.get_content_type()
+ for k,v in new_fields.items():
if v != None and type(v) != types.UnicodeType:
fields[k] = unicode(v, encoding=DEFAULT_ENCODING)
+ elif v == None and k in fields:
+ new_fields[k] = fields[k]
+ for k,v in fields.items():
+ if k not in new_fields:
+ new_fields.k = fields[k]
+ fields = new_fields
if message.is_multipart():
ret = []
alt_id = fields[u'alt-id']
+ from_str = fields[u'from']
+ date = fields[u'date']
for m in message.walk():
if m == message:
continue
+ fields[u'from'] = from_str
+ fields[u'date'] = date
if len(ret) >= 0:
fields.pop(u'alt-id')
fields[u'in-reply-to'] = alt_id