--- spambayes-1.0.4/spambayes/ProxyUI.py.orig 2005-01-28 10:23:02.000000000 +0900 +++ spambayes-1.0.4/spambayes/ProxyUI.py 2006-10-31 20:24:01.000000000 +0900 @@ -69,6 +69,9 @@ from spambayes.Options import options from email.Iterators import typed_subpart_iterator +# 2005-08-30: updated to support iso-2022-jp, by owa. +from email.Header import decode_header + global state # These are the options that will be offered on the configuration page. @@ -319,15 +322,18 @@ for header in options["html_ui", "display_headers"]: header = header.lower() text = getattr(messageInfo, "%sHeader" % (header,)) + # 2005-08-30: updated to support iso-2022-jp, by owa. if header == "subject": # Subject is special, because it links to the body. # If the user doesn't display the subject, then there # is no link to the body. h = self.html.reviewRow.linkedHeaderValue.clone() - h.text.title = messageInfo.bodySummary + text = unicode(text, errors='ignore') + h.text.title = unicode(messageInfo.bodySummary, errors='ignore') h.text.href = "view?key=%s&corpus=%s" % (key, label) else: h = self.html.reviewRow.headerValue.clone() + #text = unicode(text, 'iso-2022-jp', 'ignore') h.text = text row.optionalHeadersValues += h @@ -627,7 +633,17 @@ if sourceCorpus is not None: message = sourceCorpus.get(key) if message is not None: - self.write("
%s
" % cgi.escape(message.as_string())) + # 2005-08-30: updated to support iso-2022-jp, by owa. + # help me! i don't know what to do in this place or other's + content_type_charset = None + for x in message.get_charsets(None): + if x and x.lower() == 'iso-2022-jp': + content_type_charset = x.lower() + if content_type_charset: + text = unicode(message.as_string(), content_type_charset, 'replace') + self.write("
%s
" % cgi.escape(text)) + else: + self.write("
%s
" % cgi.escape(message.as_string())) else: self.write("

Can't find message %r. Maybe it expired.

" % key) self._writePostamble() @@ -660,10 +676,19 @@ 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} + # 2005-08-30: updated to support iso-2022-jp, by owa. + headers = {} for header in options["html_ui", "display_headers"]: headers[header.lower()] = (message[header] or "(none)") + subjectHeader = message["Subject"] or "(none)" + us = '' + for hs, hc in decode_header(subjectHeader): + if hc: + us += unicode(hs, hc, 'ignore') + else: + us += hs + headers['subject'] = us + score = message[options["Headers", "score_header_name"]] if score: # the score might have the log info at the end @@ -683,10 +708,21 @@ # already done so, or to admit that we don't know what it is. # We'll go with the latter. score = "?" + # 2005-08-30: updated to support iso-2022-jp, by owa. + content_type_charset = None try: part = typed_subpart_iterator(message, 'text', 'plain').next() text = part.get_payload() + # help me! i don't know what to do in this place or other's + for x in message.get_charsets(None): + if x and x.lower() == 'iso-2022-jp': + content_type_charset = x.lower() + if content_type_charset: + text = unicode(text, content_type_charset, errors='ignore') + text = text[:200] + text = text.encode('utf-8') except StopIteration: + content_type_charset = None try: part = typed_subpart_iterator(message, 'text', 'html').next() text = part.get_payload() @@ -712,7 +748,11 @@ headerValue = self._trimHeader(headerValue, 45, True) setattr(messageInfo, "%sHeader" % (headerName,), headerValue) messageInfo.score = score - messageInfo.bodySummary = self._trimHeader(text, 200) + # 2005-08-30: updated to support iso-2022-jp, by owa. + if content_type_charset: + messageInfo.bodySummary = text + else: + messageInfo.bodySummary = self._trimHeader(text, 200) return messageInfo def reReadOptions(self):