From 094b909173e5202705d2b3b7a81a482afddea2bf Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Thu, 22 Jan 2009 16:39:36 +0000
Subject: [PATCH] Event chardet is not able to find True encoding, so return
 allways something

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25280 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/EmailDocument.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/EmailDocument.py b/product/ERP5/Document/EmailDocument.py
index 98253e15ce..fdc71406ca 100644
--- a/product/ERP5/Document/EmailDocument.py
+++ b/product/ERP5/Document/EmailDocument.py
@@ -303,7 +303,10 @@ class EmailDocument(File, TextDocument):
           except (UnicodeDecodeError, LookupError):
             codec = self._guessEncoding(message_text)
             if codec is not None:
-              text_result = message_text.decode(codec).encode('utf-8')
+              try:
+                text_result = message_text.decode(codec).encode('utf-8')
+              except (UnicodeDecodeError, LookupError):
+                text_result = repr(message_text)
             else:
               text_result = repr(message_text)
         else:
@@ -320,7 +323,10 @@ class EmailDocument(File, TextDocument):
           except (UnicodeDecodeError, LookupError):
             codec = self._guessEncoding(message_text)
             if codec is not None:
-              text_result = message_text.decode(codec).encode('utf-8')
+              try:
+                text_result = message_text.decode(codec).encode('utf-8')
+              except (UnicodeDecodeError, LookupError):
+                text_result = repr(message_text)
             else:
               text_result = repr(message_text)
         else:
-- 
2.30.9