[MERGE] clean message_id problem in outlook plugin and opendocument button

bzr revid: hmo@tinyerp.com-20101011105311-u32doqfdc6sqejke
This commit is contained in:
Harry (OpenERP)
2010-10-11 16:23:11 +05:30
7 changed files with 130 additions and 51 deletions
+1
View File
@@ -4,6 +4,7 @@ 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
How to install openerp-outlook plug-in?
======================================================================================
+4
View File
@@ -55,6 +55,7 @@ class outlook_installer(osv.osv_memory):
Pre-requirements :
1. Python 2.6+ .
2. Python for Windows extensions - PyWin32 this module for python must be installed for appropriate version of the Python.
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” .
@@ -65,6 +66,9 @@ How to install openerp-outlook plug-in?
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\" ).
Note :
Please refer README file for dependecies external link, openobject-addons/outlook/README.
"""
}
outlook_installer()
@@ -61,14 +61,14 @@ def GetConn():
return d
class ButtonEvent:
def OnClick(self, button, cancel):
import win32ui
try:
mngr = manager.GetManager()
mngr.ShowManager()
except Exception,e:
win32ui.MessageBox("Fail to Initialize dialog.\n"+str(e),"OpenERP Configuration", win32con.MB_ICONERROR)
return cancel
def OnClick(self, button, cancel):
import win32ui
try:
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 OnClick(self, button, cancel):
@@ -202,11 +202,11 @@ class OutlookAddin:
item.Enabled = True
# item = toolbarweb.Controls.Add(Type = constants.msoControlButton, Temporary = True)
# item = self.toolbarButtonOpenDocument = DispatchWithEvents(item, OpenDocument)
# item.Caption = "Open Document"
# item.TooltipText = "Click to Open Document that ha been pushed to server."
# item.Enabled = True
item = toolbarweb.Controls.Add(Type = constants.msoControlButton, Temporary = True)
item = self.toolbarButtonOpenDocument = DispatchWithEvents(item, OpenDocument)
item.Caption = "Open Document"
item.TooltipText = "Click to Open Document that ha been pushed to server."
item.Enabled = True
# Hook events for the item
item = toolbarweb.Controls.Add(Type = constants.msoControlButton, Temporary = True)
@@ -438,6 +438,7 @@ def TestConnection(btnProcessor,*args):
return
uname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
pwd = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2])
@@ -630,6 +631,8 @@ def GetSelectedItems(hwndList):
def MakeAttachment(btnProcessor,*args):
#Check if server running or user logged in
from win32com.client import Dispatch
import win32com
b = check()
if not b:
return
@@ -637,7 +640,6 @@ def MakeAttachment(btnProcessor,*args):
assert ex.Selection.Count == 1
mail = ex.Selection.Item(1)
mail = GetMail(btnProcessor)
#get selected records
hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
r = GetSelectedItems(hwndList)
@@ -940,6 +942,8 @@ def SetDefaultContact(txtProcessor,*args):
global partner_ref
global new_con_country
global new_con_state
global state_ref
global country_ref
state = win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[2])
country = win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[3])
if txtProcessor.init_done:
@@ -958,6 +962,8 @@ def SetDefaultContact(txtProcessor,*args):
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[3],new_con_country)
new_con_country = ""
new_con_state = ""
state_ref = ""
country_ref =""
return
#
try:
@@ -1082,6 +1088,8 @@ def GetDefaultEmail(txtProcessor,*args):
global partner_ref
global country_ref
global state_ref
global new_con_country
global new_con_state
partner_n = win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[0])
state_n = win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[10])
country_n = win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[11])
@@ -1097,10 +1105,13 @@ def GetDefaultEmail(txtProcessor,*args):
partner_ref = ""
country_ref = ""
state_ref = ""
new_con_country = ""
new_con_state = ""
if state_val == None:
country_ref = country_n
country_ref = state_val
if country_ref == None:
country_ref = ""
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[11], ustr(country_ref))
if not b:
@@ -1415,38 +1426,57 @@ def SerachOpenDocuemnt(txtProcessor,*args):
from win32com.client import Dispatch
import win32con
import win32ui
import win32com
from win32com.mapi import mapi, mapiutil, mapitags
import pythoncom
b = check()
if not b:
return
global web_server
global web_server_port
#Reading Current Selected Email.
ex = txtProcessor.window.manager.outlook.ActiveExplorer()
assert ex.Selection.Count == 1
mail = ex.Selection.Item(1)
link_box = None
#Acquiring control of the text box
try:
link_box = txtProcessor.GetControl()
except Exception,e:
win32ui.MessageBox(str(e),"Excet")
link_box = txtProcessor.GetControl()
#Checking for the web server Parameters
if web_server.strip() == "" or web_server.strip() == "http:\\\\":
win32gui.SendMessage(link_box, win32con.WM_SETTEXT, 0, " <Invalid Server Address>")
txtProcessor.init_done=True
return
linktodoc = ""
#Reading Current Selected Email.
win32ui.MessageBox(str(mail),"mail")
message_id = None
try:
vals = NewConn.SearchEmailResources(mail)
outlook = win32com.client.Dispatch("Outlook.Application")
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')
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]
except Exception,e:
win32ui.MessageBox(str(e),"Excep")
win32ui.MessageBox(str(e),"Open Document")
vals = NewConn.SearchEmailResources(message_id)
if vals == None:
win32gui.SendMessage(link_box, win32con.WM_SETTEXT, 0, "< Mail is still not archived.>")
txtProcessor.init_done=True
return
try:
linktodoc = web_server+":"+str(web_server_port)+"\\openerp\\form\\view?model="+vals[0][1]+"&id="+str(vals[1][1])
win32gui.SendMessage(link_box, win32con.WM_SETTEXT, 0, linktodoc)
linktodoc = "http:\\\\" +web_server+ ":"+str(web_server_port)+"\\openerp\\form\\view?model="+vals[0][1]+"&id="+str(vals[1][1])
win32gui.SendMessage(link_box, win32con.WM_SETTEXT, 0, str(linktodoc))
except Exception,e:
win32ui.MessageBox("Error While Opening Document.\n"+str(e),"Open Document", flag_error)
webbrowser.open_new(linktodoc)
File diff suppressed because one or more lines are too long
@@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
IDD_MANAGER DIALOGEX 0, 0, 460, 260
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME
CAPTION "OpenERP Configuarion"
CAPTION "OpenERP Configuration"
FONT 8, "Tahoma", 1000, 0, 0x0
BEGIN
DEFPUSHBUTTON "Close",ID_DONE,400,239,50,14//,WS_VISIBLE //| WS_TABSTOP
@@ -27,7 +27,9 @@ import pythoncom
import time
from manager import ustr
import email
from win32com.mapi import mapi, mapiutil, mapitags
import pythoncom
import win32com
waittime = 10
wait_count = 0
wait_limit = 12
@@ -136,13 +138,42 @@ class XMLRpcConn(object):
import win32ui, win32con
conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
import eml
flag = False
new_msg = files = ext_msg =""
message_id = referances = None
try:
outlook = win32com.client.Dispatch("Outlook.Application")
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
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:
@@ -154,13 +185,12 @@ class XMLRpcConn(object):
#Reading the Object ir.model Name
ext_ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'mailgate.message','search',[('message_id','=',mail.EntryID),('model','=',model),('res_id','=',res_id)])
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 {1} '{2}'.
""".format(object_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),
@@ -168,8 +198,8 @@ class XMLRpcConn(object):
'cc':mail.CC,
'from':mail.SenderEmailAddress,
'to':mail.To,
'message-id':str(new_mail.get('Message-Id')),
'references':str(new_mail.get('References')),
'message-id':message_id,
'references':ustr(referances),
}
result = {}
if attachments:
@@ -180,8 +210,8 @@ class XMLRpcConn(object):
flag = True
if flag:
t = ext_msg
t += """Mail archived Successfully with attachments.\n"""+new_msg
t = """Mail archived Successfully with attachments.\n"""+ext_msg
t += "\n"+new_msg
win32ui.MessageBox(t,"Archived to OpenERP",win32con.MB_ICONINFORMATION)
return flag
@@ -240,13 +270,35 @@ class XMLRpcConn(object):
def CreateCase(self, section, mail, partner_ids, with_attachments=True):
import win32ui
import eml
section=str(section)
flag = False
id = -1
try:
conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
email=eml.generateEML(mail)
id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','process_email',section, email)
message_id = referances = None
outlook = win32com.client.Dispatch("Outlook.Application")
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')
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]
email.replace_header('Message-Id',message_id)
win32ui.MessageBox(str(email),"Mail ")
id = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'email.server.tools','process_email',section, str(email))
if id > 0:
flag = True
return flag
@@ -398,21 +450,13 @@ class XMLRpcConn(object):
return None
return partner_id[0]
def SearchEmailResources(self, mail):
def SearchEmailResources(self, message_id):
import win32ui
import eml
conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
sub = ""
res_vals = []
try:
# new_mail = eml.generateEML(mail)
email.SaveAs()
message_id = str(new_mail.get('message-id'))
except Exception,e:
win32ui.MessageBox(str(e),"Mail Reading Error")
return None
mail_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'mailgate.message', 'search', [('message_id','=',message_id)])
if not mail_id:
return None