aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces/xml/be-mbox-to-xml
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-21 16:33:28 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-21 16:33:28 -0400
commit885b04b50ad3bbde81ec2eccfbfb2e516d0d3a80 (patch)
tree794458babd1aa824b3e343291f6c5f2d7704f27f /interfaces/xml/be-mbox-to-xml
parent19fc927cf959005a71813ca702fc6c1aa28d3a92 (diff)
parent86d74730ded314d960e0465f2eb50e5fb66c4767 (diff)
downloadbugseverywhere-885b04b50ad3bbde81ec2eccfbfb2e516d0d3a80.tar.gz
Merged assorted changes from be.wtk-rr for BugDir.extra_strings.
Other highlights: * be show --no-comments * Improved *.sync_with_disk. * Improved be-mbox-to-xml.
Diffstat (limited to 'interfaces/xml/be-mbox-to-xml')
-rwxr-xr-xinterfaces/xml/be-mbox-to-xml34
1 files changed, 30 insertions, 4 deletions
diff --git a/interfaces/xml/be-mbox-to-xml b/interfaces/xml/be-mbox-to-xml
index a5bf13e..57de719 100755
--- a/interfaces/xml/be-mbox-to-xml
+++ b/interfaces/xml/be-mbox-to-xml
@@ -32,6 +32,8 @@ import types
DEFAULT_ENCODING = get_encoding()
set_IO_stream_encodings(DEFAULT_ENCODING)
+KNOWN_IDS = []
+
def comment_message_to_xml(message, fields=None):
if fields == None:
fields = {}
@@ -51,6 +53,27 @@ def comment_message_to_xml(message, fields=None):
new_fields.k = fields[k]
fields = new_fields
+ if fields[u'in-reply-to'] == None:
+ if message[u'references'] != None:
+ refs = message[u'references'].split()
+ for ref in refs: # search for a known reference id.
+ if ref in KNOWN_IDS:
+ fields[u'in-reply-to'] = ref
+ break
+ if fields[u'in-reply-to'] == None and len(refs) > 0:
+ fields[u'in-reply-to'] = refs[0] # default to the first
+ else: # check for mutliple in-reply-to references.
+ refs = fields[u'in-reply-to'].split()
+ for ref in refs: # search for a known reference id.
+ if ref in KNOWN_IDS:
+ fields[u'in-reply-to'] = ref
+ break
+ if fields[u'in-reply-to'] == None and len(refs) > 0:
+ fields[u'in-reply-to'] = refs[0] # default to the first
+
+ if fields['alt-id'] != None:
+ KNOWN_IDS.append(fields['alt-id'])
+
if message.is_multipart():
ret = []
alt_id = fields[u'alt-id']
@@ -61,9 +84,9 @@ def comment_message_to_xml(message, fields=None):
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
+ if len(ret) > 0: # we've added one part already
+ fields.pop(u'alt-id') # don't pass alt-id to other parts
+ fields[u'in-reply-to'] = alt_id # others respond to first
ret.append(comment_message_to_xml(m, fields))
return u'\n'.join(ret)
@@ -71,7 +94,10 @@ def comment_message_to_xml(message, fields=None):
#assert charset == DEFAULT_ENCODING.lower(), \
# u"Unknown charset: %s" % charset
- encoding = message[u'content-transfer-encoding'].lower()
+ if message[u'content-transfer-encoding'] == None:
+ encoding = DEFAULT_ENCODING
+ else:
+ encoding = message[u'content-transfer-encoding'].lower()
body = message.get_payload(decode=True) # attempt to decode
assert body != None, "Unable to decode?"
if fields[u'content-type'].startswith(u"text/"):