[FIX] thunderbird: changes in partner.py for history()
authorRifakat Haradwala (Open ERP) <rha@tinyerp.com>
Thu, 21 Apr 2011 09:11:25 +0000 (14:41 +0530)
committerRifakat Haradwala (Open ERP) <rha@tinyerp.com>
Thu, 21 Apr 2011 09:11:25 +0000 (14:41 +0530)
bzr revid: rha@tinyerp.com-20110421091125-nevt80ac5y1vn5jy

addons/mail/email_message.py
addons/mail/email_thread.py
addons/thunderbird/partner/partner.py

index b9e1a7a..6fb1bc8 100644 (file)
@@ -295,6 +295,7 @@ class email_message(osv.osv):
         """Return Dictionary Object after parse EML Message String
         @param message: email.message.Message object or string or unicode object
         """
+        msg_txt = message
         if isinstance(message, str):
             msg_txt = email.message_from_string(message)
 
@@ -304,7 +305,6 @@ class email_message(osv.osv):
             message = message.encode('utf-8')
             msg_txt = email.message_from_string(message)
 
-        msg_txt = message
         message_id = msg_txt.get('message-id', False)
         msg = {}
 
index 796fc35..df26ada 100644 (file)
@@ -158,10 +158,7 @@ class email_thread(osv.osv):
         if attach is None:
             attach = {}
 
-        model = context.get('thread_model', False)
-        if not model:
-            model = self._name
-        model_pool = self.pool.get(model)
+
 
         if email_date:
             edate = parsedate(email_date)
@@ -171,6 +168,10 @@ class email_thread(osv.osv):
         # The script sends the ids of the threads and not the object list
 
         if all(isinstance(thread_id, (int, long)) for thread_id in threads):
+            model = context.get('thread_model', False)
+            if not model:
+                model = self._name
+            model_pool = self.pool.get(model)
             threads = model_pool.browse(cr, uid, threads, context=context)
 
         att_obj = self.pool.get('ir.attachment')
index 3d0f293..7476255 100644 (file)
@@ -23,28 +23,6 @@ from osv import osv
 import base64\r
 import email\r
 import tools\r
-import binascii\r
-class email_thread(osv.osv):\r
-    _inherit = "email.thread"\r
-    def history_message(self, cr, uid, model, res_id, message, context=None):\r
-        #@param message: string of mail which is read from EML File\r
-        attachment_pool = self.pool.get('ir.attachment')\r
-        email_message_pool = self.pool.get('email.message')\r
-        msg = email_message_pool.parse_message(message)\r
-        attachments = msg.get('attachments', [])\r
-        att_ids = []\r
-        for attachment in attachments:\r
-            data_attach = {\r
-                'name': attachment,\r
-                'datas': binascii.b2a_base64(str(attachments.get(attachment))),\r
-                'datas_fname': attachment,\r
-                'description': 'Mail attachment From Thunderbird msg_id: %s' %(msg.get('message_id', '')),\r
-                'res_model': model,\r
-                'res_id': res_id,\r
-            }\r
-            att_ids.append(attachment_pool.create(cr, uid, data_attach))\r
-        return self.history(cr, uid, model, res_id, msg, att_ids)\r
-email_thread()\r
 \r
 class thunderbird_partner(osv.osv_memory):\r
     _name = "thunderbird.partner"\r
@@ -67,6 +45,7 @@ class thunderbird_partner(osv.osv_memory):
         msg = dictcreate.get('message')\r
         mail = msg\r
         msg = self.pool.get('email.message').parse_message(msg)\r
+        subject = msg.get('Subject', False)\r
         thread_pool = self.pool.get('email.thread')\r
         message_id = msg.get('message-id', False)\r
         msg_pool = self.pool.get('email.message')\r
@@ -75,7 +54,6 @@ class thunderbird_partner(osv.osv_memory):
         res_ids = []\r
         obj_list= ['crm.lead','project.issue','hr.applicant','res.partner']\r
         for ref_id in ref_ids:\r
-            msg_new = dictcreate.get('message')\r
             ref = ref_id.split(',')\r
             model = ref[0]\r
             res_id = int(ref[1])\r
@@ -108,7 +86,14 @@ class thunderbird_partner(osv.osv_memory):
                 res['datas'] = base64.b64encode(mail)\r
                 res['res_id'] = res_id\r
                 obj_attch.create(cr, uid, res)\r
-            thread_pool.history_message(cr, uid, model, res_id, msg_new)\r
+            threads = self.pool.get(model).browse(cr, uid, res_id)\r
+            thread_pool.history(cr, uid, [threads], subject,\r
+                            email=msg.get('to', False),\r
+                            details=msg.get('body', False),\r
+                            email_from=msg.get('from', False),\r
+                            message_id= msg.get('message-id', False),\r
+                            attach= msg.get('attachments', {}),\r
+                            email_date= msg.get('date', False))\r
             res_ids.append(res_id)\r
         return len(res_ids)\r
 \r