def _makeMessageInfo(self, message): """Given an email.Message, return an object with subjectHeader, bodySummary and other header (as needed) attributes. These objects are passed into appendMessages by onReview - passing email.Message objects directly uses too much memory.""" subjectHeader = message["Subject"] or "(none)" headers = {"subject" : subjectHeader} for header in options["html_ui", "display_headers"]: headers[header.lower()] = (message[header] or "(none)") score = message[options["Headers", "score_header_name"]] if score: # the score might have the log info at the end op = score.find('(') if op >= 0: score = score[:op] try: score = "%.2f%%" % (float(score)*100,) except ValueError: # Hmm. The score header should only contain a floating # point number. What's going on here, then? score = "Err" # Let the user know something is wrong. else: # If the lookup fails, this means that the "include_score" # option isn't activated. We have the choice here to either # calculate it now, which is pretty inefficient, since we have # already done so, or to admit that we don't know what it is. # We'll go with the latter. score = "?" try: part = typed_subpart_iterator(message, 'text', 'plain').next() text = part.get_payload() except StopIteration: try: part = typed_subpart_iterator(message, 'text', 'html').next() text = part.get_payload() text, unused = tokenizer.crack_html_style(text) text, unused = tokenizer.crack_html_comment(text) text = tokenizer.html_re.sub(' ', text) text = '(this message only has an HTML body)\n' + text except StopIteration: text = '(this message has no text body)' if type(text) == type([]): # gotta be a 'right' way to do this text = "(this message is a digest of %s messages)" % (len(text)) elif text is None: text = "(this message has no body)" else: text = text.replace(' ', ' ') # Else they'll be quoted text = re.sub(r'(\s)\s+', r'\1', text) # Eg. multiple blank lines text = text.strip() class _MessageInfo: pass messageInfo = _MessageInfo() for headerName, headerValue in headers.items(): headerValue = self._trimHeader(headerValue, 45, True) setattr(messageInfo, "%sHeader" % (headerName,), headerValue) messageInfo.score = score messageInfo.bodySummary = self._trimHeader(text, 200) return messageInfo
def _makeMessageInfo(self, message): """Given an email.Message, return an object with subjectHeader, bodySummary and other header (as needed) attributes. These objects are passed into appendMessages by onReview - passing email.Message objects directly uses too much memory. """ message.delNotations() subjectHeader = message["Subject"] or "(none)" headers = {"subject" : subjectHeader} for header in options["html_ui", "display_headers"]: headers[header.lower()] = (message[header] or "(none)") score = message[options["Headers", "score_header_name"]] if score: op = score.find('(') if op >= 0: score = score[:op] try: score = float(score) * 100 except ValueError: score = "Err" # Let the user know something is wrong. else: score = "?" try: part = typed_subpart_iterator(message, 'text', 'plain').next() text = part.get_payload() except StopIteration: try: part = typed_subpart_iterator(message, 'text', 'html').next() text = part.get_payload() text, unused = tokenizer.crack_html_style(text) text, unused = tokenizer.crack_html_comment(text) text = tokenizer.html_re.sub(' ', text) text = _('(this message only has an HTML body)\n') + text except StopIteration: text = _('(this message has no text body)') if type(text) == type([]): # gotta be a 'right' way to do this text = _("(this message is a digest of %s messages)") % (len(text)) elif text is None: text = _("(this message has no body)") else: text = text.replace(' ', ' ') # Else they'll be quoted text = re.sub(r'(\s)\s+', r'\1', text) # Eg. multiple blank lines text = text.strip() class _MessageInfo: pass messageInfo = _MessageInfo() for headerName, headerValue in headers.items(): headerValue = self._trimHeader(headerValue, 45, True) setattr(messageInfo, "%sHeader" % (headerName,), headerValue) messageInfo.score = score messageInfo.bodySummary = self._trimHeader(text, 200) return messageInfo