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