Fix decoding of plain text emails in non-utf8 encodings such as koi8-r. Thanks to Sergey Kirillov for the patch, which fixes Github issue #9 and Google Code issue #150.

This commit is contained in:
Ross Poulton 2011-01-29 06:22:18 +00:00
parent b68bd73d07
commit 8f15febe23

View File

@ -130,11 +130,10 @@ def process_queue(q, quiet=False):
def decodeUnknown(charset, string): def decodeUnknown(charset, string):
if not charset: if not charset:
try: try:
string = string.decode('utf-8') return string.decode('utf-8')
except: except:
string = string.decode('iso8859-1') return string.decode('iso8859-1')
string = unicode(string) return unicode(string)
return string
def decode_mail_headers(string): def decode_mail_headers(string):
decoded = decode_header(string) decoded = decode_header(string)
@ -181,7 +180,7 @@ def ticket_from_message(message, queue, quiet):
if part.get_content_maintype() == 'text' and name == None: if part.get_content_maintype() == 'text' and name == None:
if part.get_content_subtype() == 'plain': if part.get_content_subtype() == 'plain':
body_plain = decodeUnknown(part.get_charset(), part.get_payload(decode=True)) body_plain = decodeUnknown(part.get_content_charset(), part.get_payload(decode=True))
else: else:
body_html = part.get_payload(decode=True) body_html = part.get_payload(decode=True)
else: else: