From 5d4fae0fe3ccb240d180fc33ece5551107762db0 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 11:30:14 +0200 Subject: [PATCH 01/10] Move mail_environment in root folder --- {__unported__/mail_environment => mail_environment}/__init__.py | 0 .../mail_environment => mail_environment}/__openerp__.py | 0 {__unported__/mail_environment => mail_environment}/env_mail.py | 0 .../i18n/mail_environment.pot | 0 {__unported__/mail_environment => mail_environment}/mail_view.xml | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {__unported__/mail_environment => mail_environment}/__init__.py (100%) rename {__unported__/mail_environment => mail_environment}/__openerp__.py (100%) rename {__unported__/mail_environment => mail_environment}/env_mail.py (100%) rename {__unported__/mail_environment => mail_environment}/i18n/mail_environment.pot (100%) rename {__unported__/mail_environment => mail_environment}/mail_view.xml (100%) diff --git a/__unported__/mail_environment/__init__.py b/mail_environment/__init__.py similarity index 100% rename from __unported__/mail_environment/__init__.py rename to mail_environment/__init__.py diff --git a/__unported__/mail_environment/__openerp__.py b/mail_environment/__openerp__.py similarity index 100% rename from __unported__/mail_environment/__openerp__.py rename to mail_environment/__openerp__.py diff --git a/__unported__/mail_environment/env_mail.py b/mail_environment/env_mail.py similarity index 100% rename from __unported__/mail_environment/env_mail.py rename to mail_environment/env_mail.py diff --git a/__unported__/mail_environment/i18n/mail_environment.pot b/mail_environment/i18n/mail_environment.pot similarity index 100% rename from __unported__/mail_environment/i18n/mail_environment.pot rename to mail_environment/i18n/mail_environment.pot diff --git a/__unported__/mail_environment/mail_view.xml b/mail_environment/mail_view.xml similarity index 100% rename from __unported__/mail_environment/mail_view.xml rename to mail_environment/mail_view.xml From 24a2d124928951726b1e3f677a453758a3bb2d0e Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 11:33:22 +0200 Subject: [PATCH 02/10] Use absolute imports for openerp and new Model classes --- mail_environment/env_mail.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mail_environment/env_mail.py b/mail_environment/env_mail.py index 252703d2a..88c8a15bd 100644 --- a/mail_environment/env_mail.py +++ b/mail_environment/env_mail.py @@ -19,13 +19,12 @@ # ############################################################################## -from osv import fields -from osv import osv +from openerp.osv import orm, fields -from server_environment import serv_config +from openerp.addons.server_environment import serv_config -class IrMail(osv.osv): +class IrMail(orm.Model): _inherit = "ir.mail_server" def _get_smtp_conf(self, cursor, uid, ids, name, args, context=None): @@ -95,10 +94,8 @@ class IrMail(osv.osv): "- ssl: SMTP sessions are encrypted with SSL/TLS through a dedicated port (default: 465)", size=64)} -IrMail() - -class FetchmailServer(osv.osv): +class FetchmailServer(orm.Model): """Incoming POP/IMAP mail server account""" _inherit = 'fetchmail.server' @@ -222,4 +219,3 @@ class FetchmailServer(osv.osv): type="char", multi='income_mail_config', size=64)} -FetchmailServer() From 5c137c1a008028409365a86d0539541be3c2df8a Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 11:35:50 +0200 Subject: [PATCH 03/10] Use cr argument instead of cursor, propagate context --- mail_environment/__init__.py | 1 + mail_environment/env_mail.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mail_environment/__init__.py b/mail_environment/__init__.py index be0b4da9a..89dd1478f 100644 --- a/mail_environment/__init__.py +++ b/mail_environment/__init__.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- from . import env_mail diff --git a/mail_environment/env_mail.py b/mail_environment/env_mail.py index 88c8a15bd..d16f1963a 100644 --- a/mail_environment/env_mail.py +++ b/mail_environment/env_mail.py @@ -27,12 +27,12 @@ from openerp.addons.server_environment import serv_config class IrMail(orm.Model): _inherit = "ir.mail_server" - def _get_smtp_conf(self, cursor, uid, ids, name, args, context=None): + def _get_smtp_conf(self, cr, uid, ids, name, args, context=None): """ Return configuration """ res = {} - for mail_server in self.browse(cursor, uid, ids): + for mail_server in self.browse(cr, uid, ids, context=context): global_section_name = 'outgoing_mail' # default vals @@ -99,12 +99,12 @@ class FetchmailServer(orm.Model): """Incoming POP/IMAP mail server account""" _inherit = 'fetchmail.server' - def _get_incom_conf(self, cursor, uid, ids, name, args, context=None): + def _get_incom_conf(self, cr, uid, ids, name, args, context=None): """ Return configuration """ res = {} - for fetchmail in self.browse(cursor, uid, ids): + for fetchmail in self.browse(cr, uid, ids, context=context): global_section_name = 'incoming_mail' key_types = {'port': int, @@ -132,7 +132,7 @@ class FetchmailServer(orm.Model): res[fetchmail.id] = config_vals return res - def _type_search(self, cr, uid, obj, name, args, context={}): + def _type_search(self, cr, uid, obj, name, args, context=None): result_ids = [] # read all incomming servers values all_ids = self.search(cr, uid, [], context=context) From c3e9a8bae861fed1f9c6643227f0753feaa15d60 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 13:56:17 +0200 Subject: [PATCH 04/10] Update fields, remove deprecated 'method' argument, change 'states' otherwise the fields are not readonly (seems that the 'states' of the original field is kept. --- mail_environment/env_mail.py | 56 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/mail_environment/env_mail.py b/mail_environment/env_mail.py index d16f1963a..ab624053e 100644 --- a/mail_environment/env_mail.py +++ b/mail_environment/env_mail.py @@ -53,46 +53,49 @@ class IrMail(orm.Model): _columns = { 'smtp_host': fields.function( _get_smtp_conf, - method=True, string='SMTP Server', type="char", multi='outgoing_mail_config', - size=128), + states={'draft': [('readonly', True)]}, + help="Hostname or IP of SMTP server"), 'smtp_port': fields.function( _get_smtp_conf, - method=True, 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, - method=True, 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, - method=True, 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, - method=True, string='smtp_encryption', - type="char", + 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)", - size=64)} + "- ssl: SMTP sessions are encrypted with SSL/TLS through a dedicated port (default: 465)",) + } class FetchmailServer(orm.Model): @@ -158,64 +161,65 @@ class FetchmailServer(orm.Model): _columns = { 'server': fields.function( _get_incom_conf, - method=True, string='Server', type="char", multi='income_mail_config', - size=256, help="Hostname or IP of the mail server"), + states={'draft': [('readonly', True)]}, + help="Hostname or IP of the mail server"), 'port': fields.function( _get_incom_conf, - method=True, string='Port', type="integer", - multi='income_mail_config', - help="Hostname or IP of the mail server"), + states={'draft': [('readonly', True)]}, + multi='income_mail_config'), 'type': fields.function( _get_incom_conf, - method=True, string='Type', - type="char", + type="selection", + selection=[('pop', 'POP Server'), + ('imap', 'IMAP Server'), + ('local', 'Local Server'), + ], multi='income_mail_config', fnct_search=_type_search, - size=64, + states={'draft': [('readonly', True)]}, help="pop, imap, local"), 'is_ssl': fields.function( _get_incom_conf, - method=True, 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, - method=True, 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, - method=True, 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, - method=True, string='Username', type="char", - multi='income_mail_config', - size=64), + states={'draft': [('readonly', True)]}, + multi='income_mail_config'), 'password': fields.function( _get_incom_conf, - method=True, string='password', type="char", - multi='income_mail_config', - size=64)} + states={'draft': [('readonly', True)]}, + multi='income_mail_config') + } From 29ff442856668ab4d9ad617e534cad2a56ca1c4b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 13:59:06 +0200 Subject: [PATCH 05/10] Activate the installable flag --- mail_environment/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail_environment/__openerp__.py b/mail_environment/__openerp__.py index 45313fe7c..29970701f 100644 --- a/mail_environment/__openerp__.py +++ b/mail_environment/__openerp__.py @@ -63,6 +63,6 @@ password = openerp 'init_xml': [], 'update_xml': ['mail_view.xml'], 'demo_xml': [], - 'installable': False, + 'installable': True, 'active': False, } From 6f6b2662700214bc13bd0766f5269d07fec007c4 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 14:01:38 +0200 Subject: [PATCH 06/10] Indentation of the view with 2 spaces --- mail_environment/mail_view.xml | 45 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/mail_environment/mail_view.xml b/mail_environment/mail_view.xml index 59577ed21..531391076 100644 --- a/mail_environment/mail_view.xml +++ b/mail_environment/mail_view.xml @@ -1,27 +1,24 @@ - - - - inherit_fetchmail_for_env_support - fetchmail.server - - - - - - - - - - - - - - - - - - - + + + inherit_fetchmail_for_env_support + fetchmail.server + + + + + + + + + + + + + + + + + From 715621cf30133874fdf1021e3f8e737975d9d18e Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 14:05:26 +0200 Subject: [PATCH 07/10] Remove only the attrs attribute instead of redefining the whole field --- mail_environment/mail_view.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mail_environment/mail_view.xml b/mail_environment/mail_view.xml index 531391076..505b95278 100644 --- a/mail_environment/mail_view.xml +++ b/mail_environment/mail_view.xml @@ -6,17 +6,17 @@ fetchmail.server - - + + - - + + - - + + - - + + From 9a5037709ce03ab13bec9cb587b967944bb74e39 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 14:10:24 +0200 Subject: [PATCH 08/10] pep8 --- mail_environment/__openerp__.py | 6 +++++- mail_environment/env_mail.py | 29 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mail_environment/__openerp__.py b/mail_environment/__openerp__.py index 29970701f..f584873eb 100644 --- a/mail_environment/__openerp__.py +++ b/mail_environment/__openerp__.py @@ -59,7 +59,11 @@ password = openerp 'author': 'Camptocamp', 'license': 'AGPL-3', 'website': 'http://openerp.camptocamp.com', - 'depends': ['mail', 'fetchmail', 'server_environment', 'server_environment_files', 'crm'], + 'depends': ['mail', + 'fetchmail', + 'server_environment', + 'server_environment_files', + 'crm'], 'init_xml': [], 'update_xml': ['mail_view.xml'], 'demo_xml': [], diff --git a/mail_environment/env_mail.py b/mail_environment/env_mail.py index ab624053e..c4025340a 100644 --- a/mail_environment/env_mail.py +++ b/mail_environment/env_mail.py @@ -40,7 +40,8 @@ class IrMail(orm.Model): 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)) + 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)) @@ -64,7 +65,8 @@ class IrMail(orm.Model): type="integer", multi='outgoing_mail_config', states={'draft': [('readonly', True)]}, - help="SMTP Port. Usually 465 for SSL, and 25 or 587 for other cases.", + help="SMTP Port. Usually 465 for SSL, " + "and 25 or 587 for other cases.", size=5), 'smtp_user': fields.function( _get_smtp_conf, @@ -87,14 +89,16 @@ class IrMail(orm.Model): string='smtp_encryption', type="selection", multi='outgoing_mail_config', - selection=[('none','None'), - ('starttls','TLS (STARTTLS)'), - ('ssl','SSL/TLS')], + 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)",) + "- 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)") } @@ -125,7 +129,8 @@ class FetchmailServer(orm.Model): 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)) + 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)) @@ -137,7 +142,7 @@ class FetchmailServer(orm.Model): def _type_search(self, cr, uid, obj, name, args, context=None): result_ids = [] - # read all incomming servers values + # 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[:] @@ -146,12 +151,14 @@ class FetchmailServer(orm.Model): operator = args[i][1] if operator == '=': for res in results: - if (res['type'] == args[i][2]) and (res['id'] not in result_ids): + 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): + if (res['type'] == search_vals and + res['id'] not in result_ids): result_ids.append(res['id']) else: continue From d18ce97849e12a9bea2e08c6f63028810770fc72 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 14:10:46 +0200 Subject: [PATCH 09/10] crm is not a dependency for mail_environment --- mail_environment/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail_environment/__openerp__.py b/mail_environment/__openerp__.py index f584873eb..6b4437f14 100644 --- a/mail_environment/__openerp__.py +++ b/mail_environment/__openerp__.py @@ -63,7 +63,7 @@ password = openerp 'fetchmail', 'server_environment', 'server_environment_files', - 'crm'], + ], 'init_xml': [], 'update_xml': ['mail_view.xml'], 'demo_xml': [], From feaba04f8e7eab78ef2d6549d06ec9151b1110e9 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 19 Jan 2015 16:10:59 +0100 Subject: [PATCH 10/10] Fix typo in manifest --- mail_environment/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail_environment/__openerp__.py b/mail_environment/__openerp__.py index 6b4437f14..05efe5717 100644 --- a/mail_environment/__openerp__.py +++ b/mail_environment/__openerp__.py @@ -26,7 +26,7 @@ 'description': """ Extend mail and fetch mail with server environment module. -In config files, sections outgoint_mail and incoming_mails are default values +In config files, sections outgoing_mail and incoming_mails are default values for all Outgoing Mail Servers and Fetchmail Servers. For each server, you can (re)define values with a section named "outgoing_mail.resource_name" where resource_name is the name of your server.