diff --git a/addons/crm/__terp__.py b/addons/crm/__terp__.py index 332a592431c..22010efe368 100644 --- a/addons/crm/__terp__.py +++ b/addons/crm/__terp__.py @@ -46,7 +46,8 @@ between mails and Open ERP.""", 'website': 'http://www.openerp.com', 'depends': ['base', 'caldav', - 'process' + 'process', + 'mail_gateway', ], 'init_xml': ['crm_data.xml', 'crm_meeting_data.xml', diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 13514afd3b2..f2172aa37be 100755 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -32,7 +32,7 @@ import tools from osv import fields,osv,orm from osv.orm import except_orm -from scripts.openerp_mailgate import openerp_mailgate +#from scripts.openerp_mailgate import openerp_mailgate import email import netsvc from poplib import POP3, POP3_SSL @@ -74,7 +74,7 @@ class crm_case_section(osv.osv): 'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by Open ERP about cases in this section"), 'parent_id': fields.many2one('crm.case.section', 'Parent Section'), 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Sections'), - "gateway_ids" : fields.one2many("crm.email.gateway",'section_id',"Email Gateways"), + "gateway_ids" : fields.one2many("mail.gateway",'section_id',"Email Gateways"), 'calendar' : fields.boolean('Calendar', help='Allows to show calendar'), } _defaults = { @@ -209,147 +209,14 @@ class crm_case_section(osv.osv): return res crm_case_section() -class crm_email_gateway_server(osv.osv): - _name = "crm.email.gateway.server" - _description = "Email Gateway Server" - _columns = { - 'name': fields.char('Server Address',size=64,required=True ,help="IMAP/POP Address Of Email gateway Server"), - 'login': fields.char('User',size=64,required=True,help="User Login Id of Email gateway"), - 'password': fields.char('Password',size=64,required=True,help="User Password Of Email gateway"), - 'server_type': fields.selection([("pop","POP"),("imap","Imap")],"Type of Server", required=True, help="Type of Email gateway Server"), - 'port': fields.integer("Port" , help="Port Of Email gateway Server. If port is omitted, the standard POP3 port (110) is used for POP EMail Server and the standard IMAP4 port (143) is used for IMAP Sever."), - 'ssl': fields.boolean('SSL',help ="Use Secure Authentication"), - 'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the email gateway server without removing it."), - } - _defaults = { - 'server_type':lambda * a:'pop', - 'active':lambda * a:True, - } - def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False): - port = 0 - if server_type == 'pop': - port = ssl and 995 or 110 - elif server_type == 'imap': - port = ssl and 993 or 143 - return {'value':{'port':port}} -crm_email_gateway_server() - - - -class crm_email_gateway(osv.osv): - _name = "crm.email.gateway" +class mail_gateway(osv.osv): + _inherit = "mail.gateway" _description = "Email Gateway" _columns = { - 'name': fields.char('Name',size=64,help="Name of Mail Gateway."), - 'server_id': fields.many2one('crm.email.gateway.server',"Gateway Server", required=True), - 'to_email_id': fields.char('TO', size=64, help="Email address used in the From field of outgoing messages"), - 'cc_email_id': fields.char('CC',size=64,help="Default eMail in case of any trouble."), - 'section_id': fields.many2one('crm.case.section',"Section",required=True), - 'mail_history': fields.one2many("crm.email.history","gateway_id","History", readonly=True) + 'section_id': fields.many2one('crm.case.section',"Section",required=True), } - - def _fetch_mails(self, cr, uid, ids=False, context={}): - ''' - Function called by the scheduler to fetch mails - ''' - cr.execute('select * from crm_email_gateway gateway \ - inner join crm_email_gateway_server server \ - on server.id = gateway.server_id where server.active = True') - ids2 = map(lambda x: x[0], cr.fetchall() or []) - return self.fetch_mails(cr, uid, ids=ids2, context=context) - - def parse_mail(self, cr, uid, gateway_id, email_message, email_parser=None, context={}): - msg_id = case_id = note = False - user_obj = self.pool.get('res.users') - mail_history_obj = self.pool.get('crm.email.history') - users = user_obj.read(cr, uid, uid, ['password']) - mailgateway = self.browse(cr, uid, gateway_id, context=context) - try : - if not email_parser: - email_parser = openerp_mailgate.email_parser(uid, users['password'], mailgateway.section_id.id, - mailgateway.to_email_id or '', mailgateway.cc_email_id or '', dbname=cr.dbname, - host=tools.config['interface'] or 'localhost', port=tools.config['port'] or '8069') - - msg_txt = email.message_from_string(email_message) - msg_id = msg_txt['Message-ID'] - case_id = email_parser.parse(msg_txt)[0] - except Exception, e: - note = "Error in Parsing Mail: %s " %(str(e)) - netsvc.Logger().notifyChannel('Emailgate:Parsing mail:%s' % (mailgateway.name or - '%s (%s)'%(mailgateway.server_id.login, mailgateway.server_id.name)), netsvc.LOG_ERROR, str(e)) - - mail_history_obj.create(cr, uid, {'name':msg_id, 'case_id': case_id, 'gateway_id':mailgateway.id, 'note':note}) - return case_id,note - - def fetch_mails(self, cr, uid, ids=[], section_ids=[], context={}): - if len(section_ids): - casesection_obj = self.pool.get('crm.case.section') - for section in casesection_obj.read(cr, uid, section_ids, ['gateway_ids']): - ids += section['gateway_ids'] - log_messages = [] - for mailgateway in self.browse(cr, uid, ids): - try : - mailgate_server = mailgateway.server_id - if not mailgate_server.active: - continue - mailgate_name = mailgateway.name or "%s (%s)" % (mailgate_server.login, mailgate_server.name) - log_messages.append("Mail Server : %s" % mailgate_name) - log_messages.append("="*40) - new_messages = [] - if mailgate_server.server_type == 'pop': - if mailgate_server.ssl: - pop_server = POP3_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 110) - else: - pop_server = POP3(mailgate_server.name or 'localhost', mailgate_server.port or 110) - pop_server.user(mailgate_server.login) - pop_server.pass_(mailgate_server.password) - pop_server.list() - (numMsgs, totalSize) = pop_server.stat() - for i in range(1, numMsgs + 1): - (header, msges, octets) = pop_server.retr(i) - case_id, note = self.parse_mail(cr, uid, mailgateway.id, '\n'.join(msges)) - log = '' - if case_id: - log = _('Case Successfull Created : %d'% case_id) - if note: - log = note - log_messages.append(log) - new_messages.append(i) - pop_server.quit() - - elif mailgate_server.server_type == 'imap': - if mailgate_server.ssl: - imap_server = IMAP4_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 143) - else: - imap_server = IMAP4(mailgate_server.name or 'localhost', mailgate_server.port or 143) - imap_server.login(mailgate_server.login, mailgate_server.password) - imap_server.select() - typ, data = imap_server.search(None, '(UNSEEN)') - for num in data[0].split(): - typ, data = imap_server.fetch(num, '(RFC822)') - case_id, note = self.parse_mail(cr, uid, mailgateway.id, data[0][1]) - log = '' - if case_id: - log = 'Case Successfully Created : %d'% case_id - if note: - log = note - log_messages.append(log) - new_messages.append(num) - imap_server.close() - imap_server.logout() - - except Exception, e: - log_messages.append("Error in Fetching Mail: %s " %(str(e))) - netsvc.Logger().notifyChannel('Emailgate:Fetching mail:[%d]%s' % (mailgate_server.id, mailgate_server.name), netsvc.LOG_ERROR, str(e)) - - log_messages.append("-"*25) - log_messages.append("Total Read Mail: %d\n\n" %(len(new_messages))) - return log_messages - -crm_email_gateway() - - +mail_gateway() class crm_case_categ(osv.osv): _name = "crm.case.categ" @@ -1040,19 +907,6 @@ class crm_case_history(osv.osv): } crm_case_history() -class crm_email_history(osv.osv): - _name = "crm.email.history" - _description = "Email History" - _columns = { - 'name': fields.char('Message Id', size=64, help="Message Id in Email Server."), - 'case_id': fields.many2one('crm.case',"Case"), - 'gateway_id': fields.many2one('crm.email.gateway',"Email Gateway", required=True), - 'note': fields.text('Notes'), - } - _order = 'id desc' -crm_email_history() - - class crm_email_add_cc_wizard(osv.osv_memory): _name = "crm.email.add.cc" _description = "Email Add CC" diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index 985520ed113..9671cf45115 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -42,8 +42,8 @@ - - + + @@ -56,12 +56,10 @@ -
- @@ -649,89 +647,5 @@ - - - crm.email.gateway.form - crm.email.gateway - form - -
- - - - - - - - - - - - - - - - - - - - -
- - - crm.email.gateway.tree - crm.email.gateway - tree - - - - - - - - - - - crm.email.gateway.server.form - crm.email.gateway.server - form - -
- - - - - - - - - - -
- - - crm.email.gateway.server.tree - crm.email.gateway.server - tree - - - - - - - - - - - - - Email Gateway - crm.email.gateway - form - tree,form - - - - diff --git a/addons/crm/crm_wizard.xml b/addons/crm/crm_wizard.xml index 7950d74e53e..2d52767afdc 100644 --- a/addons/crm/crm_wizard.xml +++ b/addons/crm/crm_wizard.xml @@ -8,11 +8,5 @@ name="crm.case.section.fetchmail" id="wizard_crm_case_section_fetchmail"/> - - - diff --git a/addons/crm/security/ir.model.access.csv b/addons/crm/security/ir.model.access.csv index cb1cc46f9e8..ec1efbb18d2 100644 --- a/addons/crm/security/ir.model.access.csv +++ b/addons/crm/security/ir.model.access.csv @@ -13,12 +13,6 @@ "access_crm_case_rule_manager","crm.case.rule.manager","model_crm_case_rule","crm.group_crm_manager",1,1,1,1 "access_crm_case_log_manager","crm.case.log manager","model_crm_case_log","crm.group_crm_manager",1,1,1,1 "access_crm_case_history_manager","crm.case.history manager","model_crm_case_history","crm.group_crm_manager",1,1,1,1 -"access_crm_email_gateway_server_manager","crm.email.gateway.server","model_crm_email_gateway_server","crm.group_crm_manager",1,1,1,1 -"access_crm_email_gateway_server_user","crm.email.gateway.server","model_crm_email_gateway_server","crm.group_crm_user",1,0,0,0 -"access_crm_email_gateway_manager","crm.email.gateway","model_crm_email_gateway","crm.group_crm_manager",1,1,1,1 -"access_crm_email_gateway_user","crm.email.gateway","model_crm_email_gateway","crm.group_crm_user",1,0,0,0 -"access_crm_email_history_manager","crm.email.history","model_crm_email_history","crm.group_crm_manager",1,1,1,1 -"access_crm_email_history_user","crm.email.history","model_crm_email_history","crm.group_crm_user",1,0,0,0 "access_crm_email_add_cc_manager","crm.email.add.cc","model_crm_email_add_cc","crm.group_crm_manager",1,1,1,1 "access_crm_email_add_cc_user","crm.email.add.cc","model_crm_email_add_cc","crm.group_crm_user",1,0,0,0 "access_crm_case_stage","crm.case.stage","model_crm_case_stage","crm.group_crm_user",1,0,0,0 diff --git a/addons/crm/wizard/wizard_fetch_mail.py b/addons/crm/wizard/wizard_fetch_mail.py index d06c98fe5cf..a7655185005 100644 --- a/addons/crm/wizard/wizard_fetch_mail.py +++ b/addons/crm/wizard/wizard_fetch_mail.py @@ -50,23 +50,16 @@ def _default(self , cr, uid, data, context): gateway_pool=pool.get('crm.case.section') sections = gateway_pool.browse(cr, uid, data['ids'], context=context) server = [] - for section in sections: - for gateway in section.gateway_ids: - if gateway.server_id.active: - server.append(gateway.name or '%s (%s)'%(gateway.server_id.login, gateway.server_id.name) ) +# for section in sections: +# for gateway in section.gateway_ids: +# if gateway.server_id.active: +# server.append(gateway.name or '%s (%s)'%(gateway.server_id.login, gateway.server_id.name) ) data['form']['server'] = '\n'.join(server) return data['form'] def section_fetch_mail(self , cr, uid, data, context): pool = pooler.get_pool(cr.dbname) - gateway_pool=pool.get('crm.email.gateway') - messages = gateway_pool.fetch_mails(cr, uid, ids=[], section_ids=data['ids'], context=context) - data['form']['message'] = '\n'.join(messages) - return data['form'] - -def mailgate_fetch_mail(self , cr, uid, data, context): - pool = pooler.get_pool(cr.dbname) - gateway_pool=pool.get('crm.email.gateway') + gateway_pool=pool.get('mail.gateway') messages = gateway_pool.fetch_mails(cr, uid, ids=data['ids'], context=context) data['form']['message'] = '\n'.join(messages) return data['form'] @@ -87,22 +80,6 @@ class wiz_section_fetch_mail(wizard.interface): }, }, } -class wiz_mailgateway_fetch_mail(wizard.interface): - states = { - 'init': { - 'actions': [], - 'result': {'type': 'form', 'arch':_email_form, 'fields':_email_fields, 'state':[('end','Cancel','gtk-cancel'), ('fetch','Fetch','gtk-execute')]} - }, - 'fetch': { - 'actions': [mailgate_fetch_mail], - 'result': {'type': 'form', 'arch': _email_done_form, - 'fields': _email_done_fields, - 'state': ( - ('end', 'Close'), - ) - }, - }, - } wiz_section_fetch_mail('crm.case.section.fetchmail') -wiz_mailgateway_fetch_mail('crm.case.mailgate.fetchmail') + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail_gateway/__init__.py b/addons/mail_gateway/__init__.py new file mode 100644 index 00000000000..4d8099212bf --- /dev/null +++ b/addons/mail_gateway/__init__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import mailgateway +import wizard + + + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mail_gateway/__terp__.py b/addons/mail_gateway/__terp__.py new file mode 100644 index 00000000000..2c977637e3c --- /dev/null +++ b/addons/mail_gateway/__terp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'EMail Gateway', + 'version': '1.0', + 'category': 'Generic Modules/Mail Gate', + 'description': """The generic email gateway system for the synchronisation interface +between mails and Open ERP. +""", + 'author': 'Tiny', + 'website': 'http://www.openerp.com', + 'depends': ['base', 'process'], + 'init_xml': [], + 'update_xml': [ + 'mailgateway_wizard.xml', + 'mailgateway_view.xml', + 'security/ir.model.access.csv', + ], + 'demo_xml': [], + 'installable': True, + 'active': False, + 'certificate': None, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail_gateway/mailgateway.py b/addons/mail_gateway/mailgateway.py new file mode 100644 index 00000000000..c2b679d16fe --- /dev/null +++ b/addons/mail_gateway/mailgateway.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +from tools.translate import _ + +import tools +from osv import fields,osv,orm +from osv.orm import except_orm + +from scripts.openerp_mailgate import openerp_mailgate +import email +import netsvc +from poplib import POP3, POP3_SSL +from imaplib import IMAP4, IMAP4_SSL + + + +class mail_gateway_server(osv.osv): + _name = "mail.gateway.server" + _description = "Email Gateway Server" + _columns = { + 'name': fields.char('Server Address',size=64,required=True ,help="IMAP/POP Address Of Email gateway Server"), + 'login': fields.char('User',size=64,required=True,help="User Login Id of Email gateway"), + 'password': fields.char('Password',size=64,required=True,help="User Password Of Email gateway"), + 'server_type': fields.selection([("pop","POP"),("imap","Imap")],"Type of Server", required=True, help="Type of Email gateway Server"), + 'port': fields.integer("Port" , help="Port Of Email gateway Server. If port is omitted, the standard POP3 port (110) is used for POP EMail Server and the standard IMAP4 port (143) is used for IMAP Sever."), + 'ssl': fields.boolean('SSL',help ="Use Secure Authentication"), + 'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the email gateway server without removing it."), + } + _defaults = { + 'server_type':lambda * a:'pop', + 'active':lambda * a:True, + } + def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False): + port = 0 + if server_type == 'pop': + port = ssl and 995 or 110 + elif server_type == 'imap': + port = ssl and 993 or 143 + return {'value':{'port':port}} +mail_gateway_server() + +class mail_gateway(osv.osv): + _name = "mail.gateway" + _description = "Email Gateway" + + _columns = { + 'name': fields.char('Name',size=64,help="Name of Mail Gateway."), + 'server_id': fields.many2one('mail.gateway.server',"Gateway Server", required=True), + 'to_email_id': fields.char('TO', size=64, help="Email address used in the From field of outgoing messages"), + 'cc_email_id': fields.char('CC',size=64,help="Default eMail in case of any trouble."), + 'mail_history': fields.one2many("mail.gateway.history","gateway_id","History", readonly=True) + } + + def _fetch_mails(self, cr, uid, ids=False, context={}): + ''' + Function called by the scheduler to fetch mails + ''' + cr.execute('select * from mail_gateway gateway \ + inner join mail_gateway_server server \ + on server.id = gateway.server_id where server.active = True') + ids2 = map(lambda x: x[0], cr.fetchall() or []) + return self.fetch_mails(cr, uid, ids=ids2, context=context) + + def parse_mail(self, cr, uid, gateway_id, email_message, email_parser=None, context={}): + msg_id = case_id = note = False + user_obj = self.pool.get('res.users') + mail_history_obj = self.pool.get('mail.gateway.history') + users = user_obj.read(cr, uid, uid, ['password']) + mailgateway = self.browse(cr, uid, gateway_id, context=context) + try : + if not email_parser: + email_parser = openerp_mailgate.email_parser(uid, users['password'], + mailgateway.to_email_id or '', mailgateway.cc_email_id or '', dbname=cr.dbname, + host=tools.config['interface'] or 'localhost', port=tools.config['port'] or '8069') + + msg_txt = email.message_from_string(email_message) + msg_id = msg_txt['Message-ID'] + res_id = email_parser.parse(msg_txt)[0] + res_model = False + except Exception, e: + note = "Error in Parsing Mail: %s " %(str(e)) + netsvc.Logger().notifyChannel('Emailgate: Parsing mail:%s' % (mailgateway.name or + '%s (%s)'%(mailgateway.server_id.login, mailgateway.server_id.name)), netsvc.LOG_ERROR, str(e)) + + mail_history_obj.create(cr, uid, {'name':msg_id, 'res_id': res_id, 'res_model': res_model,'gateway_id':mailgateway.id, 'note':note}) + return res_id, res_model, note + + def fetch_mails(self, cr, uid, ids=[], context={}): + log_messages = [] + for mailgateway in self.browse(cr, uid, ids): + try : + mailgate_server = mailgateway.server_id + if not mailgate_server.active: + continue + mailgate_name = mailgateway.name or "%s (%s)" % (mailgate_server.login, mailgate_server.name) + log_messages.append("Mail Server : %s" % mailgate_name) + log_messages.append("="*40) + new_messages = [] + if mailgate_server.server_type == 'pop': + if mailgate_server.ssl: + pop_server = POP3_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 995) + else: + pop_server = POP3(mailgate_server.name or 'localhost', mailgate_server.port or 110) + pop_server.user(mailgate_server.login) + pop_server.pass_(mailgate_server.password) + pop_server.list() + (numMsgs, totalSize) = pop_server.stat() + for i in range(1, numMsgs + 1): + (header, msges, octets) = pop_server.retr(i) + res_id, res_model, note = self.parse_mail(cr, uid, mailgateway.id, '\n'.join(msges)) + log = '' + if res_id: + log = _('Object Successfully Created : %d of %s'% (res_id, res_model)) + if note: + log = note + log_messages.append(log) + new_messages.append(i) + pop_server.quit() + + elif mailgate_server.server_type == 'imap': + if mailgate_server.ssl: + imap_server = IMAP4_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 993) + else: + imap_server = IMAP4(mailgate_server.name or 'localhost', mailgate_server.port or 143) + imap_server.login(mailgate_server.login, mailgate_server.password) + imap_server.select() + typ, data = imap_server.search(None, '(UNSEEN)') + for num in data[0].split(): + typ, data = imap_server.fetch(num, '(RFC822)') + res_id, res_model, note = self.parse_mail(cr, uid, mailgateway.id, data[0][1]) + log = '' + if res_id: + log = _('Object Successfully Created : %d of %s'% (res_id, res_model)) + if note: + log = note + log_messages.append(log) + new_messages.append(num) + imap_server.close() + imap_server.logout() + + except Exception, e: + log_messages.append("Error in Fetching Mail: %s " %(str(e))) + netsvc.Logger().notifyChannel('Emailgate: Fetching mail:[%d]%s' % (mailgate_server.id, mailgate_server.name), netsvc.LOG_ERROR, str(e)) + + log_messages.append("-"*25) + log_messages.append("Total Read Mail: %d\n\n" %(len(new_messages))) + return log_messages + +mail_gateway() + +class mail_gateway_history(osv.osv): + _name = "mail.gateway.history" + _description = "Mail Gateway History" + _columns = { + 'name': fields.char('Message Id', size=64, help="Message Id in Email Server."), + 'res_id': fields.integer("Resource ID"), + 'res_model': fields.many2one('ir.model',"Model"), + 'gateway_id': fields.many2one('mail.gateway',"Mail Gateway", required=True), + 'note': fields.text('Notes'), + } + _order = 'id desc' +mail_gateway_history() +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mail_gateway/mailgateway_view.xml b/addons/mail_gateway/mailgateway_view.xml new file mode 100644 index 00000000000..4dc97524913 --- /dev/null +++ b/addons/mail_gateway/mailgateway_view.xml @@ -0,0 +1,87 @@ + + + + + mail.gateway.form + mail.gateway + form + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + mail.gateway.tree + mail.gateway + tree + + + + + + + + + + mail.gateway.server.form + mail.gateway.server + form + +
+ + + + + + + + + +
+ + + mail.gateway.server.tree + mail.gateway.server + tree + + + + + + + + + + + + Email Gateway + mail.gateway + form + tree,form + + + + + +
+
diff --git a/addons/mail_gateway/mailgateway_wizard.xml b/addons/mail_gateway/mailgateway_wizard.xml new file mode 100644 index 00000000000..eb862116f58 --- /dev/null +++ b/addons/mail_gateway/mailgateway_wizard.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/addons/crm/scripts/__init__.py b/addons/mail_gateway/scripts/__init__.py similarity index 100% rename from addons/crm/scripts/__init__.py rename to addons/mail_gateway/scripts/__init__.py diff --git a/addons/crm/scripts/openerp_mailgate/__init__.py b/addons/mail_gateway/scripts/openerp_mailgate/__init__.py similarity index 100% rename from addons/crm/scripts/openerp_mailgate/__init__.py rename to addons/mail_gateway/scripts/openerp_mailgate/__init__.py diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py old mode 100755 new mode 100644 similarity index 96% rename from addons/crm/scripts/openerp_mailgate/openerp_mailgate.py rename to addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py index d2c996ce223..a5c74c7fac7 --- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py @@ -135,12 +135,8 @@ class rpc_proxy(object): return self.rpc.execute(self.dbname, self.user_id, self.passwd, *request) class email_parser(object): - def __init__(self, uid, password, section, email, email_default, dbname, host, port): + def __init__(self, uid, password, email, email_default, dbname, host, port): self.rpc = rpc_proxy(uid, password, host=host, port=port, dbname=dbname) - try: - self.section_id = int(section) - except: - self.section_id = self.rpc('crm.case.section', 'search', [('code','=',section)])[0] self.email = email self.email_default = email_default self.canal_id = False @@ -169,7 +165,6 @@ class email_parser(object): message = self.msg_body_get(msg) data = { 'name': self._decode_header(msg['Subject']), - 'section_id': self.section_id, 'email_from': self._decode_header(msg['From']), 'email_cc': self._decode_header(msg['Cc'] or ''), 'canal_id': self.canal_id, @@ -205,16 +200,6 @@ class email_parser(object): return id -# #change the return type format to dictionary -# { -# 'body':'body part', -# 'attachment':{ -# 'file_name':'file data', -# 'file_name':'file data', -# 'file_name':'file data', -# } -# } -# # def msg_body_get(self, msg): message = {}; message['body'] = ''; diff --git a/addons/mail_gateway/security/ir.model.access.csv b/addons/mail_gateway/security/ir.model.access.csv new file mode 100644 index 00000000000..996147308f6 --- /dev/null +++ b/addons/mail_gateway/security/ir.model.access.csv @@ -0,0 +1,4 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" + + + diff --git a/addons/mail_gateway/wizard/__init__.py b/addons/mail_gateway/wizard/__init__.py new file mode 100644 index 00000000000..4ae407fe1b7 --- /dev/null +++ b/addons/mail_gateway/wizard/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import wizard_fetch_mail + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mail_gateway/wizard/wizard_fetch_mail.py b/addons/mail_gateway/wizard/wizard_fetch_mail.py new file mode 100644 index 00000000000..a36dd702d22 --- /dev/null +++ b/addons/mail_gateway/wizard/wizard_fetch_mail.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## +import wizard +import time +import pooler +import tools +import os +_email_form = ''' +
+ + + ''' + +_email_done_form = ''' +
+ + + + ''' + +_email_fields = { + 'server': {'string':"Server", 'type':'text', 'readonly':True}, + } + +_email_done_fields = { + 'message': {'string':"Log Detail", 'type':'text', 'readonly':True}, + } + +def mailgate_fetch_mail(self , cr, uid, data, context): + pool = pooler.get_pool(cr.dbname) + gateway_pool=pool.get('mail.gateway') + messages = gateway_pool.fetch_mails(cr, uid, ids=data['ids'], context=context) + data['form']['message'] = '\n'.join(messages) + return data['form'] + +class wiz_mailgateway_fetch_mail(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type': 'form', 'arch':_email_form, 'fields':_email_fields, 'state':[('end','Cancel','gtk-cancel'), ('fetch','Fetch','gtk-execute')]} + }, + 'fetch': { + 'actions': [mailgate_fetch_mail], + 'result': {'type': 'form', 'arch': _email_done_form, + 'fields': _email_done_fields, + 'state': ( + ('end', 'Close'), + ) + }, + }, + } +wiz_mailgateway_fetch_mail('mailgate.fetchmail') +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: