[IMP] outlook: improvement

bzr revid: hmo@tinyerp.com-20100805103845-fiiiavbohbka01pl
This commit is contained in:
JAM (OpenERP)
2010-08-05 16:08:45 +05:30
committed by Harry (OpenERP)
parent 06145300d2
commit c5d49c63f4
7 changed files with 85 additions and 73 deletions
+3 -3
View File
@@ -23,15 +23,15 @@
"version" : "1.0",
"author" : "OpenERP SA",
"website" : "http://www.openerp.com/",
"depends" : ["base"],
"depends" : ["base", "mail_gateway"],
"category" : "Generic Modules/Outlook interface",
"description": '''
This module provide the Outlook plug-in.
Outlook plug-in allows you to select an object that you’d like to add
to your email and its attachments from MS Outlook. You can select a partner, a task,
a project, an analytical account, or any other object and attach selected
mail as .eml file in attachment of selected record.
a project, an analytical account, or any other object and Archived selected
mail in mailgate.messages with attachments.
''',
"init_xml" : [],
+1 -1
View File
@@ -711,7 +711,7 @@ def SearchObjectsForText(btnProcessor,*args):
search_txt = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
if not search_txt:
win32ui.MessageBox("Enter text to search for", "", flag_info)
win32ui.MessageBox("Enter text to search for", "Archive to OpenERP", flag_info)
return
# Get titles from list
obj_titles=[]
Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

File diff suppressed because one or more lines are too long
@@ -33,8 +33,7 @@ STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME
CAPTION "OpenERP Configuarion"
FONT 8, "Tahoma", 1000, 0, 0x0
BEGIN
DEFPUSHBUTTON "Done",ID_DONE,400,239,50,14//,WS_VISIBLE //| WS_TABSTOP
PUSHBUTTON "Cancel",IDCANCEL,340,239,50,14//, WS_VISIBLE //| WS_TABSTOP
DEFPUSHBUTTON "Cancel",ID_DONE,400,239,50,14//,WS_VISIBLE //| WS_TABSTOP
CONTROL "",IDC_TAB,"SysTabControl32",0x0,8,7,440,228
CONTROL "",IDC_LIST,"SysListView32",WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL |
LVS_SHOWSELALWAYS | LVS_REPORT | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES,0,0,0,0
@@ -57,7 +56,7 @@ BEGIN
EDITTEXT ID_USERNAME,85,70,154,12,ES_AUTOHSCROLL | WS_VISIBLE | WS_TABSTOP
LTEXT "Password : ",IDC_STATIC,30,90,100,17
EDITTEXT ID_PASSWORD,85,90,154,12,ES_AUTOHSCROLL | WS_VISIBLE | WS_TABSTOP | ES_PASSWORD
PUSHBUTTON "Test Connection",ID_BUT_TESTCONNECTION,179,110,60,13, WS_VISIBLE | WS_TABSTOP
PUSHBUTTON "Connect",ID_BUT_TESTCONNECTION,179,110,60,13, WS_VISIBLE | WS_TABSTOP
END
IDD_OBJECT_SETTINGS DIALOGEX 0, 0, 430, 210
@@ -92,25 +91,21 @@ BEGIN
LTEXT "",IDC_ABOUT,80,90,250,100
END
IDD_SERVER_PORT_DIALOG DIALOGEX 0, 0, 160, 90
IDD_SERVER_PORT_DIALOG DIALOGEX 0, 0, 160, 55
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTEXTHELP
CAPTION "Server and Port"
CAPTION "OpenERP Connection"
FONT 8, "Tahoma", 400, 0, 0x0
BEGIN
LTEXT "Server : ",IDC_STATIC,5,3,150,17
EDITTEXT ID_SERVER,40,3,94,12,ES_AUTOHSCROLL | WS_TABSTOP
EDITTEXT ID_SERVER,40,3,100,12,ES_AUTOHSCROLL | WS_TABSTOP
LTEXT "Port : ",IDC_STATIC,5,18,100,17
EDITTEXT ID_PORT,40,18,94,12,ES_AUTOHSCROLL | WS_TABSTOP
GROUPBOX " Protocol ", IDC_STATIC_GROUP, 5, 35, 150, 30
PUSHBUTTON "XML-RPC",IDR_XML_PROTOCOL,8,45,50,14,BS_AUTORADIOBUTTON | BST_CHECKED |WS_TABSTOP
PUSHBUTTON "XML-RPCS",IDR_XMLS_PROTOCOL,55,45,50,14,BS_AUTORADIOBUTTON | WS_TABSTOP
PUSHBUTTON "NET-RPC",IDR_NETRPC_PROTOCOL,105,45,45,14,BS_AUTORADIOBUTTON | WS_TABSTOP
PUSHBUTTON "Close",IDCANCEL,60,70,45,14,WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,110,70,45,14,WS_TABSTOP
EDITTEXT ID_PORT,40,18,100,12,ES_AUTOHSCROLL | WS_TABSTOP
PUSHBUTTON "Close",IDCANCEL,110,35,45,14,WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,60,35,45,14,WS_TABSTOP
END
IDD_SYNC DIALOGEX 0, 0, 470, 300
IDD_SYNC DIALOGEX 0, 0, 470, 320
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTEXTHELP
CAPTION "Archive to OpenERP"
@@ -120,8 +115,9 @@ BEGIN
LTEXT "Search for : ",IDC_STATIC,15,17,40,12
EDITTEXT ID_SEARCH_TEXT,60,15,120,12,ES_AUTOHSCROLL | WS_TABSTOP// left top width height
PUSHBUTTON "Search",ID_SEARCH,187,15,40,14,WS_TABSTOP
LTEXT "Documents : ",IDC_STATIC,15,140,100,14
CONTROL "List1",IDC_NAME_LIST,"SysListView32",WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_SHOWSELALWAYS | LVS_REPORT | WS_TABSTOP, 15,150,234,110
PUSHBUTTON "Upload to OpenERP",ID_MAKE_ATTACHMENT,160,270,85,14,WS_TABSTOP
PUSHBUTTON "Archive to OpenERP",ID_MAKE_ATTACHMENT,160,270,85,14,WS_TABSTOP
GROUPBOX " Create a Document ", IDC_STATIC_GROUP, 263,5,202,100,WS_TABSTOP
LTEXT "Type of Document : ",IDC_STATIC,266,25,100,12
@@ -132,7 +128,7 @@ BEGIN
GROUPBOX " Create a Contact ", IDC_STATIC_GROUP, 263, 110,202,185,WS_TABSTOP
LTEXT "Create a New Contact : ",IDC_STATIC,280,140,100,12
PUSHBUTTON "Create Contact",ID_CREATE_CONTACT,360,138,60,14,WS_TABSTOP
PUSHBUTTON "Cancel",IDCANCEL,385,270,60,14,WS_TABSTOP
PUSHBUTTON "Close",IDCANCEL,385,300,60,14,WS_TABSTOP
END
IDD_NEW_CONTACT_DIALOG DIALOGEX 0, 0, 350, 190
+3 -2
View File
@@ -37,7 +37,8 @@ def generateEML(mail):
eml_name= ustr(sub).encode('iso-8859-1')+'-'+str(mail.EntryID)[-9:]
ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|', '\t', '\n']
attachments_folder_path = os.path.abspath(os.path.dirname(__file__)+"\\dialogs\\resources\\attachments\\")
mails_folder_path = os.path.abspath(os.path.dirname(__file__)+"\\dialogs\\resources\\mails\\")
attachments_folder_path = mails_folder_path + "\\attachments\\"
if not os.path.exists(attachments_folder_path):
os.makedirs(attachments_folder_path)
for i in xrange(1, attachments.Count+1):
@@ -62,7 +63,7 @@ def generateEML(mail):
print mail.lastErrorText()
sys.exit()
mails_folder_path = os.path.abspath(os.path.dirname(__file__)+"\\dialogs\\resources\\mails\\")
if not os.path.exists(mails_folder_path):
os.makedirs(mails_folder_path)
for c in ls:
+63 -48
View File
@@ -26,11 +26,11 @@ import os
import pythoncom
import time
from manager import ustr
waittime = 10
wait_count = 0
wait_limit = 12
import binascii
import base64
def execute(connector, method, *args):
global wait_count
res = False
@@ -119,7 +119,7 @@ class XMLRpcConn(object):
def InsertObj(self, obj_title,obj_name,image_path):
self._obj_list=list(self._obj_list)
self._obj_list.append((obj_title,obj_name,ustr(image_path).encode('iso-8859-1')))
self._obj_list.append((obj_title,obj_name,ustr(image_path)))
self._obj_list.sort(reverse=True)
def DeleteObject(self,sel_text):
@@ -133,46 +133,53 @@ class XMLRpcConn(object):
import win32ui, win32con
conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
import eml
msg = ""
ext_msg = ""
new_msg = files = ext_msg =""
eml_path=eml.generateEML(mail)
att_name = ustr(eml_path.split('\\')[-1])
cnt=1
flag=False
for rec in recs: #[('res.partner', 3, 'Agrolait')]
cnt+=1
obj = rec[0]
obj_id = rec[1]
ids=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.attachment','search',[('res_id','=',obj_id),('name','=',att_name)])
object_ids = execute ( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','search',[('model','=',obj)])
object_name = execute( conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','read',object_ids,['name'])[0]['name']
sub = ustr(mail.Subject)
if ids:
name=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'read',obj_id,['name'])['name']
ext_msg+=""" - File "{0}.eml" is already archived to {1} "{2}" .
""".format(sub,object_name,name)
continue
if len(sub) > 60:
l = 60 - len(sub)
sub = sub[0:l]
res={}
res['res_model'] = obj
content = "".join(open(eml_path,"r").readlines()).encode('base64')
res['name'] = att_name
res['datas_fname'] = sub+".eml"
res['datas'] = content
res['res_id'] = obj_id
execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.attachment','create',res)
msg+=""" - File "{0}.eml" archived to {1} "{2}".
""".format(sub,object_name,str(rec[2]))
flag=True
if flag:
t = "Mail archived to OpenERP.\nArchive Summary : \n"
if ext_msg != "" :
t+="\nAlready Attached Documents : \n"+ext_msg +"\n"
t+="Newly Attachment Documents:\n"+msg
win32ui.MessageBox(t,"Archive To OpenERP",win32con.MB_ICONINFORMATION)
attachments=mail.Attachments
for rec in recs: #[('res.partner', 3, 'Agrolait')]
model = rec[0]
res_id = rec[1]
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','=',mail.EntryID),('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)
continue
msg = {
'subject':mail.Subject,
'date':str(mail.ReceivedTime),
'body':mail.Body,
'cc':mail.CC,
'from':mail.SenderEmailAddress,
'to':mail.To,
'message-id':str(mail.EntryID),## we are use Entry_Id as a MessageID Because MessageID is not provided by Outlook API, http://msdn.microsoft.com/en-us/library/bb176688%28v=office.12%29.aspx
'references':False,
}
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 = ext_msg
t += """Mail archived Successfully with attachments.\n"""+new_msg
win32ui.MessageBox(t,"Archived to OpenERP",win32con.MB_ICONINFORMATION)
return flag
def IsCRMInstalled(self):
@@ -189,7 +196,7 @@ class XMLRpcConn(object):
obj_list.append((-999, ustr('')))
for id in ids:
object = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.partner','read',[id],['id','name'])[0]
obj_list.append((object['id'], ustr(object['name']).encode('iso-8859-1')))
obj_list.append((object['id'], ustr(object['name'])))
return obj_list
def GetObjectItems(self, search_list=[], search_text=''):
@@ -203,17 +210,17 @@ class XMLRpcConn(object):
ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'search',['|',('name','ilike',ustr(search_text)),('email','ilike',ustr(search_text))])
recs = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'read',ids,['id','name','street','city'])
for rec in recs:
name = ustr(rec['name']).encode('iso-8859-1')
name = ustr(rec['name'])
if rec['street']:
name += ', ' + ustr(rec['street']).encode('iso-8859-1')
name += ', ' + ustr(rec['street'])
if rec['city']:
name += ', ' + ustr(rec['city']).encode('iso-8859-1')
name += ', ' + ustr(rec['city'])
res.append((obj,rec['id'],name,object_name))
else:
ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'search',[('name','ilike',ustr(search_text))])
recs = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'read',ids,['id','name'])
for rec in recs:
name = ustr(rec['name']).encode('iso-8859-1')
name = ustr(rec['name'])
res.append((obj,rec['id'],name,object_name))
return res
@@ -247,17 +254,22 @@ class XMLRpcConn(object):
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(__file__)+"\\dialogs\\resources\\attachments\\")
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).encode('iso-8859-1')
fn = ustr(attachments[i].FileName)
if len(fn) > 64:
l = 64 - len(fn)
f = fn.split('.')
@@ -271,7 +283,10 @@ class XMLRpcConn(object):
res['datas_fname'] = ustr(fn)
res['datas'] = content
res['res_id'] = obj_id
execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.attachment','create',res)
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
def CreateContact(self, sel=None, res=None):
res=eval(str(res))
@@ -345,7 +360,7 @@ class XMLRpcConn(object):
state_ids = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country.state', 'search', [])
for state_id in state_ids:
obj = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country.state', 'read', [state_id],['id','name'])[0]
state_list.append((obj['id'], ustr(obj['name']).encode('iso-8859-1')))
state_list.append((obj['id'], ustr(obj['name'])))
return state_list
def GetAllCountry(self):
@@ -356,5 +371,5 @@ class XMLRpcConn(object):
country_ids = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country', 'search', [])
for country_id in country_ids:
obj = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country','read', [country_id], ['id','name'])[0]
country_list.append((obj['id'], ustr(obj['name']).encode('iso-8859-1')))
country_list.append((obj['id'], ustr(obj['name'])))
return country_list