[Erp5-report] r22238 - in /erp5/trunk/products/ERP5/Document: Document.py EmailDocument.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Jul 3 11:55:24 CEST 2008


Author: romain
Date: Thu Jul  3 11:55:20 2008
New Revision: 22238

URL: http://svn.erp5.org?rev=22238&view=rev
Log:
Handle inconsistent encoding in mail message (in case declared charset is
different from the one used).

Modified:
    erp5/trunk/products/ERP5/Document/Document.py
    erp5/trunk/products/ERP5/Document/EmailDocument.py

Modified: erp5/trunk/products/ERP5/Document/Document.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Document.py?rev=22238&r1=22237&r2=22238&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Document.py (original)
+++ erp5/trunk/products/ERP5/Document/Document.py Thu Jul  3 11:55:20 2008
@@ -1274,7 +1274,11 @@
     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')

Modified: erp5/trunk/products/ERP5/Document/EmailDocument.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/EmailDocument.py?rev=22238&r1=22237&r2=22238&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/EmailDocument.py (original)
+++ erp5/trunk/products/ERP5/Document/EmailDocument.py Thu Jul  3 11:55:20 2008
@@ -277,7 +277,10 @@
       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',):
-          return part.get_payload(decode=1).decode(part_encoding).encode('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
 




More information about the Erp5-report mailing list