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):
if not charset:
try:
string = string.decode('utf-8')
return string.decode('utf-8')
except:
string = string.decode('iso8859-1')
string = unicode(string)
return string
return string.decode('iso8859-1')
return unicode(string)
def decode_mail_headers(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_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:
body_html = part.get_payload(decode=True)
else: