コード例 #1
0
 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("%temp%\\"))
 	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)
 			if len(fn) > 64:
 				l = 64 - len(fn)
 				f = fn.split('.')
 				fn = f[0][0:l] + '.' + f[-1]
 			att_path = os.path.join(att_folder_path,fn)
 			attachments[i].SaveAsFile(att_path)
 			f=open(att_path,"rb")
 			content = "".join(f.readlines()).encode('base64')
 			f.close()
 			res['name'] = ustr(attachments[i].DisplayName)
 			res['datas_fname'] = ustr(fn)
 			res['datas'] = content
 			res['res_id'] = obj_id
 			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
コード例 #2
0
 def CreateCase(self, section, mail, partner_ids, with_attachments=True):
     res = {}
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     res['name'] = ustr(mail.Subject)
     res['note'] = ustr(mail.Body)
     ids = execute(conn, 'execute', self._dbname, int(self._uid), self._pwd,
                   'crm.case.section', 'search',
                   [('name', '=', ustr(section))])
     res['section_id'] = ids[0]
     if partner_ids:
         for partner_id in partner_ids:
             res['partner_id'] = partner_id
             partner_addr = execute(conn, 'execute', self._dbname,
                                    int(self._uid), self._pwd,
                                    'res.partner', 'address_get',
                                    [partner_id])
             res['partner_address_id'] = partner_addr['default']
             id = execute(conn, 'execute', self._dbname, int(self._uid),
                          self._pwd, 'crm.case', 'create', res)
             recs = [('crm.case', id, '')]
             if with_attachments:
                 self.MakeAttachment(recs, mail)
     else:
         id = execute(conn, 'execute', self._dbname, int(self._uid),
                      self._pwd, 'crm.case', 'create', res)
         recs = [('crm.case', id, '')]
         if with_attachments:
             self.MakeAttachment(recs, mail)
コード例 #3
0
def CreateContact(btnProcessor,*args):
    b = check()
    if not b:
        return

    partner = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[4])
    combo = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[4])
    sel = win32gui.SendMessage(combo, win32con.CB_GETCURSEL)

    name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
    email = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
    office_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2])
    mobile_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[3])

    if not name:
        win32ui.MessageBox("Please enter name.", "Create Contact", flag_stop)
        return
    res = {'name':ustr(name), 'email':ustr(email), 'phone':ustr(office_no), 'mobile':ustr(mobile_no)}
    try:
        id = NewConn.CreateContact(sel, str(res))
        msg="New contact created for partner '%s'."%partner
    except Exception,e:
        msg="Contact not created \n\n" + getMessage(e)
        win32ui.MessageBox(msg, "Create Contact", flag_error)
        return
コード例 #4
0
 def login(self, dbname, user, pwd):
     self._dbname = dbname
     self._uname = user
     self._pwd = pwd
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/common')
     uid = execute(conn, 'login', dbname, ustr(user), ustr(pwd))
     return uid
コード例 #5
0
 def ArchiveToOpenERP(self, recs, mail):
     import win32ui, win32con
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     import eml
     eml_path=eml.generateEML(mail)
     att_name = ustr(eml_path.split('\\')[-1])
     cnt=1
     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)])
         if ids:
             name=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'read',obj_id,['name'])['name']
             msg="This mail is already attached to object with name '%s'"%name
             win32ui.MessageBox(msg,"Make Attachment",win32con.MB_ICONINFORMATION)
             continue
         sub = ustr(mail.Subject)
         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)
コード例 #6
0
    def CreateCase(self, section, mail, partner_ids, with_attachments=True):
        res={}
        import win32ui
        section=str(section)
        partner_ids=eval(str(partner_ids))
        conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
        res['name'] = ustr(mail.Subject)
        res['description'] = ustr(mail.Body)
        res['partner_name'] = ustr(mail.SenderName)
        res['email_from'] = ustr(mail.SenderEmailAddress)

        if partner_ids:
            for partner_id in partner_ids:
                res['partner_id'] = partner_id
                partner_addr = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.partner','address_get',[partner_id])
                res['partner_address_id'] = partner_addr['default']
                id=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,section,'create',res)
                if section == 'project.issue':
                    execute(conn,'execute',self._dbname,int(self._uid),self._pwd,section,'convert_to_bug',[id])
                recs=[(section,id,'')]
                if with_attachments:
                    self.MakeAttachment(recs, mail)
        else:
            id=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,section,'create',res)
            recs=[(section,id,'')]
            if with_attachments:
                self.MakeAttachment(recs, mail)
コード例 #7
0
 def MakeAttachment(self, recs, mail):
     attachments = mail.Attachments
     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
         for i in xrange(1, attachments.Count+1):
             fn = ustr(attachments[i].FileName).encode('iso-8859-1')
             if len(fn) > 64:
                 l = 64 - len(fn)
                 f = fn.split('.')
                 fn = f[0][0:l] + '.' + f[-1]
             att_path = os.path.join(att_folder_path,fn)
             attachments[i].SaveAsFile(att_path)
             f=open(att_path,"rb")
             content = "".join(f.readlines()).encode('base64')
             f.close()
             res['name'] = ustr(attachments[i].DisplayName)
             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)
コード例 #8
0
 def login(self,dbname, user, pwd):
     self._dbname = dbname
     self._uname = user
     self._pwd = pwd
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/common')
     uid = execute(conn,'login',dbname, ustr(user), ustr(pwd))
     return uid
コード例 #9
0
    def CreateCase(self, section, mail, partner_ids, with_attachments=True):
        res = {}
        import win32ui
        section = str(section)
        partner_ids = eval(str(partner_ids))
        conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
        res['name'] = ustr(mail.Subject)
        res['description'] = ustr(mail.Body)
        res['partner_name'] = ustr(mail.SenderName)
        res['email_from'] = ustr(mail.SenderEmailAddress)

        if partner_ids:
            for partner_id in partner_ids:
                res['partner_id'] = partner_id
                partner_addr = execute(conn, 'execute', self._dbname,
                                       int(self._uid), self._pwd,
                                       'res.partner', 'address_get',
                                       [partner_id])
                res['partner_address_id'] = partner_addr['default']
                id = execute(conn, 'execute', self._dbname, int(self._uid),
                             self._pwd, section, 'create', res)
                if section == 'project.issue':
                    execute(conn, 'execute', self._dbname, int(self._uid),
                            self._pwd, section, 'convert_to_bug', [id])
                recs = [(section, id, '')]
                if with_attachments:
                    self.MakeAttachment(recs, mail)
        else:
            id = execute(conn, 'execute', self._dbname, int(self._uid),
                         self._pwd, section, 'create', res)
            recs = [(section, id, '')]
            if with_attachments:
                self.MakeAttachment(recs, mail)
コード例 #10
0
 def ArchiveToOpenERP(self, recs, mail):
     import win32ui, win32con
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     import eml
     eml_path = eml.generateEML(mail)
     att_name = ustr(eml_path.split('\\')[-1])
     cnt = 1
     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)])
         if ids:
             name = execute(conn, 'execute', self._dbname, int(self._uid),
                            self._pwd, obj, 'read', obj_id,
                            ['name'])['name']
             msg = "This mail is already attached to object with name '%s'" % name
             win32ui.MessageBox(msg, "Make Attachment",
                                win32con.MB_ICONINFORMATION)
             continue
         sub = ustr(mail.Subject)
         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)
コード例 #11
0
 def MakeAttachment(self, recs, mail):
     attachments = mail.Attachments
     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
         for i in xrange(1, attachments.Count + 1):
             fn = ustr(attachments[i].FileName).encode('iso-8859-1')
             if len(fn) > 64:
                 l = 64 - len(fn)
                 f = fn.split('.')
                 fn = f[0][0:l] + '.' + f[-1]
             att_path = os.path.join(att_folder_path, fn)
             attachments[i].SaveAsFile(att_path)
             f = open(att_path, "rb")
             content = "".join(f.readlines()).encode('base64')
             f.close()
             res['name'] = ustr(attachments[i].DisplayName)
             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)
コード例 #12
0
    def ArchiveToOpenERP(self, recs, mail):
        import win32ui, win32con
        conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
        import eml
        msg = ""
        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)

        return flag
コード例 #13
0
 def GetPartners(self):
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     ids=[]
     ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.partner','search',[])
     ids.sort()
     obj_list=[]
     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')))
     return obj_list
コード例 #14
0
ファイル: eml.py プロジェクト: Arsalan88/openerp-extra-6.1
def generateEML(mail):
    sub = (mail.Subject).replace(' ','')
    body = mail.Body.encode("utf-8")
    recipients=mail.Recipients
    sender=mail.SenderEmailAddress
    attachments=mail.Attachments

    email = chilkat.CkEmail()
    email.put_Subject(ustr(sub).encode('iso-8859-1'))
    email.put_Body(ustr(body).encode('utf-8'))
    email.put_From(ustr(sender).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count+1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        email.AddTo(name,address)

    eml_name= ustr(sub).encode('iso-8859-1')+'-'+str(mail.EntryID)[-9:]
    ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|']

    attachments_folder_path = os.path.abspath(os.path.dirname(__file__)+"\\dialogs\\resources\\attachments\\")
    if not os.path.exists(attachments_folder_path):
        os.makedirs(attachments_folder_path)
    for i in xrange(1, attachments.Count+1):
        fn = eml_name + '-' + ustr(attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c,'')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        f1  = att_file
        attachments[i].SaveAsFile(att_file)
        contentType = email.addFileAttachment(att_file)
        if (contentType == None ):
            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:
        eml_name = eml_name.replace(c,'')
    if len(eml_name) > 64:
       l = 64 - len(eml_name)
       f = eml_name.split('-')
       eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,eml_name+".eml")).encode('iso-8859-1')
    success = email.SaveEml(eml_path)
    if (success == False):
        sys.exit()

    return eml_path
コード例 #15
0
 def GetPartners(self):
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     ids = []
     ids = execute(conn, 'execute', self._dbname, int(self._uid), self._pwd,
                   'res.partner', 'search', [])
     ids.sort()
     obj_list = []
     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')))
     return obj_list
コード例 #16
0
 def GetCountry(self, country_search=''):
 	conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
 	ids=[]
 	obj_list=[]
 	domain = []
 	if not country_search.strip() == '':
 		domain.append(('name','ilike',ustr(country_search)))
 	ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.country','search',domain)
 	if ids:
 		ids.sort()
 		for id in ids:
 			object = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.country','read',[id],['id','name'])[0]
 			obj_list.append((object['id'], ustr(object['name'])))
 		obj_list.sort(lambda x, y: cmp(x[1],y[1]))
 	return obj_list
コード例 #17
0
 def ArchiveToOpenERP(self, recs, mail):
 	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]
 	except Exception,e:
 		win32ui.MessageBox(str(e),"Archive To OpenERP")
 		return
コード例 #18
0
def SetDefaultContact(txtProcessor,*args):
    txt_name = txtProcessor.GetControl()
    txt_email = txtProcessor.GetControl(txtProcessor.other_ids[0])

    global name
    global email
    if txtProcessor.init_done:
        win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.control_id,name)
        win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[0],email)
        return

    try:
        mail = GetMail(txtProcessor)
        name = ustr(mail.SenderName).encode('iso-8859-1')
        email = ustr(mail.SenderEmailAddress).encode('iso-8859-1')
    except Exception,e:
        pass
コード例 #19
0
    def ArchiveToOpenERP(self, recs, mail):
        import win32ui, win32con
        conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
        import eml
        msg = ""
        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)

        return flag
コード例 #20
0
 def GetObjectItems(self, search_list=[], search_text=''):
     res = []
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     for obj in search_list:
         if obj == "res.partner.address":
             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')
                 if rec['street']:
                     name += ', ' + ustr(rec['street']).encode('iso-8859-1')
                 if rec['city']:
                     name += ', ' + ustr(rec['city']).encode('iso-8859-1')
                 res.append((obj, rec['id'], 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')
                 res.append((obj, rec['id'], name))
     return res
コード例 #21
0
 def GetAllState(self):
 	state_list = []
 	state_ids = []
 	conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/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'])))
 	return state_list
コード例 #22
0
 def GetAllCountry(self):
 	country_list = []
 	country_ids = []
 	conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/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'])))
 	return country_list
コード例 #23
0
 def SearchPartners(self):
     res = []
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     obj = 'res.partner'
     ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'search',[])
     recs = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,obj,'read',ids,['id','name'])
     for rec in recs:
         name = ustr(rec['name'])
         res.append((obj,rec['id'],name,obj))
     return res
コード例 #24
0
 def GetCSList(self):
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     ids = execute(conn, 'execute', self._dbname, int(int(self._uid)),
                   self._pwd, 'crm.case.section', 'search', [])
     objects = execute(conn, 'execute', self._dbname, int(self._uid),
                       self._pwd, 'crm.case.section', 'read', ids, ['name'])
     obj_list = [
         ustr(item['name']).encode('iso-8859-1') for item in objects
     ]
     return obj_list
コード例 #25
0
 def GetObjectItems(self, search_list=[], search_text=''):
     res = []
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     for obj in search_list:
         if obj == "res.partner.address":
             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')
                 if rec['street']:
                     name += ', ' + ustr(rec['street']).encode('iso-8859-1')
                 if rec['city']:
                     name += ', ' + ustr(rec['city']).encode('iso-8859-1')
                 res.append((obj,rec['id'],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')
                 res.append((obj,rec['id'],name))
     return res
コード例 #26
0
 def CreateCase(self, section, mail, partner_ids, with_attachments=True):
     res={}
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     res['name'] = ustr(mail.Subject)
     res['note'] = ustr(mail.Body)
     ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'crm.case.section','search',[('name','=',ustr(section))])
     res['section_id'] = ids[0]
     if partner_ids:
         for partner_id in partner_ids:
             res['partner_id'] = partner_id
             partner_addr = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.partner','address_get',[partner_id])
             res['partner_address_id'] = partner_addr['default']
             id=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'crm.case','create',res)
             recs=[('crm.case',id,'')]
             if with_attachments:
                 self.MakeAttachment(recs, mail)
     else:
         id=execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'crm.case','create',res)
         recs=[('crm.case',id,'')]
         if with_attachments:
             self.MakeAttachment(recs, mail)
コード例 #27
0
def CreatePartner(btnProcessor,*args):
    #Check if server running or user logged in
    b = check()
    if not b:
        return

    partner_name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
    if not partner_name:
        win32ui.MessageBox("Please enter Partner name.", "Create Partner", flag_excl)
        return
    res = {'name':ustr(partner_name)}
    try:
        id = NewConn.CreatePartner(str(res))
    except Exception,e:
        msg="Partner not created \n\n" + getMessage(e)
        win32ui.MessageBox(msg, "Create Partner", flag_error)
        return
コード例 #28
0
ファイル: opt_processors.py プロジェクト: lbiemans/docker
 def UpdateControl_FromValue(self):
    from manager import ustr
    import win32ui
    combo = self.GetControl()
    conn = self.func()
    win32gui.SendMessage(combo, win32con.CB_RESETCONTENT, 0, 0);
    id_list = {}
    state_list=[]
    try:
        country_list = list(conn.GetAllCountry())
        for item in country_list:
            win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, ustr(item[1]).encode('iso-8859-1'))
        win32gui.SendMessage(combo, win32con.CB_SETCURSEL, -1, 0)
        cnt = win32gui.SendMessage(combo, win32con.CB_GETCOUNT, 0, 0)
        return
    except xmlrpclib.Fault,e:
        msg = str(e.faultCode) or e.faultString or e.message or str(e)
        win32ui.MessageBox(msg, "Open Partner")
コード例 #29
0
ファイル: opt_processors.py プロジェクト: Sk1f161/ERP
 def UpdateControl_FromValue(self):
    from manager import ustr
    import win32ui
    combo = self.GetControl()
    conn = self.func()
    win32gui.SendMessage(combo, win32con.CB_RESETCONTENT, 0, 0);
    id_list = {}
    state_list=[]
    try:
        country_list = list(conn.GetAllCountry())
        for item in country_list:
            win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, ustr(item[1]).encode('iso-8859-1'))
        win32gui.SendMessage(combo, win32con.CB_SETCURSEL, -1, 0)
        cnt = win32gui.SendMessage(combo, win32con.CB_GETCOUNT, 0, 0)
        return
    except xmlrpclib.Fault,e:
        msg = str(e.faultCode) or e.faultString or e.message or str(e)
        win32ui.MessageBox(msg, "Open Partner")
コード例 #30
0
def GetSearchText(txtProcessor,*args):
    #Check if server running or user logged in
    b = check()
    if not b:
        return

    search_box = txtProcessor.GetControl()
    global search_text
    if txtProcessor.init_done:
        win32gui.SendMessage(search_box, win32con.WM_SETTEXT, 0,search_text)
        return

    # Get the selected mail and set the default value for search_text_control to mail.SenderEmailAddress
    ex = txtProcessor.window.manager.outlook.ActiveExplorer()
    assert ex.Selection.Count == 1
    mail = ex.Selection.Item(1)
    try:
        search_text = ustr(mail.SenderEmailAddress).encode('iso-8859-1')
    except Exception,e:
        pass
コード例 #31
0
 def SearchPartnerDetail(self, search_email_id):
     import win32ui
     res_vals = []
     address = {}
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     address_id = execute(conn, 'execute', self._dbname, int(self._uid),
                          self._pwd, 'res.partner.address', 'search',
                          [('email', 'ilike', ustr(search_email_id))])
     if not address_id:
         return
     address = execute(conn, 'execute', self._dbname, int(self._uid),
                       self._pwd, 'res.partner.address', 'read',
                       address_id[0], [
                           'id', 'partner_id', 'name', 'street', 'street2',
                           'city', 'state_id', 'country_id', 'phone',
                           'mobile', 'email', 'fax', 'zip'
                       ])
     for key, vals in address.items():
         res_vals.append([key, vals])
     return res_vals
コード例 #32
0
 def UpdateControl_FromValue(self):
     from manager import ustr
     combo = self.GetControl()
     conn = self.func()
     win32gui.SendMessage(combo, win32con.CB_RESETCONTENT,0, 0);
     id_list = {}
     list=[]
     try:
         list = conn.GetPartners()
         cnt=0
         for item in list:
             win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, ustr(item[1]).encode('iso-8859-1'))
             id_list[cnt] = item[0]
             cnt+=1
         conn.setitem('partner_id_list', str(id_list))
         cnt = win32gui.SendMessage(combo, win32con.CB_GETCOUNT, 0, 0)
         win32gui.SendMessage(combo, win32con.CB_SETCURSEL, cnt-1, 0)
         return
     except xmlrpclib.Fault,e:
          msg = str(e.faultCode) or e.faultString or e.message or str(e)
コード例 #33
0
 def UpdateControl_FromValue(self):
     from manager import ustr
     combo = self.GetControl()
     conn = self.func()
     win32gui.SendMessage(combo, win32con.CB_RESETCONTENT, 0, 0)
     id_list = {}
     list = []
     try:
         list = conn.GetPartners()
         cnt = 0
         for item in list:
             win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0,
                                  ustr(item[1]).encode('iso-8859-1'))
             id_list[cnt] = item[0]
             cnt += 1
         conn.setitem('partner_id_list', str(id_list))
         cnt = win32gui.SendMessage(combo, win32con.CB_GETCOUNT, 0, 0)
         win32gui.SendMessage(combo, win32con.CB_SETCURSEL, cnt - 1, 0)
         return
     except xmlrpclib.Fault, e:
         msg = str(e.faultCode) or e.faultString or e.message or str(e)
コード例 #34
0
 def WritePartnerValues(self, new_vals):
     import win32ui
     flag = -1
     new_dict = dict(new_vals)
     email = new_dict['email']
     conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/object')
     address_id = execute(conn, 'execute', self._dbname, int(self._uid),
                          self._pwd, 'res.partner.address', 'search',
                          [('email', '=', ustr(email))])
     if not address_id:
         return flag
     address = execute(conn, 'execute', self._dbname, int(self._uid),
                       self._pwd, 'res.partner.address', 'read',
                       address_id[0],
                       ['id', 'partner_id', 'state_id', 'country_id'])
     vals_res_address = {
         'name': new_dict['name'],
         'street': new_dict['street'],
         'street2': new_dict['street2'],
         'city': new_dict['city'],
         'phone': new_dict['phone'],
         'mobile': new_dict['mobile'],
         'fax': new_dict['fax'],
         'zip': new_dict['zip'],
     }
     if new_dict['partner_id'] != -1:
         vals_res_address['partner_id'] = new_dict['partner_id']
     if new_dict['state_id'] != -1:
         vals_res_address['state_id'] = new_dict['state_id']
     if new_dict['country_id'] != -1:
         vals_res_address['country_id'] = new_dict['country_id']
     temp = execute(conn, 'execute', self._dbname, int(self._uid),
                    self._pwd, 'res.partner.address', 'write', address_id,
                    vals_res_address)
     if temp:
         flag = 1
     else:
         flag = 0
     return flag
コード例 #35
0
 def CreateCase(self, section, mail, partner_ids, with_attachments=True):
 	import eml
 	flag = False
 	id = -1
 	try:
         conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
         email, path = eml.generateEML(mail)
         message_id   = None
         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)
         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
         else:
         	flag = False
         	return flag
     except Exception,e:
 		win32ui.MessageBox("Create Case\n"+str(e),"Mail Reading Error")
 		return flag
コード例 #36
0
 def SearchPartnerDetail(self, search_email_id):
     import win32ui
     res_vals = []
     address = {}
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     address_id = execute(conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'search', [('email','ilike',ustr(search_email_id))])
     if not address_id :
         return
     address = execute(conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address','read',address_id[0],['id','partner_id','name','street','street2','city','state_id','country_id','phone','mobile','email','fax','zip'])
     for key, vals in address.items():
         res_vals.append([key,vals])
     return res_vals
コード例 #37
0
 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.sort(reverse=True)
コード例 #38
0
 def GetCSList(self):
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     ids = execute(conn,'execute',self._dbname,int(int(self._uid)),self._pwd,'crm.case.section','search',[])
     objects = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'crm.case.section','read',ids,['name'])
     obj_list = [ustr(item['name']).encode('iso-8859-1') for item in objects]
     return obj_list
コード例 #39
0
 def SearchPartner(self, mail_id = ""):
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'search', [('email','=',ustr(mail_id))])
     if not address:
     	return False
     add_rec = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'read', address[0])
     partner = add_rec.get('partner_id',False)
     if partner:  return partner[0]
     else:  return partner
コード例 #40
0
def generateEML(mail):
    sub = (mail.Subject).replace(' ', '')
    body = mail.Body.encode("utf-8")
    recipients = mail.Recipients
    sender_email = mail.SenderEmailAddress
    sender_name = mail.SenderName
    attachments = mail.Attachments
    #    to = mail.To
    #    cc = mail.CC
    #    rec_date = mail.ReceivedTime

    email = chilkat.CkEmail()
    email.put_Subject(ustr(sub).encode('iso-8859-1'))
    email.put_Body(ustr(body).encode('utf-8'))
    email.put_FromAddress(ustr(sender_email).encode('iso-8859-1'))
    email.put_From(ustr(sender_name).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count + 1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        email.AddTo(name, address)

#    email.AddMultipleTo(to)
#    email.AddMultipleCC(cc)
#    win32ui.MessageBox("cccc---"+str(dir(cc)),'')
#    for i in xrange(1, cc.Count+1):
#        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
#        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
#        email.AddCC(name,address)

    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\\")
    if not os.path.exists(attachments_folder_path):
        os.makedirs(attachments_folder_path)
    for i in xrange(1, attachments.Count + 1):
        fn = eml_name + '-' + ustr(
            attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c, '')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        f1 = att_file
        attachments[i].SaveAsFile(att_file)
        contentType = email.addFileAttachment(att_file)
        if (contentType == None):
            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:
        eml_name = eml_name.replace(c, '')
    if len(eml_name) > 64:
        l = 64 - len(eml_name)
        f = eml_name.split('-')
        eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,
                                 eml_name + ".eml")).encode('iso-8859-1')
    success = email.SaveEml(eml_path)
    if (success == False):
        print email.lastErrorText()
        sys.exit()

    print "Saved EML!", eml_path
    return eml_path
コード例 #41
0
ファイル: eml.py プロジェクト: Sk1f161/ERP
def generateEML(mail):
    sub = (mail.Subject).replace(' ','')
    body = mail.Body.encode("utf-8")
    recipients = mail.Recipients
    sender_email = mail.SenderEmailAddress
    sender_name = mail.SenderName
    attachments=mail.Attachments
#    to = mail.To
#    cc = mail.CC
#    rec_date = mail.ReceivedTime

    email = chilkat.CkEmail()
    email.put_Subject (ustr(sub).encode('iso-8859-1'))
    email.put_Body (ustr(body).encode('utf-8'))
    email.put_FromAddress (ustr(sender_email).encode('iso-8859-1'))
    email.put_From (ustr(sender_name).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count+1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        email.AddTo(name,address)

#    email.AddMultipleTo(to)
#    email.AddMultipleCC(cc)
#    win32ui.MessageBox("cccc---"+str(dir(cc)),'')
#    for i in xrange(1, cc.Count+1):
#        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
#        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
#        email.AddCC(name,address)

    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\\")
    if not os.path.exists(attachments_folder_path):
        os.makedirs(attachments_folder_path)
    for i in xrange(1, attachments.Count+1):
        fn = eml_name + '-' + ustr(attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c,'')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        f1  = att_file
        attachments[i].SaveAsFile(att_file)
        contentType = email.addFileAttachment(att_file)
        if (contentType == None ):
            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:
        eml_name = eml_name.replace(c,'')
    if len(eml_name) > 64:
       l = 64 - len(eml_name)
       f = eml_name.split('-')
       eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,eml_name+".eml")).encode('iso-8859-1')
    success = email.SaveEml(eml_path)
    if (success == False):
        print email.lastErrorText()
        sys.exit()

    print "Saved EML!",eml_path
    return eml_path
コード例 #42
0
ファイル: eml.py プロジェクト: lbiemans/docker
def generateEML(mail):
    sub = (mail.Subject).replace(' ','')
    body = mail.Body.encode("utf-8")
    recipients = mail.Recipients
    sender_email = mail.SenderEmailAddress
    attachments=mail.Attachments

    cemail = chilkat.CkEmail()
    cemail.put_Subject (ustr(sub).encode('iso-8859-1'))
    cemail.put_Body (ustr(body).encode('utf-8'))
    cemail.put_FromAddress (ustr(sender_email).encode('iso-8859-1'))
    cemail.put_From (ustr(sender_email).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count+1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        cemail.AddTo(name,address)

    eml_name= ustr(sub).encode('iso-8859-1')+'-'+str(mail.EntryID)[-9:]
    ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|', '\t', '\n']
    mails_folder_path = os.path.abspath("%temp%\\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):
        fn = eml_name + '-' + ustr(attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c,'')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        attachments[i].SaveAsFile(att_file)
        contentType = cemail.addFileAttachment(att_file)
        if (contentType == None ):
            print mail.lastErrorText()
            sys.exit()


    if not os.path.exists(mails_folder_path):
        os.makedirs(mails_folder_path)
    for c in ls:
        eml_name = eml_name.replace(c,'')
    if len(eml_name) > 64:
       l = 64 - len(eml_name)
       f = eml_name.split('-')
       eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,eml_name+".eml")).encode('iso-8859-1')
    success = cemail.SaveEml(eml_path)
    fp = open(eml_path, 'rb')
    new_mail = email.message_from_file(fp)
    fp.close()
    if (success == False):
        print cemail.lastErrorText()
        sys.exit()
    return new_mail, eml_path
コード例 #43
0
class XMLRpcConn(object):
    __name__ = 'XMLRpcConn'
    _com_interfaces_ = ['_IDTExtensibility2']
    _public_methods_ = ['GetDBList', 'login', 'GetAllObjects', 'GetObjList', 'InsertObj', 'DeleteObject', 'GetCSList', \
    'ArchiveToOpenERP', 'IsCRMInstalled', 'GetPartners', 'GetObjectItems', \
    'CreateCase', 'MakeAttachment', 'CreateContact', 'CreatePartner', 'getitem', 'setitem', \
    'SearchPartnerDetail', 'WritePartnerValues', 'GetAllState', 'GetAllCountry', 'SearchPartner', 'SearchEmailResources', \
    'GetCountry', 'GetStates', 'FindCountryForState','CreateEmailAttachment','SearchPartners']
    _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER
    _reg_clsid_ = "{C6399AFD-763A-400F-8191-7F9D0503CAE2}"
    _reg_progid_ = "Python.OpenERP.XMLRpcConn"
    _reg_policy_spec_ = "win32com.server.policy.EventHandlerPolicy"
    def __init__(self,server='localhost',port=8069,uri='http://localhost:8069',webserver='localhost', webport=8080):
        self._server=server
        self._port=port
        self._uri=uri
        self._webserver=webserver
        self._webport=webport
        self._obj_list=[]
        self._dbname=''
        self._uname='admin'
        self._pwd='a'
        self._login=False
        self._running=False
        self._uid=False
        self._iscrm=True
        self.partner_id_list=None
        self.protocol=None
        self._webprotocol=None
        self._weburi=None

    def getitem(self, attrib):
        v=self.__getattribute__(attrib)
        return str(v)

    def setitem(self, attrib, value):
    	return self.__setattr__(attrib, value)

    def GetDBList(self):
        conn = xmlrpclib.ServerProxy(self._uri + '/xmlrpc/db')
        try:
            db_list = execute(conn, 'list')
            if db_list == False:
                self._running=False
                return []
            else:
                self._running=True
        except:
            db_list=-1
            self._running=True
        return db_list

    def login(self,dbname, user, pwd):
        self._dbname = dbname
        self._uname = user
        self._pwd = pwd
        conn = xmlrpclib.ServerProxy(str(self._uri) + '/xmlrpc/common')
        try:
            uid = execute(conn,'login',dbname, ustr(user), ustr(pwd))
        except:
            return False
        return uid

    def GetAllObjects(self):
        conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
        ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','search',[])
        objects = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'ir.model','read',ids,['model'])
        obj_list = [item['model'] for item in objects]
        return obj_list

    def GetObjList(self):
    	self._obj_list=list(self._obj_list)
    	self._obj_list.sort(reverse=True)
    	return self._obj_list

    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)))
    	self._obj_list.sort(reverse=True)

    def DeleteObject(self,sel_text):
    	self._obj_list=list(self._obj_list)
    	for obj in self._obj_list:
    		if obj[0] == sel_text:
    			self._obj_list.remove(obj)
    			break

    def ArchiveToOpenERP(self, recs, mail):
    	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]
    	except Exception,e:
    		win32ui.MessageBox(str(e),"Archive To OpenERP")
    		return
    	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:
                self.CreateEmailAttachment(rec,mail)
            result = {}
            if attachments:
            	result = self.MakeAttachment([rec], mail)
            attachment_ids = result.get(model, {}).get(res_id, [])
            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
    		t += "\n"+new_msg
    		win32ui.MessageBox(t,"Archived to OpenERP",win32con.MB_ICONINFORMATION)
    	return flag
コード例 #44
0
 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.sort(reverse=True)
コード例 #45
0
 def FindCountryForState(self, state_search=''):
 	conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
 	ids = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.country.state','search',[('name','=',ustr(state_search))])
 	if not ids:
 		return None
 	object = execute(conn,'execute',self._dbname,int(self._uid),self._pwd,'res.country.state','read',ids)[0]
 	country = object['country_id'][1]
 	return country
コード例 #46
0
 def WritePartnerValues(self, new_vals):
     import win32ui
     flag = -1
     new_dict = dict(new_vals)
     email=new_dict['email']
     conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
     address_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'search', [('email','=',ustr(email))])
     if not address_id:
         return flag
     address = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address','read',address_id[0],['id','partner_id','state_id','country_id'])
     vals_res_address={ 'name' : new_dict['name'],
                        'street':new_dict['street'],
                        'street2' : new_dict['street2'],
                        'city' : new_dict['city'],
                        'phone' : new_dict['phone'],
                        'mobile' : new_dict['mobile'],
                        'fax' : new_dict['fax'],
                        'zip' : new_dict['zip'],
                      }
     if new_dict['partner_id'] != -1:
         vals_res_address['partner_id'] = new_dict['partner_id']
     if new_dict['state_id'] != -1:
         vals_res_address['state_id'] = new_dict['state_id']
     if new_dict['country_id'] != -1:
         vals_res_address['country_id'] = new_dict['country_id']
     temp = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'write', address_id, vals_res_address)
     if temp:
         flag=1
     else:
         flag=0
     return flag
コード例 #47
0
 def WritePartnerValues(self, new_vals):
 	flag = -1
 	new_dict = dict(new_vals)
 	email=new_dict['email']
 	partner = new_dict['partner']
 	country_val = new_dict['country']
 	state_val = new_dict['state']
 	conn = xmlrpclib.ServerProxy(self._uri+ '/xmlrpc/object')
 	partner_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner', 'search', [('name','=',ustr(partner))])
 	country_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country', 'search', [('name','=',ustr(country_val))])
 	state_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.country.state', 'search', [('name','=',ustr(state_val))])
 	address_id = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'search', [('email','=',ustr(email))])
 	if not partner_id or not address_id or not country_id or not state_id:
 		return flag
 	vals_res_address={
 					   'partner_id' : partner_id[0],
 					   'name' : new_dict['name'],
 					   'street':new_dict['street'],
 					   'street2' : new_dict['street2'],
 					   'city' : new_dict['city'],
 					   'phone' : new_dict['phone'],
 					   'mobile' : new_dict['mobile'],
 					   'fax' : new_dict['fax'],
 					   'zip' : new_dict['zip'],
 					   'country_id' : country_id[0],
 					   'state_id' : state_id[0]
 					 }
 	temp = execute( conn, 'execute', self._dbname, int(self._uid), self._pwd, 'res.partner.address', 'write', address_id, vals_res_address)
 	if temp:
 		flag=1
 	else:
 		flag=0
 	return flag