[FIX] thunderbird: changes in partner.py for history()
bzr revid: rha@tinyerp.com-20110421091125-nevt80ac5y1vn5jy
This commit is contained in:
parent
b511ca0034
commit
b794d93e2a
|
@ -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 = {}
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -23,28 +23,6 @@ from osv import osv
|
|||
import base64
|
||||
import email
|
||||
import tools
|
||||
import binascii
|
||||
class email_thread(osv.osv):
|
||||
_inherit = "email.thread"
|
||||
def history_message(self, cr, uid, model, res_id, message, context=None):
|
||||
#@param message: string of mail which is read from EML File
|
||||
attachment_pool = self.pool.get('ir.attachment')
|
||||
email_message_pool = self.pool.get('email.message')
|
||||
msg = email_message_pool.parse_message(message)
|
||||
attachments = msg.get('attachments', [])
|
||||
att_ids = []
|
||||
for attachment in attachments:
|
||||
data_attach = {
|
||||
'name': attachment,
|
||||
'datas': binascii.b2a_base64(str(attachments.get(attachment))),
|
||||
'datas_fname': attachment,
|
||||
'description': 'Mail attachment From Thunderbird msg_id: %s' %(msg.get('message_id', '')),
|
||||
'res_model': model,
|
||||
'res_id': res_id,
|
||||
}
|
||||
att_ids.append(attachment_pool.create(cr, uid, data_attach))
|
||||
return self.history(cr, uid, model, res_id, msg, att_ids)
|
||||
email_thread()
|
||||
|
||||
class thunderbird_partner(osv.osv_memory):
|
||||
_name = "thunderbird.partner"
|
||||
|
@ -67,6 +45,7 @@ class thunderbird_partner(osv.osv_memory):
|
|||
msg = dictcreate.get('message')
|
||||
mail = msg
|
||||
msg = self.pool.get('email.message').parse_message(msg)
|
||||
subject = msg.get('Subject', False)
|
||||
thread_pool = self.pool.get('email.thread')
|
||||
message_id = msg.get('message-id', False)
|
||||
msg_pool = self.pool.get('email.message')
|
||||
|
@ -75,7 +54,6 @@ class thunderbird_partner(osv.osv_memory):
|
|||
res_ids = []
|
||||
obj_list= ['crm.lead','project.issue','hr.applicant','res.partner']
|
||||
for ref_id in ref_ids:
|
||||
msg_new = dictcreate.get('message')
|
||||
ref = ref_id.split(',')
|
||||
model = ref[0]
|
||||
res_id = int(ref[1])
|
||||
|
@ -108,7 +86,14 @@ class thunderbird_partner(osv.osv_memory):
|
|||
res['datas'] = base64.b64encode(mail)
|
||||
res['res_id'] = res_id
|
||||
obj_attch.create(cr, uid, res)
|
||||
thread_pool.history_message(cr, uid, model, res_id, msg_new)
|
||||
threads = self.pool.get(model).browse(cr, uid, res_id)
|
||||
thread_pool.history(cr, uid, [threads], subject,
|
||||
email=msg.get('to', False),
|
||||
details=msg.get('body', False),
|
||||
email_from=msg.get('from', False),
|
||||
message_id= msg.get('message-id', False),
|
||||
attach= msg.get('attachments', {}),
|
||||
email_date= msg.get('date', False))
|
||||
res_ids.append(res_id)
|
||||
return len(res_ids)
|
||||
|
||||
|
|
Loading…
Reference in New Issue