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)
# 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')
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
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
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
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