diff --git a/addons/outlook/plugin/openerp-outlook-plugin/addin.py b/addons/outlook/plugin/openerp-outlook-plugin/addin.py index 8b376a5fd93..8edc277a306 100644 --- a/addons/outlook/plugin/openerp-outlook-plugin/addin.py +++ b/addons/outlook/plugin/openerp-outlook-plugin/addin.py @@ -33,33 +33,25 @@ import sys import os from win32com.client import Dispatch import win32con - sys.path.append(os.path.abspath(os.path.dirname(__file__))) #outlook sys.path.append(os.path.abspath(__file__)) #outlook/addin - import manager from win32com.client import CastTo import win32ui -from tiny_xmlrpc import * - +from tiny_xmlrpc import XMLRpcConn import locale locale.setlocale(locale.LC_NUMERIC, "C") - # Support for COM objects we use. gencache.EnsureModule('{00062FFF-0000-0000-C000-000000000046}', 0, 9, 0, bForDemand=True) # Outlook 9 gencache.EnsureModule('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 1, bForDemand=True) # Office 9 - # The TLB defiining the interfaces we implement universal.RegisterInterfaces('{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}', 0, 1, 0, ["_IDTExtensibility2"]) - global NewConn - # Retrieves registered XMLRPC connection def GetConn(): d=Dispatch("Python.OpenERP.XMLRpcConn") mngr = manager.GetManager() return d - class Configuration: def OnClick(self, button, cancel): import win32ui @@ -286,7 +278,6 @@ def RegisterXMLConn(klass): _winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, klass._reg_progid_) if __name__ == '__main__': - import win32com.server.register NewConn=XMLRpcConn() win32com.server.register.UseCommandLine(OutlookAddin) diff --git a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py index 3883e08ad78..c5c915dd254 100644 --- a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py +++ b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py @@ -34,7 +34,6 @@ import win32ui waittime = 10 wait_count = 0 wait_limit = 12 - def execute(connector, method, *args): global wait_count res = False @@ -173,42 +172,42 @@ class XMLRpcConn(object): new_mail=eml.generateEML(mail) attachments=mail.Attachments 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')]) - 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) - 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)]) - 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) - flag = True - continue - msg = { - 'subject':mail.Subject, - 'date':str(mail.ReceivedTime), - 'body':mail.Body, - 'cc':mail.CC, - 'from':mail.SenderEmailAddress, - 'to':mail.To, - 'message-id':message_id, - 'references':ustr(referances), - } - obj_list= ['crm.lead','project.issue','hr.applicant','res.partner'] - if rec[0] not in obj_list: - ids = self.CreateEmailAttachment(rec,mail) - result = {} - if attachments: - result = self.MakeAttachment([rec], mail) - attachment_ids = result.get(model, {}).get(res_id, []) - ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','history',model, res_id, msg, attachment_ids) - new_msg += """- {0} : {1}\n""".format(object_name,str(rec[2])) - flag = True + 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')]) + 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) + 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)]) + 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) + flag = True + continue + msg = { + 'subject':mail.Subject, + 'date':str(mail.ReceivedTime), + 'body':mail.Body, + 'cc':mail.CC, + 'from':mail.SenderEmailAddress, + 'to':mail.To, + 'message-id':message_id, + 'references':ustr(referances), + } + obj_list= ['crm.lead','project.issue','hr.applicant','res.partner'] + if rec[0] not in obj_list: + ids = self.CreateEmailAttachment(rec,mail) + result = {} + if attachments: + result = self.MakeAttachment([rec], mail) + attachment_ids = result.get(model, {}).get(res_id, []) + ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','history',model, res_id, msg, attachment_ids) + new_msg += """- {0} : {1}\n""".format(object_name,str(rec[2])) + flag = True if flag: t = """Mail archived Successfully with attachments.\n"""+ext_msg @@ -530,21 +529,15 @@ class XMLRpcConn(object): object = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.country.state','read',ids)[0] country = object['country_id'][1] return country - def CreateEmailAttachment(self, rec, email): + def CreateEmailAttachment(self, rec, mail): 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): - os.makedirs(att_folder_path) obj = rec[0] obj_id = rec[1] res={} res['res_model'] = obj ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|', '\t', '\n',':','~'] - sub = (email.Subject).replace(' ','') - if sub.strip() == '': - sub = 'NO SBUJECT' - fn = sub + fn = (mail.Subject).replace(' ','') for c in ls: fn = fn.replace(c,'') if len(fn) > 64: @@ -555,16 +548,15 @@ class XMLRpcConn(object): l = 64 - len(fn) f = fn.split('.') fn = f[0][0:l] + '.' + f[-1] - fn = fn+'.txt' - att_path = os.path.join(att_folder_path,fn) + fn = fn[:-4]+'.txt' f=open(fn,"w") - f.writelines(ustr(email.Body).encode('iso-8859-1')) + body = mail.Body.encode("utf-8") + f.writelines(body) f.close() - f=open(fn,"r") + f=open(fn,"rb") content = "".join(f.readlines()).encode('base64') f.close() - att_path = os.path.join(att_folder_path,fn) - res['name'] = ustr(sub) + res['name'] = ustr((mail.Subject).replace(' ','')) res['datas_fname'] = ustr(fn) res['datas'] = content res['res_id'] = obj_id