Commit 4dc78702 authored by Romain Courteaud's avatar Romain Courteaud

Handle inconsistent encoding in mail message (in case declared charset is

different from the one used).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22238 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d9bc7203
......@@ -1274,7 +1274,11 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna
charset_list = self.charset_parser.findall(str(html)) # XXX - Not efficient is datastream
# instance but hard to do better
if charset_list and charset_list[0] not in ('utf-8', 'UTF-8'):
stripped_html = unicode(str(stripped_html), charset_list[0]).encode('utf-8')
try:
stripped_html = unicode(str(stripped_html),
charset_list[0]).encode('utf-8')
except UnicodeDecodeError:
return str(stripped_html)
return stripped_html
security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation')
......
......@@ -277,7 +277,10 @@ class EmailDocument(File, TextDocument):
elif part.get_content_type() == 'text/html' and not html_result and not part.is_multipart():
part_encoding = part.get_content_charset()
if part_encoding not in (None, 'utf-8',):
try:
return part.get_payload(decode=1).decode(part_encoding).encode('utf-8')
except UnicodeDecodeError:
return part.get_payload(decode=1)
return part.get_payload(decode=1)
return text_result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment