From e9d546c6d4075e8a632f93a3834e070a434e2a6f Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 21 Dec 2016 12:45:46 +0100 Subject: [PATCH 1/2] Migrate mail_environment to 10.0 --- mail_environment/README.rst | 6 +- mail_environment/__init__.py | 2 +- mail_environment/__manifest__.py | 26 +- mail_environment/env_mail.py | 232 ------------------ mail_environment/mail_view.xml | 24 -- mail_environment/models/__init__.py | 3 + mail_environment/models/fetchmail_server.py | 74 ++++++ mail_environment/models/ir_mail_server.py | 46 ++++ .../views/fetchmail_server_views.xml | 21 ++ 9 files changed, 152 insertions(+), 282 deletions(-) delete mode 100644 mail_environment/env_mail.py delete mode 100644 mail_environment/mail_view.xml create mode 100644 mail_environment/models/__init__.py create mode 100644 mail_environment/models/fetchmail_server.py create mode 100644 mail_environment/models/ir_mail_server.py create mode 100644 mail_environment/views/fetchmail_server_views.xml diff --git a/mail_environment/README.rst b/mail_environment/README.rst index 388ec9ac2..fd0643a28 100644 --- a/mail_environment/README.rst +++ b/mail_environment/README.rst @@ -81,11 +81,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed `feedback -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= diff --git a/mail_environment/__init__.py b/mail_environment/__init__.py index 89dd1478f..a0fdc10fe 100644 --- a/mail_environment/__init__.py +++ b/mail_environment/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -from . import env_mail +from . import models diff --git a/mail_environment/__manifest__.py b/mail_environment/__manifest__.py index 6026bf771..ca9d8e063 100644 --- a/mail_environment/__manifest__.py +++ b/mail_environment/__manifest__.py @@ -1,24 +1,10 @@ # -*- coding: utf-8 -*- -# -# Author: Nicolas Bessi -# Copyright 2012 Camptocamp SA -# -# 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 . +# Copyright 2012-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) { 'name': 'Mail configuration with server_environment', - 'version': '9.0.1.0.0', + 'version': '10.0.1.0.0', 'category': 'Tools', 'summary': 'Configure mail servers with server_environment_files', 'author': "Camptocamp,Odoo Community Association (OCA)", @@ -28,7 +14,7 @@ 'server_environment', 'server_environment_files', ], - 'data': ['mail_view.xml'], - 'installable': False, - 'active': False, + 'data': ['views/fetchmail_server_views.xml', + ], + 'installable': True, } diff --git a/mail_environment/env_mail.py b/mail_environment/env_mail.py deleted file mode 100644 index c4025340a..000000000 --- a/mail_environment/env_mail.py +++ /dev/null @@ -1,232 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Nicolas Bessi -# Copyright 2012 Camptocamp SA -# -# 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 openerp.osv import orm, fields - -from openerp.addons.server_environment import serv_config - - -class IrMail(orm.Model): - _inherit = "ir.mail_server" - - def _get_smtp_conf(self, cr, uid, ids, name, args, context=None): - """ - Return configuration - """ - res = {} - for mail_server in self.browse(cr, uid, ids, context=context): - global_section_name = 'outgoing_mail' - - # default vals - config_vals = {'smtp_port': 587} - if serv_config.has_section(global_section_name): - config_vals.update((serv_config.items(global_section_name))) - - custom_section_name = '.'.join((global_section_name, - mail_server.name)) - if serv_config.has_section(custom_section_name): - config_vals.update(serv_config.items(custom_section_name)) - - if config_vals.get('smtp_port'): - config_vals['smtp_port'] = int(config_vals['smtp_port']) - - res[mail_server.id] = config_vals - return res - - _columns = { - 'smtp_host': fields.function( - _get_smtp_conf, - string='SMTP Server', - type="char", - multi='outgoing_mail_config', - states={'draft': [('readonly', True)]}, - help="Hostname or IP of SMTP server"), - 'smtp_port': fields.function( - _get_smtp_conf, - string='SMTP Port', - type="integer", - multi='outgoing_mail_config', - states={'draft': [('readonly', True)]}, - help="SMTP Port. Usually 465 for SSL, " - "and 25 or 587 for other cases.", - size=5), - 'smtp_user': fields.function( - _get_smtp_conf, - string='Username', - type="char", - multi='outgoing_mail_config', - states={'draft': [('readonly', True)]}, - help="Optional username for SMTP authentication", - size=64), - 'smtp_pass': fields.function( - _get_smtp_conf, - string='Password', - type="char", - multi='outgoing_mail_config', - states={'draft': [('readonly', True)]}, - help="Optional password for SMTP authentication", - size=64), - 'smtp_encryption': fields.function( - _get_smtp_conf, - string='smtp_encryption', - type="selection", - multi='outgoing_mail_config', - selection=[('none', 'None'), - ('starttls', 'TLS (STARTTLS)'), - ('ssl', 'SSL/TLS')], - states={'draft': [('readonly', True)]}, - help="Choose the connection encryption scheme:\n" - "- none: SMTP sessions are done in cleartext.\n" - "- starttls: TLS encryption is requested at start " - "of SMTP session (Recommended)\n" - "- ssl: SMTP sessions are encrypted with SSL/TLS " - "through a dedicated port (default: 465)") - } - - -class FetchmailServer(orm.Model): - """Incoming POP/IMAP mail server account""" - _inherit = 'fetchmail.server' - - def _get_incom_conf(self, cr, uid, ids, name, args, context=None): - """ - Return configuration - """ - res = {} - for fetchmail in self.browse(cr, uid, ids, context=context): - global_section_name = 'incoming_mail' - - key_types = {'port': int, - 'is_ssl': lambda a: bool(int(a)), - 'attach': lambda a: bool(int(a)), - 'original': lambda a: bool(int(a)), - } - - # default vals - config_vals = {'port': 993, - 'is_ssl': 0, - 'attach': 0, - 'original': 0, - } - if serv_config.has_section(global_section_name): - config_vals.update(serv_config.items(global_section_name)) - - custom_section_name = '.'.join((global_section_name, - fetchmail.name)) - if serv_config.has_section(custom_section_name): - config_vals.update(serv_config.items(custom_section_name)) - - for key, to_type in key_types.iteritems(): - if config_vals.get(key): - config_vals[key] = to_type(config_vals[key]) - res[fetchmail.id] = config_vals - return res - - def _type_search(self, cr, uid, obj, name, args, context=None): - result_ids = [] - # read all incoming servers values - all_ids = self.search(cr, uid, [], context=context) - results = self.read(cr, uid, all_ids, ['id', 'type'], context=context) - args = args[:] - i = 0 - while i < len(args): - operator = args[i][1] - if operator == '=': - for res in results: - if (res['type'] == args[i][2] and - res['id'] not in result_ids): - result_ids.append(res['id']) - elif operator == 'in': - for search_vals in args[i][2]: - for res in results: - if (res['type'] == search_vals and - res['id'] not in result_ids): - result_ids.append(res['id']) - else: - continue - i += 1 - return [('id', 'in', result_ids)] - - _columns = { - 'server': fields.function( - _get_incom_conf, - string='Server', - type="char", - multi='income_mail_config', - states={'draft': [('readonly', True)]}, - help="Hostname or IP of the mail server"), - 'port': fields.function( - _get_incom_conf, - string='Port', - type="integer", - states={'draft': [('readonly', True)]}, - multi='income_mail_config'), - 'type': fields.function( - _get_incom_conf, - string='Type', - type="selection", - selection=[('pop', 'POP Server'), - ('imap', 'IMAP Server'), - ('local', 'Local Server'), - ], - multi='income_mail_config', - fnct_search=_type_search, - states={'draft': [('readonly', True)]}, - help="pop, imap, local"), - 'is_ssl': fields.function( - _get_incom_conf, - string='Is SSL', - type="boolean", - multi='income_mail_config', - states={'draft': [('readonly', True)]}, - help='Connections are encrypted with SSL/TLS through' - ' a dedicated port (default: IMAPS=993, POP3S=995)'), - 'attach': fields.function( - _get_incom_conf, - string='Keep Attachments', - type="boolean", - multi='income_mail_config', - states={'draft': [('readonly', True)]}, - help="Whether attachments should be downloaded. " - "If not enabled, incoming emails will be stripped of any " - "attachments before being processed"), - 'original': fields.function( - _get_incom_conf, - string='Keep Original', - type="boolean", - multi='income_mail_config', - states={'draft': [('readonly', True)]}, - help="Whether a full original copy of each email should be kept " - "for reference and attached to each processed message. This " - "will usually double the size of your message database."), - 'user': fields.function( - _get_incom_conf, - string='Username', - type="char", - states={'draft': [('readonly', True)]}, - multi='income_mail_config'), - 'password': fields.function( - _get_incom_conf, - string='password', - type="char", - states={'draft': [('readonly', True)]}, - multi='income_mail_config') - } diff --git a/mail_environment/mail_view.xml b/mail_environment/mail_view.xml deleted file mode 100644 index 505b95278..000000000 --- a/mail_environment/mail_view.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - inherit_fetchmail_for_env_support - fetchmail.server - - - - - - - - - - - - - - - - - - diff --git a/mail_environment/models/__init__.py b/mail_environment/models/__init__.py new file mode 100644 index 000000000..493195a0d --- /dev/null +++ b/mail_environment/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import ir_mail_server +from . import fetchmail_server diff --git a/mail_environment/models/fetchmail_server.py b/mail_environment/models/fetchmail_server.py new file mode 100644 index 000000000..6d94def76 --- /dev/null +++ b/mail_environment/models/fetchmail_server.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# Copyright 2012-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +import operator +from odoo import api, fields, models + +from odoo.addons.server_environment import serv_config + + +class FetchmailServer(models.Model): + """Incoming POP/IMAP mail server account""" + _inherit = 'fetchmail.server' + + server = fields.Char(compute='_compute_server_env', + states={}) + port = fields.Integer(compute='_compute_server_env', + states={}) + type = fields.Selection(compute='_compute_server_env', + search='_search_type', + states={}) + user = fields.Char(compute='_compute_server_env', + states={}) + password = fields.Char(compute='_compute_server_env', + states={}) + is_ssl = fields.Boolean(compute='_compute_server_env') + attach = fields.Boolean(compute='_compute_server_env') + original = fields.Boolean(compute='_compute_server_env') + + @api.depends() + def _compute_server_env(self): + for fetchmail in self: + global_section_name = 'incoming_mail' + + key_types = {'port': int, + 'is_ssl': lambda a: bool(int(a or 0)), + 'attach': lambda a: bool(int(a or 0)), + 'original': lambda a: bool(int(a or 0)), + } + + # default vals + config_vals = {'port': 993, + 'is_ssl': 0, + 'attach': 0, + 'original': 0, + } + if serv_config.has_section(global_section_name): + config_vals.update(serv_config.items(global_section_name)) + + custom_section_name = '.'.join((global_section_name, + fetchmail.name)) + if serv_config.has_section(custom_section_name): + config_vals.update(serv_config.items(custom_section_name)) + + for key, to_type in key_types.iteritems(): + if config_vals.get(key): + config_vals[key] = to_type(config_vals[key]) + + fetchmail.update(config_vals) + + @api.model + def _search_type(self, oper, value): + operators = { + '=': operator.eq, + '!=': operator.ne, + 'in': operator.contains, + 'not in': lambda a, b: not operator.contains(a, b), + } + if oper not in operators: + return [('id', 'in', [])] + servers = self.search([]).filtered( + lambda s: operators[oper](value, s.type) + ) + return [('id', 'in', servers.ids)] diff --git a/mail_environment/models/ir_mail_server.py b/mail_environment/models/ir_mail_server.py new file mode 100644 index 000000000..4aaed6257 --- /dev/null +++ b/mail_environment/models/ir_mail_server.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2012-2016 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models + +from odoo.addons.server_environment import serv_config + + +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + smtp_host = fields.Char(compute='_compute_server_env', + required=False, + readonly=True) + smtp_port = fields.Integer(compute='_compute_server_env', + required=False, + readonly=True) + smtp_user = fields.Char(compute='_compute_server_env', + required=False, + readonly=True) + smtp_pass = fields.Char(compute='_compute_server_env', + required=False, + readonly=True) + smtp_encryption = fields.Selection(compute='_compute_server_env', + required=False, + readonly=True) + + @api.depends() + def _compute_server_env(self): + for server in self: + global_section_name = 'outgoing_mail' + + # default vals + config_vals = {'smtp_port': 587} + if serv_config.has_section(global_section_name): + config_vals.update((serv_config.items(global_section_name))) + + custom_section_name = '.'.join((global_section_name, server.name)) + if serv_config.has_section(custom_section_name): + config_vals.update(serv_config.items(custom_section_name)) + + if config_vals.get('smtp_port'): + config_vals['smtp_port'] = int(config_vals['smtp_port']) + + server.update(config_vals) diff --git a/mail_environment/views/fetchmail_server_views.xml b/mail_environment/views/fetchmail_server_views.xml new file mode 100644 index 000000000..1b04550b4 --- /dev/null +++ b/mail_environment/views/fetchmail_server_views.xml @@ -0,0 +1,21 @@ + + + + fetchmail.server + + + + + + + + + + + + + + + + + From 53f933888f12db5f63fe8eb09344686366eb8823 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 24 Mar 2017 15:27:55 +0100 Subject: [PATCH 2/2] README.rst - Fix layout --- mail_environment/README.rst | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mail_environment/README.rst b/mail_environment/README.rst index fd0643a28..9dbfb62e0 100644 --- a/mail_environment/README.rst +++ b/mail_environment/README.rst @@ -33,28 +33,28 @@ default values with a section named `[outgoing_mail.resource_name]` or `[incoming_mail.resource_name]` where "resource_name" is the name of the server. -Exemple of config file : - -[outgoing_mail] -smtp_host = smtp.myserver.com -smtp_port = 587 -smtp_user = -smtp_pass = -smtp_encryption = ssl - -[outgoing_mail.odoo_smtp_server1] -smtp_user = odoo -smtp_pass = odoo - -[incoming_mail.odoo_pop_mail1] -server = mail.myserver.com -port = 110 -type = pop -is_ssl = 0 -attach = 0 -original = 0 -user = odoo@myserver.com -password = uas1ohV0 +Exemple of config file :: + + [outgoing_mail] + smtp_host = smtp.myserver.com + smtp_port = 587 + smtp_user = + smtp_pass = + smtp_encryption = ssl + + [outgoing_mail.odoo_smtp_server1] + smtp_user = odoo + smtp_pass = odoo + + [incoming_mail.odoo_pop_mail1] + server = mail.myserver.com + port = 110 + type = pop + is_ssl = 0 + attach = 0 + original = 0 + user = odoo@myserver.com + password = uas1ohV0 You will need to create 2 records in the database, one outgoing mail server with the field `name` set to "odoo_smtp_server1" and one @@ -73,7 +73,7 @@ Known issues / Roadmap ====================== * Due to the special nature of this addon, you cannot test it on the OCA -runbot. + runbot. Bug Tracker ===========