From cd6e18011bd8f9255ecdf3212c0fc8a33408c074 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 19 Apr 2009 13:13:47 +0000
Subject: [PATCH] Make the accessor more robust. Remove starting and trailing '
 from result

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

diff --git a/product/ERP5/Document/EmailDocument.py b/product/ERP5/Document/EmailDocument.py
index a8cd7cc1ce..a89f45db25 100644
--- a/product/ERP5/Document/EmailDocument.py
+++ b/product/ERP5/Document/EmailDocument.py
@@ -140,9 +140,12 @@ class EmailDocument(File, TextDocument):
         except (UnicodeDecodeError, LookupError), error_message:
           encoding = self._guessEncoding(text)
           if encoding is not None:
-            text = text.decode(encoding).encode('utf-8')
+            try:
+              text = text.decode(encoding).encode('utf-8')
+            except (UnicodeDecodeError, LookupError), error_message:
+              text = repr(text)[1:-1]
           else:
-            text = repr(text)
+            text = repr(text)[1:-1]
         if name in result:
           result[name] = '%s %s' % (result[name], text)
         else:
-- 
2.30.9