From 9c97036dade713208f49d6a05edbb38d5cc04596 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Thu, 11 Nov 2010 15:54:02 +0530 Subject: [PATCH 1/3] [FIX] Outlook : Archive Text File with the Document bzr revid: jam@tinyerp.com-20101111102402-3smnpciw2lzne0tj --- .../plugin/openerp-outlook-plugin/addin.py | 11 +-- .../openerp-outlook-plugin/tiny_xmlrpc.py | 94 +++++++++---------- 2 files changed, 44 insertions(+), 61 deletions(-) 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 From 9719dcd0dfdb59f87bb44f6d9b17c2a69b7ce8e7 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Thu, 11 Nov 2010 16:41:57 +0530 Subject: [PATCH 3/3] [IMP] Outlook : Modfifed the Installer for new outlook exe setup feature bzr revid: jam@tinyerp.com-20101111111157-m5snzqrnyj9lrwe8 --- addons/outlook/README | 25 ++++++++----------------- addons/outlook/installer.py | 17 ++++++----------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/addons/outlook/README b/addons/outlook/README index adfd4401cb3..a737a700496 100644 --- a/addons/outlook/README +++ b/addons/outlook/README @@ -2,31 +2,22 @@ OpenERP Outlook PLUG-IN Installation Guide Pre requirements : ====================================================================================== -1.Python 2.6+ . python can be downloaded from http://www.python.org/download/releases/ . -2.Python for Windows extensions - PyWin32 this module for python must be installed for appropriate version of the Python. It can be downloaded from http://sourceforge.net/projects/pywin32/files/ or http://starship.python.net/crew/mhammond/win32/ -3.If you are using MS Outlook 2007 than you are required to install "Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 (CDO 1.21)". It can be downloaded from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e17e7f31-079a-43a9-bff2-0a110307611e&displaylang=en + 1.Python 2.6+ . python can be downloaded from http://www.python.org/download/releases/ . + 2.Python for Windows extensions - PyWin32 this module for python must be installed for appropriate version of the Python. It can be downloaded from http://sourceforge.net/projects/pywin32/files/ or http://starship.python.net/crew/mhammond/win32/ + 3.If you are using MS Outlook 2007 than you are required to install "Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 (CDO 1.21)". It can be downloaded from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e17e7f31-079a-43a9-bff2-0a110307611e&displaylang=en How to install openerp-outlook plug-in? ====================================================================================== -1.Open your Python installation directory (e.g.: C:\Python26). -2.Create folder named “openerp-outlook-plugin”. -3.Extract your zip file “outlook-plugin.zip” to the folder. -4.Open the folder outlook-plugin. -5.And Run “Register-plugin.bat” file. -6.Run Outlook and Check addin has been registered. -7.Tools->OpenERP Configuration and test your connection. -8.See User Guide for More. + 1. Save the executable plug-in file. + 2. Close Outlook Application if Running. + 3. Run executable plug-in file and the folllow the instruction. How to uninstall openerp-outlook plug-in? ===================================================================================== -1.Open the folder outlook-plugin. -2.And Run “Unregister-plugin.bat” file. + 1. Go to Control Panel Click "Add/Remove Programmes" + 2. You will entry, you will find entry named 'OpenERP Outlook Addin 1.0' select it and click Uninstall. Note : Plug In has been successfully tested with MS Office 2003 and MS Offcie 2007. - Enjoy Archiving your Outlook E-mails to OpenERP. - - - diff --git a/addons/outlook/installer.py b/addons/outlook/installer.py index 0f71b6c33dc..5506d9e0ccd 100755 --- a/addons/outlook/installer.py +++ b/addons/outlook/installer.py @@ -32,7 +32,7 @@ class outlook_installer(osv.osv_memory): def default_get(self, cr, uid, fields, context={}): data = super(outlook_installer, self).default_get(cr, uid, fields, context) data['doc_file'] = 'http://doc.openerp.com/book/2/2_6_Comms/2_6_Comms_outlook.html' - file = open(addons.get_module_resource('outlook','plugin','openerp-outlook-plugin.zip'), 'r') + file = open(addons.get_module_resource('outlook','plugin','openerp-outlook-addin.exe'), 'r') data['plugin_file'] = base64.encodestring(file.read()) return data @@ -47,7 +47,7 @@ class outlook_installer(osv.osv_memory): _defaults = { 'outlook' : True, - 'name' : 'OpenERP-Outlook-PlugIn.zip', + 'name' : 'Openerp-Outlook-Addin v1.exe', 'doc_name' : 'Installation Guide to OpenERP Outlook Plug-in.doc', 'description' : """ * Save the Outlook plug­-in. @@ -58,15 +58,10 @@ Pre-requirements : 3. If you are using MS Outlook 2007 than you are required to install "Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 (CDO 1.21)". How to install openerp-outlook plug-in? - 1. Extract zip file “openerp-outlook-plugin.zip” . - 2. Open the folder openerp-outlook-plugin. - 3. Run “Register-plugin.bat” file. - 4. Run Outlook and Check addon has been registered. - 5. Tools->OpenERP Configuration and test your connection. - 6. See User Guide for more information. - 7. Keep All extratced files in some safe places - (e.g. python installation Directory "C:\pythonXX\" or Windows installation Directory "C:\Program Files\" ). - + 1. Save the executable plug-in file. + 2. Close Outlook Application if Running. + 3. Run executable plug-in file and the folllow the instruction. + Note : Please refer README file for dependecies external link, openobject-addons/outlook/README. """