Fix some decoding error problems

This commit is contained in:
Benjamin Renard 2017-10-27 15:05:58 +02:00
parent d2fc01d46e
commit 60fc16756a

View file

@ -98,7 +98,7 @@ EX_OK=0
#############
def decode(text, prefer_encoding=None):
try_enc=['iso-8859-15', 'utf-8']
try_enc=['utf-8', 'iso-8859-15']
if prefer_encoding:
try_enc.insert(0,prefer_encoding)
for i in try_enc:
@ -316,8 +316,7 @@ for header in ('To', 'CC', 'BCC'):
logging.debug('Mail header %s : "%s"' % (header, mail_tos))
if isinstance(mail_tos, list):
for (to, encoding) in mail_tos:
if encoding is not None:
to=to.decode(encoding)
to=decode(to, encoding)
to=mail_address_to_phone_number(to)
if to and to not in sms_recipients:
sms_recipients.append(to)
@ -336,8 +335,7 @@ if isinstance(raw_mail_subject, str):
mail_subjects=email.header.decode_header(raw_mail_subject)
if isinstance(mail_subjects, list):
for (subject, encoding) in mail_subjects:
if encoding is not None:
subject=subject.decode(encoding)
subject=decode(subject, encoding)
mail_subject+=subject
logging.debug(u'Mail subject : "%s"' % mail_subject)
sms_content=mail_subject+u"\n"