* Fixed issue #25 - unknown charsets on incoming email caused problems. This

fix causes multiple charsets to be used in decoding to avoid this problem. 
  Thank you to Paul Boehm for the patch.
This commit is contained in:
Ross Poulton 2008-11-18 00:24:37 +00:00
parent 77f3e71bd9
commit d5d692db45

View File

@ -106,14 +106,26 @@ def process_queue(q):
server.logout()
def decodeUnknown(charset, string):
if not charset:
try:
string = string.decode('utf-8')
except:
string = string.decode('iso8859-1')
string = unicode(string)
return string
def ticket_from_message(message, queue):
# 'message' must be an RFC822 formatted message.
msg = message
message = email.message_from_string(msg)
subject = message.get('subject', _('Created from e-mail'))
subject = decodeUnknown(message.get_charset(), subject)
subject = subject.replace("Re: ", "").replace("Fw: ", "").strip()
sender = message.get('from', _('Unknown Sender'))
sender = decodeUnknown(message.get_charset(), sender)
sender_email = parseaddr(sender)[1]
@ -138,7 +150,8 @@ def ticket_from_message(message, queue):
name = part.get_param("name")
if part.get_content_maintype() == 'text' and name == None:
body = part.get_payload()
body = part.get_payload(decode=True)
body = decodeUnknown(part.get_charset(), body)
else:
if not name:
ext = mimetypes.guess_extension(part.get_content_type())