diff options
| author | Stephane Wirtel <stw@openerp.com> | 2011-09-13 16:00:16 +0200 |
|---|---|---|
| committer | Stephane Wirtel <stw@openerp.com> | 2011-09-13 16:00:16 +0200 |
| commit | 2a59ce92e3ea35cca00a314d44556b522b3c2fa8 (patch) | |
| tree | 6e7eec2157a513284e6740a95f2e39b7f04aef79 /addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py | |
| parent | 8a2bc42c3c45b4d3c94070a29fa76636256f3da7 (diff) | |
| parent | 2a40f9a4997eecc6f997ab0e43dc6334263b9cad (diff) | |
[MERGE] Email Framework - lp:~openerp-dev/openobject-addons/trunk-emails-unified
bzr revid: stw@openerp.com-20110913140016-zzfynrnjdaap0tfb
Diffstat (limited to 'addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py')
| -rw-r--r-- | addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py | 98 |
1 files changed, 53 insertions, 45 deletions
diff --git a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py index 7ecb2aea81f..41346fe7cf9 100644 --- a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py +++ b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py @@ -20,6 +20,8 @@ ##############################################################################
import xmlrpclib
+import binascii
+import base64
import sys
import socket
import os
@@ -146,6 +148,7 @@ class XMLRpcConn(object): flag = False
new_msg = ext_msg =""
message_id = referances = None
+ context = {}
try:
session = win32com.client.Dispatch("MAPI.session")
session.Logon('Outlook')
@@ -177,15 +180,15 @@ class XMLRpcConn(object): for rec in recs: #[('res.partner', 3, 'Agrolait')]
model = rec[0]
res_id = rec[1]
- #Check if mailgate installed
- object_id = execute ( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','search',[('model','=','mailgate.message')])
+ #Check if mail installed
+ object_id = execute ( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','search',[('model','=','mail.message')])
if not object_id:
- win32ui.MessageBox("Mailgate is not installed on your configured database '%s' !!\n\nPlease install it to archive the mail."%(self._dbname),"Mailgate not installed",win32con.MB_ICONERROR)
+ win32ui.MessageBox("Mail is not installed on your configured database '%s' !!\n\nPlease install it to archive the mail."%(self._dbname),"Mail not installed",win32con.MB_ICONERROR)
return
object_ids = execute ( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','search',[('model','=',model)])
object_name = execute( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','read',object_ids,['name'])[0]['name']
#Reading the Object ir.model Name
- ext_ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'mailgate.message','search',[('message_id','=',message_id),('model','=',model),('res_id','=',res_id)])
+ ext_ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'mail.message','search',[('message_id','=',message_id),('model','=',model),('res_id','=',res_id)])
if ext_ids:
name = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,model,'read',res_id,['name'])['name']
ext_msg += """This mail is already archived to {0} '{1}'.\n""".format(object_name,name)
@@ -201,14 +204,30 @@ class XMLRpcConn(object): 'message-id':message_id,
'references':ustr(referances),
}
- obj_list= ['crm.lead','project.issue','hr.applicant','res.partner']
- if rec[0] not in obj_list:
- self.CreateEmailAttachment(rec,mail)
result = {}
+ context['thread_model'] = model
if attachments:
result = self.MakeAttachment([rec], mail)
- attachment_ids = result.get(model, {}).get(res_id, [])
- execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','history',model, res_id, msg, attachment_ids)
+ execute(conn, 'execute', self. _dbname, int(self._uid), self._pwd,
+ 'mail.thread','message_append',[res_id],
+ msg.get('subject', False),
+ msg.get('body', False),
+ msg.get('to', False),
+ msg.get('from', False),
+ msg.get('cc', False),
+ False, # BCC
+ False, #reply-to
+ msg.get('date', False),
+ msg.get('message-id'),\
+ msg.get('references', False),
+ result, #attachments
+ #FIXME: properly handle plaintext/html body variants?
+ False, #body_html
+ False, #subtype
+ False, #headers
+ False, #original
+ context)
+
new_msg += """- {0} : {1}\n""".format(object_name,str(rec[2]))
flag = True
@@ -298,7 +317,7 @@ class XMLRpcConn(object): endCut = message_id.find(">")
message_id = message_id[startCut:endCut+1]
email.replace_header('Message-Id',message_id)
- id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','process_email',section, str(email))
+ id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'mail.thread','message_process',section, str(email))
if id > 0:
flag = True
return flag
@@ -310,39 +329,28 @@ class XMLRpcConn(object): return flag
def MakeAttachment(self, recs, mail):
- attachments = mail.Attachments
- result = {}
- conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
- att_folder_path = os.path.abspath(os.path.dirname("%temp%\\"))
- if not os.path.exists(att_folder_path):
+ attachments = mail.Attachments
+ attachment = {}
+ conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
+ att_folder_path = os.path.abspath(os.path.dirname("%temp%\\"))
+ if not os.path.exists(att_folder_path):
os.makedirs(att_folder_path)
for rec in recs: #[('res.partner', 3, 'Agrolait')]
- obj = rec[0]
- obj_id = rec[1]
- res={}
- res['res_model'] = obj
- attachment_ids = []
- if obj not in result:
- result[obj] = {}
- for i in xrange(1, attachments.Count+1):
- fn = ustr(attachments[i].FileName)
- if len(fn) > 64:
- l = 64 - len(fn)
- f = fn.split('.')
- fn = f[0][0:l] + '.' + f[-1]
- att_path = os.path.join(att_folder_path,fn)
- attachments[i].SaveAsFile(att_path)
- f=open(att_path,"rb")
- content = "".join(f.readlines()).encode('base64')
- f.close()
- res['name'] = ustr(attachments[i].DisplayName)
- res['datas_fname'] = ustr(fn)
- res['datas'] = content
- res['res_id'] = obj_id
- id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.attachment','create',res)
- attachment_ids.append(id)
- result[obj].update({obj_id: attachment_ids})
- return result
+ obj = rec[0]
+ obj_id = rec[1]
+ for i in xrange(1, attachments.Count+1):
+ fn = ustr(attachments[i].FileName)
+ if len(fn) > 64:
+ l = 64 - len(fn)
+ f = fn.split('.')
+ fn = f[0][0:l] + '.' + f[-1]
+ att_path = os.path.join(att_folder_path,fn)
+ attachments[i].SaveAsFile(att_path)
+ f=open(att_path,"rb")
+ content = "".join(f.readlines())
+ f.close()
+ attachment[fn] = content
+ return attachment
def CreateContact(self, res=None):
res=eval(str(res))
@@ -456,17 +464,17 @@ class XMLRpcConn(object): import win32ui
conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
res_vals = []
- mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message', 'search', [('message_id','=',message_id)])
+ mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mail.message', 'search', [('message_id','=',message_id)])
ref_mail_id = None
if not mail_id:
- ref_mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message', 'search', [('references','=',message_id)])
+ ref_mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mail.message', 'search', [('references','like','%'+message_id+'%')])
if ref_mail_id:
- address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message','read',ref_mail_id[0],['model','res_id'])
+ address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mail.message','read',ref_mail_id[0],['model','res_id'])
for key, vals in address.items():
res_vals.append([key,vals])
return res_vals
return None
- address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message','read',mail_id[0],['model','res_id'])
+ address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mail.message','read',mail_id[0],['model','res_id'])
for key, vals in address.items():
res_vals.append([key,vals])
return res_vals
|
