From 3b168403ff5e50d767476c4c0f037d1841bb2bf9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Nov 2009 10:53:04 -0500 Subject: Broke `be comment --xml` out and extended into `be import-xml`. It should currently do everything that `be comment --xml` did, but it still has a way to go before it lives up to it's longhelp string, mostly figuring out bug/comment merging. The allowed XML format also changed a bit, becoming a bit more structured. cmdutil.bug_from_shortname() renamed to cmdutil.bug_from_id(). New functions cmdutil.parse_id() and cmdutil.bug_comment_from_id(). Additional doctests in libbe.comment.Comment.comment_shortnames() to show example output if bug_shortname==None. Brought be-xml-to-mbox and be-mbox-to-xml up to speed on the current -rooted format. * Added handling to their comment handling. * Moved extra strings from email bodies to X-Extra-String headers (some comment bodies are not text, and we should keep the estr location consistent between bugs and comments.) --- interfaces/xml/be-mbox-to-xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'interfaces/xml/be-mbox-to-xml') diff --git a/interfaces/xml/be-mbox-to-xml b/interfaces/xml/be-mbox-to-xml index a740117..3af2978 100755 --- a/interfaces/xml/be-mbox-to-xml +++ b/interfaces/xml/be-mbox-to-xml @@ -15,8 +15,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -Convert an mbox into xml suitable for imput into be. - $ cat mbox | be-mbox-to-xml | be comment --xml - +Convert an mbox into xml suitable for input into be. + $ be-mbox-to-xml file.mbox | be import-xml -c - mbox is a flat-file format, consisting of a series of messages. Messages begin with a a From_ line, followed by RFC 822 email, followed by a blank line. @@ -140,10 +140,10 @@ def comment_message_to_xml(message, fields=None): def main(mbox_filename): mb = mbox(mbox_filename) print u'' % DEFAULT_ENCODING - print u"" + print u"" for message in mb: print comment_message_to_xml(message) - print u"" + print u"" if __name__ == "__main__": -- cgit From 882492c80f47b6b5330b2510e9b8ef4164666303 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 5 Dec 2009 17:34:09 -0500 Subject: Adjusted be-mbox-to-xml to not drop author info from multipart messages --- interfaces/xml/be-mbox-to-xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'interfaces/xml/be-mbox-to-xml') diff --git a/interfaces/xml/be-mbox-to-xml b/interfaces/xml/be-mbox-to-xml index 3af2978..eda6d6e 100755 --- a/interfaces/xml/be-mbox-to-xml +++ b/interfaces/xml/be-mbox-to-xml @@ -40,7 +40,10 @@ def normalize_email_address(address): """ Standardize whitespace, etc. """ - return email.utils.formataddr(email.utils.parseaddr(address)) + addr = email.utils.formataddr(email.utils.parseaddr(address)) + if len(addr) == 0: + return None + return addr def normalize_RFC_2822_date(date): """ -- cgit From 072a46eefb66733ae570a9fb9abbc9570461a490 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 21:53:58 -0500 Subject: Emptied interfaces directory Mostly throwing out a bunch of outdated GUIs. The email interface hasn't been moved over to the new 'Command' format yet... --- interfaces/xml/be-mbox-to-xml | 154 ------------------------------------------ 1 file changed, 154 deletions(-) delete mode 100755 interfaces/xml/be-mbox-to-xml (limited to 'interfaces/xml/be-mbox-to-xml') diff --git a/interfaces/xml/be-mbox-to-xml b/interfaces/xml/be-mbox-to-xml deleted file mode 100755 index eda6d6e..0000000 --- a/interfaces/xml/be-mbox-to-xml +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2009 W. Trevor King -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -""" -Convert an mbox into xml suitable for input into be. - $ be-mbox-to-xml file.mbox | be import-xml -c - -mbox is a flat-file format, consisting of a series of messages. -Messages begin with a a From_ line, followed by RFC 822 email, -followed by a blank line. -""" - -import base64 -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 time import asctime, gmtime, mktime -import types -from xml.sax.saxutils import escape - -DEFAULT_ENCODING = get_encoding() -set_IO_stream_encodings(DEFAULT_ENCODING) - -KNOWN_IDS = [] - -def normalize_email_address(address): - """ - Standardize whitespace, etc. - """ - addr = email.utils.formataddr(email.utils.parseaddr(address)) - if len(addr) == 0: - return None - return addr - -def normalize_RFC_2822_date(date): - """ - Some email clients write non-RFC 2822-compliant date tags like: - Fri, 18 Sep 2009 08:49:02 -0400 (EDT) - with the non-standard (EDT) timezone name. This funtion attempts - to deal with such inconsistencies. - """ - time_tuple = email.utils.parsedate(date) - assert time_tuple != None, \ - 'unparsable date: "%s"' % date - return time_to_str(mktime(time_tuple)) - -def comment_message_to_xml(message, fields=None): - if fields == None: - fields = {} - 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'author'] = normalize_email_address(message[u'from']) - new_fields[u'date'] = message[u'date'] - if new_fields[u'date'] != None: - new_fields[u'date'] = normalize_RFC_2822_date(new_fields[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 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() - found_ref = False - for ref in refs: # search for a known reference id. - if ref in KNOWN_IDS: - fields[u'in-reply-to'] = ref - found_ref = True - break - if found_ref == False and len(refs) > 0: - fields[u'in-reply-to'] = refs[0] # default to the first - - if fields[u'alt-id'] != None: - KNOWN_IDS.append(fields[u'alt-id']) - - if message.is_multipart(): - ret = [] - alt_id = fields[u'alt-id'] - from_str = fields[u'author'] - date = fields[u'date'] - for m in message.walk(): - if m == message: - continue - fields[u'author'] = from_str - fields[u'date'] = date - 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) - - charset = message.get_content_charset(DEFAULT_ENCODING).lower() - #assert charset == DEFAULT_ENCODING.lower(), \ - # u"Unknown charset: %s" % charset - - 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/"): - body = unicode(body, encoding=charset).rstrip(u'\n') - else: - body = base64.encode(body) - fields[u'body'] = body - lines = [u""] - for tag,body in fields.items(): - if body != None: - ebody = escape(body) - lines.append(u" <%s>%s" % (tag, ebody, tag)) - lines.append(u"") - return u'\n'.join(lines) - -def main(mbox_filename): - mb = mbox(mbox_filename) - print u'' % DEFAULT_ENCODING - print u"" - for message in mb: - print comment_message_to_xml(message) - print u"" - - -if __name__ == "__main__": - import sys - main(sys.argv[1]) -- cgit