diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-21 14:17:03 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-21 14:17:03 -0400 |
commit | b6f34db0ce3b5d93ecb740bae064342f7eb05587 (patch) | |
tree | 4aaaca3d5428c07d5415a45ebe3546dffcd2ef6c /interfaces/xml/be-mbox-to-xml | |
parent | eee872e51ef0b44a526dc981ef78e48a93ad8116 (diff) | |
download | bugseverywhere-b6f34db0ce3b5d93ecb740bae064342f7eb05587.tar.gz |
be-mbox-to-xml is now better at message-id, in-reply-to, and references.
A previous "len(ret) >= 0" had been stripping the alt-id and
in-reply-to from _all_ parts of multipart comments. Now it only
strips them from parts after the first. The following parts do not
specify and alt-id, and they all are in-reply-to the first part.
I also added the KNOWN_IDS list for selecting amongst an array of
possible in-reply-to or references ids. This works well enough for
now, but would be more robust if we could import a list of previously
known ids from BE...
Diffstat (limited to 'interfaces/xml/be-mbox-to-xml')
-rwxr-xr-x | interfaces/xml/be-mbox-to-xml | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/interfaces/xml/be-mbox-to-xml b/interfaces/xml/be-mbox-to-xml index 75cfd2b..335f92f 100755 --- a/interfaces/xml/be-mbox-to-xml +++ b/interfaces/xml/be-mbox-to-xml @@ -35,6 +35,8 @@ from xml.sax.saxutils import escape DEFAULT_ENCODING = get_encoding() set_IO_stream_encodings(DEFAULT_ENCODING) +KNOWN_IDS = [] + def comment_message_to_xml(message, fields=None): if fields == None: fields = {} @@ -54,6 +56,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'] @@ -64,9 +87,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) |