From 9697f8b04341af6e76937c14d38255813219660b Mon Sep 17 00:00:00 2001
From: Stephane Wirtel <stephane@openerp.com>
Date: Thu, 6 May 2010 14:28:19 +0200
Subject: [PATCH] [FIX] fetchmail: Decode correctly the body and the subject of
 the emails

bzr revid: stephane@openerp.com-20100506122819-2c2ya2rln710l048
---
 addons/fetchmail/fetchmail.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py
index 598ed4aad6f3..832a2ffd9102 100644
--- a/addons/fetchmail/fetchmail.py
+++ b/addons/fetchmail/fetchmail.py
@@ -184,7 +184,7 @@ class email_server(osv.osv):
         history_pool = self.pool.get('mail.server.history')
         msg_txt = email.message_from_string(message)
         message_id = msg_txt.get('Message-ID', False)
-        
+
         msg = {}
         if not message_id:
             return False
@@ -195,7 +195,7 @@ class email_server(osv.osv):
         msg['message-id'] = message_id
         
         if 'Subject' in fields:
-            msg['subject'] = msg_txt.get('Subject')
+            msg['subject'] = ' '.join(map(lambda (x, y): unicode(x, y or 'ascii'), decode_header(msg_txt.get('Subject'))))
         
         if 'Content-Type' in fields:
             msg['content-type'] = msg_txt.get('Content-Type')
@@ -259,6 +259,9 @@ class email_server(osv.osv):
             msg['body'] = body
             msg['attachments'] = attachents
 
+        encoding = msg_txt.get_content_charset('utf-8')
+        msg['body'] = msg['body'].decode(encoding).encode('utf-8')
+
         res_id = False
         if msg.get('references', False):
             id = False
-- 
GitLab