mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 02:10:49 +01:00
* 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:
parent
77f3e71bd9
commit
d5d692db45
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user