+ # get the subject
+ subject = descr_lines[pos]
+ lasthdr = pos + 1
+
+ # get the body
+ if lasthdr < end:
+ body = reduce(lambda x, y: x + '\n' + y, descr_lines[lasthdr:], '')
+
+ return (subject + body, authname, authemail, authdate)
+
+def __parse_mail(msg):
+ """Parse the message object and return (description, authname,
+ authemail, authdate, diff)
+ """
+ def __decode_header(header):
+ """Decode a qp-encoded e-mail header as per rfc2047"""
+ try:
+ words_enc = decode_header(header)
+ hobj = make_header(words_enc)
+ except Exception, ex:
+ raise CmdException, 'header decoding error: %s' % str(ex)
+ return unicode(hobj).encode('utf-8')
+
+ # parse the headers
+ if msg.has_key('from'):
+ authname, authemail = name_email(__decode_header(msg['from']))
+ else:
+ authname = authemail = None
+
+ # '\n\t' can be found on multi-line headers
+ descr = __decode_header(msg['subject']).replace('\n\t', ' ')
+ authdate = msg['date']