aboutsummaryrefslogtreecommitdiffstats
path: root/misc/xml/be-mail-to-xml
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-20 15:44:39 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-20 15:44:39 -0500
commit55f1e8588edc35410dd16b883e7cddd06ebc4ed6 (patch)
treeddfe7a95b1870036a4ab8cafe7ab43a624125fa5 /misc/xml/be-mail-to-xml
parentc8985785eb741ff646082879f1ca5e9cfe3873b0 (diff)
downloadbugseverywhere-55f1e8588edc35410dd16b883e7cddd06ebc4ed6.tar.gz
Strip footers (signatures) in be-mail-to-xml
Diffstat (limited to 'misc/xml/be-mail-to-xml')
-rwxr-xr-xmisc/xml/be-mail-to-xml11
1 files changed, 10 insertions, 1 deletions
diff --git a/misc/xml/be-mail-to-xml b/misc/xml/be-mail-to-xml
index 2add065..0b33465 100755
--- a/misc/xml/be-mail-to-xml
+++ b/misc/xml/be-mail-to-xml
@@ -34,6 +34,7 @@ from time import asctime, gmtime, mktime
import types
from xml.sax.saxutils import escape
+BREAK = u'--' # signature separator
DEFAULT_ENCODING = get_output_encoding()
sys.stdout = codecs.getwriter(DEFAULT_ENCODING)(sys.stdout)
@@ -60,6 +61,14 @@ def normalize_RFC_2822_date(date):
'unparsable date: "%s"' % date
return time_to_str(mktime(time_tuple))
+def strip_footer(body):
+ body_lines = body.splitlines()
+ for i,line in enumerate(body_lines):
+ if line.startswith(BREAK):
+ break
+ i += 1 # increment past the current valid line.
+ return u'\n'.join(body_lines[:i]).strip()
+
def comment_message_to_xml(message, fields=None):
if fields == None:
fields = {}
@@ -131,7 +140,7 @@ def comment_message_to_xml(message, fields=None):
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')
+ body = strip_footer(unicode(body, encoding=charset))
else:
body = base64.encode(body)
fields[u'body'] = body