diff --git a/addons/outlook/plugin/openerp-outlook-plugin/addin.py b/addons/outlook/plugin/openerp-outlook-plugin/addin.py index b75342e9996..eec4e5ed6f2 100644 --- a/addons/outlook/plugin/openerp-outlook-plugin/addin.py +++ b/addons/outlook/plugin/openerp-outlook-plugin/addin.py @@ -50,120 +50,71 @@ def GetConn(): d=Dispatch("Python.OpenERP.XMLRpcConn") return d class Configuration: - def Init(self, application): - self.mngr = None - - def Close(self): - self.mngr = None - self.close() - win32ui.MessageBox("Configuration","Configuration") def OnClick(self, button, cancel): import win32ui try: - self.mngr = manager.GetManager() - self.mngr.ShowManager() + mngr = manager.GetManager() + mngr.ShowManager() except Exception,e: win32ui.MessageBox("Fail to Initialize dialog.\n"+str(e),"OpenERP Configuration", win32con.MB_ICONERROR) return cancel # class ViewPartners: - def Init(self, application): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - - def Close(self): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - self.close() - win32ui.MessageBox("ViewPartners","ViewPartners") - def OnClick(self, button, cancel): from win32com.client import Dispatch import win32con - self.mngr = manager.GetManager() - self.data = self.mngr.LoadConfig() - self.outlook = Dispatch("Outlook.Application") - self.ex = self.outlook.ActiveExplorer() - if self.ex: - is_login = str(self.data['login']) + mngr = manager.GetManager() + data = mngr.LoadConfig() + outlook = Dispatch("Outlook.Application") + ex = outlook.ActiveExplorer() + if ex: + is_login = str(data['login']) if is_login == 'False': win32ui.MessageBox("Please login to the database first", "OpenERP Connection", win32con.MB_ICONEXCLAMATION) - elif self.ex.Selection.Count == 1 or self.ex.Selection.Count == 0: - self.mngr = manager.GetManager() - self.mngr.ShowManager("IDD_VIEW_PARTNER_DIALOG") - elif self.ex.Selection.Count > 1: + elif ex.Selection.Count == 1 or ex.Selection.Count == 0: + mngr = manager.GetManager() + mngr.ShowManager("IDD_VIEW_PARTNER_DIALOG") + elif ex.Selection.Count > 1: win32ui.MessageBox("Multiple selection not allowed. Please select only one mail at a time.","Open Contact",win32con.MB_ICONINFORMATION) return cancel # class OpenPartner: - def Init(self, application): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - - def Close(self): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - self.close() - win32ui.MessageBox("OpenPartner","OpenPartner") - def OnClick(self, button, cancel): import win32ui - self.mngr = manager.GetManager() - self.data = self.mngr.LoadConfig() - self.outlook = Dispatch("Outlook.Application") - self.ex = self.outlook.ActiveExplorer() + mngr = manager.GetManager() + data = mngr.LoadConfig() + outlook = Dispatch("Outlook.Application") + ex = outlook.ActiveExplorer() if ex: - is_login = str(self.data['login']) + is_login = str(data['login']) if is_login == 'False': win32ui.MessageBox("Please login to the database first", "OpenERP Connection", win32con.MB_ICONEXCLAMATION) - elif self.ex.Selection.Count == 1: - self.mngr = manager.GetManager() - self.mngr.ShowManager("IDD_OPEN_PARTNER_DIALOG") - elif self.ex.Selection.Count == 0: + elif ex.Selection.Count == 1: + mngr = manager.GetManager() + mngr.ShowManager("IDD_OPEN_PARTNER_DIALOG") + elif ex.Selection.Count == 0: win32ui.MessageBox("No mail selected to push to OpenERP","Push to OpenERP",win32con.MB_ICONINFORMATION) - elif self.ex.Selection.Count > 1: + elif ex.Selection.Count > 1: win32ui.MessageBox("Multiple selection not allowed. Please select only one mail at a time.","Push to OpenERP",win32con.MB_ICONINFORMATION) return cancel # class OpenDocument: - def Init(self, application): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - - def Close(self): - self.mngr = None - self.data = None - self.outlook = None - self.ex= None - self.close() - win32ui.MessageBox("OpenDocument","OpenDocument") - def OnClick(self, button, cancel): from win32com.client import Dispatch import win32con - self.mngr = manager.GetManager() - self.data = self.mngr.LoadConfig() - self.outlook = Dispatch("Outlook.Application") - self.ex = self.outlook.ActiveExplorer() - if self.ex: - is_login = str(self.data['login']) + mngr = manager.GetManager() + data = mngr.LoadConfig() + outlook = Dispatch("Outlook.Application") + ex = outlook.ActiveExplorer() + if ex: + is_login = str(data['login']) if is_login == 'False': win32ui.MessageBox("Please login to the database first", "OpenERP Connection", win32con.MB_ICONEXCLAMATION) - elif self.ex.Selection.Count == 1 or self.ex.Selection.Count == 0: - self.mngr = self.manager.GetManager() - self.mngr.ShowManager("IDD_OPEN_DOCUEMNT_DIALOG") - elif self.ex.Selection.Count > 1: + elif ex.Selection.Count == 1 or ex.Selection.Count == 0: + mngr = manager.GetManager() + mngr.ShowManager("IDD_OPEN_DOCUEMNT_DIALOG") + elif ex.Selection.Count > 1: win32ui.MessageBox("Multiple selection not allowed. Please select only one mail at a time.","Open Document",win32con.MB_ICONINFORMATION) return cancel # diff --git a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py index 36646fb1299..85abe755bd7 100644 --- a/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py +++ b/addons/outlook/plugin/openerp-outlook-plugin/tiny_xmlrpc.py @@ -133,35 +133,36 @@ class XMLRpcConn(object): break def ArchiveToOpenERP(self, recs, mail): - import win32con + import win32con + import win32ui conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object') flag = False new_msg = ext_msg ="" message_id = referances = None try: - session = win32com.client.Dispatch("MAPI.session") - session.Logon('Outlook') - objMessage = session.GetMessage(mail.EntryID, mail.Parent.StoreID) - objFields = objMessage.Fields - strheader = objFields.Item(mapitags.PR_TRANSPORT_MESSAGE_HEADERS) - strheader = ustr(strheader).encode('iso-8859-1') - headers = {} - strheader = strheader.replace("\n ", " ").splitlines() - for line in strheader: - split_here = line.find(":") - headers[line[:split_here]] = line[split_here:] - temp1 = headers.get('Message-ID') - temp2 = headers.get('Message-Id') - referances = headers.get('References') - if temp1 == None: message_id = temp2 - if temp2 == None: message_id = temp1 - startCut = message_id.find("<") - endCut = message_id.find(">") - message_id = message_id[startCut:endCut+1] - if not referances == None: - startCut = referances.find("<") - endCut = referances.find(">") - referances = referances[startCut:endCut+1] + session = win32com.client.Dispatch("MAPI.session") + session.Logon('Outlook') + objMessage = session.GetMessage(mail.EntryID, mail.Parent.StoreID) + objFields = objMessage.Fields + strheader = objFields.Item(mapitags.PR_TRANSPORT_MESSAGE_HEADERS) + strheader = ustr(strheader).encode('iso-8859-1') + headers = {} + strheader = strheader.replace("\n ", " ").splitlines() + for line in strheader: + split_here = line.find(":") + headers[line[:split_here]] = line[split_here:] + temp1 = headers.get('Message-ID') + temp2 = headers.get('Message-Id') + referances = headers.get('References') + if temp1 == None: message_id = temp2 + if temp2 == None: message_id = temp1 + startCut = message_id.find("<") + endCut = message_id.find(">") + message_id = message_id[startCut:endCut+1] + if not referances == None: + startCut = referances.find("<") + endCut = referances.find(">") + referances = referances[startCut:endCut+1] except Exception,e: win32ui.MessageBox(str(e),"Archive To OpenERP") return @@ -447,11 +448,21 @@ class XMLRpcConn(object): return True def SearchEmailResources(self, message_id): + 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)]) + ref_mail_id = None if not mail_id: - return None + ref_mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message', 'search', [('references','=',message_id)]) + if ref_mail_id: + win32ui.MessageBox(str(ref_mail_id),"ref_mail_id") + address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message','read',ref_mail_id[0],['model','res_id']) + win32ui.MessageBox(str(address),"address") + 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']) for key, vals in address.items(): res_vals.append([key,vals])