[IMP] mail_environment misc
This commit is contained in:
parent
bafd09ad4c
commit
def2c738fc
|
|
@ -1,6 +1 @@
|
||||||
# -*- encoding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Author Nicolas Bessi. Copyright Camptocamp SA
|
|
||||||
##############################################################################
|
|
||||||
from . import env_mail
|
from . import env_mail
|
||||||
|
|
@ -1,16 +1,61 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Author Nicolas Bessi. Copyright Camptocamp SA
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Server env config for mail + fetchmail',
|
'name': 'Server env config for mail + fetchmail',
|
||||||
'version': '0.1',
|
'version': '0.1',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'description': """
|
'description': """
|
||||||
extend mail and fetch mail with server env
|
Extend mail and fetch mail with server environment module.
|
||||||
|
|
||||||
|
In config files, sections outgoint_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.
|
||||||
|
|
||||||
|
Exemple of config file :
|
||||||
|
|
||||||
|
[outgoing_mail]
|
||||||
|
smtp_host = smtp.myserver.com
|
||||||
|
smtp_port = 587
|
||||||
|
smtp_user =
|
||||||
|
smtp_pass =
|
||||||
|
smtp_encryption = ssl
|
||||||
|
|
||||||
|
[outgoing_mail.openerp_smtp_server1]
|
||||||
|
smtp_user = openerp
|
||||||
|
smtp_pass = openerp
|
||||||
|
|
||||||
|
[incoming_mail.openerp_pop_mail1]
|
||||||
|
server = mail.myserver.com
|
||||||
|
port = 110
|
||||||
|
type = pop
|
||||||
|
is_ssl = 0
|
||||||
|
attach = 0
|
||||||
|
original = 0
|
||||||
|
user = openerp@myserver.com
|
||||||
|
password = openerp
|
||||||
|
|
||||||
|
|
||||||
""",
|
""",
|
||||||
'author': 'Camptocamp',
|
'author': 'Camptocamp',
|
||||||
|
'license': 'AGPL-3',
|
||||||
'website': 'http://openerp.camptocamp.com',
|
'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': [],
|
'init_xml': [],
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,31 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Author Nicolas Bessi. Copyright Camptocamp SA
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from osv import fields
|
from osv import fields
|
||||||
from osv import osv
|
from osv import osv
|
||||||
|
|
||||||
from server_environment import serv_config
|
from server_environment import serv_config
|
||||||
|
|
||||||
|
|
||||||
class IRMAIL(osv.osv):
|
class IrMail(osv.osv):
|
||||||
_inherit = "ir.mail_server"
|
_inherit = "ir.mail_server"
|
||||||
|
|
||||||
def _get_smtp_conf(self, cursor, uid, ids, name, args, context=None):
|
def _get_smtp_conf(self, cursor, uid, ids, name, args, context=None):
|
||||||
|
|
@ -17,10 +33,22 @@ class IRMAIL(osv.osv):
|
||||||
Return configuration
|
Return configuration
|
||||||
"""
|
"""
|
||||||
res = {}
|
res = {}
|
||||||
for conf in self.browse(cursor, uid, ids):
|
for mail_server in self.browse(cursor, uid, ids):
|
||||||
res_dict = dict(serv_config.items('outgoing_mail'))
|
global_section_name = 'outgoing_mail'
|
||||||
res_dict['smtp_port'] = int(res_dict.get('smtp_port', 587))
|
|
||||||
res[conf.id] = res_dict
|
# 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
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
@ -28,41 +56,41 @@ class IRMAIL(osv.osv):
|
||||||
method=True,
|
method=True,
|
||||||
string='SMTP Server',
|
string='SMTP Server',
|
||||||
type="char",
|
type="char",
|
||||||
multi='smtp_host',
|
multi='outgoing_mail_config',
|
||||||
size=128),
|
size=128),
|
||||||
'smtp_port': fields.function(_get_smtp_conf,
|
'smtp_port': fields.function(_get_smtp_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='SMTP Port',
|
string='SMTP Port',
|
||||||
type="integer",
|
type="integer",
|
||||||
multi='smtp_port',
|
multi='outgoing_mail_config',
|
||||||
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),
|
size=5),
|
||||||
'smtp_user': fields.function(_get_smtp_conf,
|
'smtp_user': fields.function(_get_smtp_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Username',
|
string='Username',
|
||||||
type="char",
|
type="char",
|
||||||
multi='smtp_user',
|
multi='outgoing_mail_config',
|
||||||
help="Optional username for SMTP authentication",
|
help="Optional username for SMTP authentication",
|
||||||
size=64),
|
size=64),
|
||||||
'smtp_pass': fields.function(_get_smtp_conf,
|
'smtp_pass': fields.function(_get_smtp_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Password',
|
string='Password',
|
||||||
type="char",
|
type="char",
|
||||||
multi='smtp_pass',
|
multi='outgoing_mail_config',
|
||||||
help="Optional password for SMTP authentication",
|
help="Optional password for SMTP authentication",
|
||||||
size=64),
|
size=64),
|
||||||
'smtp_encryption' :fields.function(_get_smtp_conf,
|
'smtp_encryption' :fields.function(_get_smtp_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='smtp_encryption',
|
string='smtp_encryption',
|
||||||
type="char",
|
type="char",
|
||||||
multi='smtp_encryption',
|
multi='outgoing_mail_config',
|
||||||
help="Choose the connection encryption scheme:\n"
|
help="Choose the connection encryption scheme:\n"
|
||||||
"- none: SMTP sessions are done in cleartext.\n"
|
"- none: SMTP sessions are done in cleartext.\n"
|
||||||
"- starttls: TLS encryption is requested at start of SMTP session (Recommended)\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)",
|
"- ssl: SMTP sessions are encrypted with SSL/TLS through a dedicated port (default: 465)",
|
||||||
size=64)}
|
size=64)}
|
||||||
|
|
||||||
IRMAIL()
|
IrMail()
|
||||||
|
|
||||||
|
|
||||||
class FetchmailServer(osv.osv):
|
class FetchmailServer(osv.osv):
|
||||||
|
|
@ -74,14 +102,30 @@ class FetchmailServer(osv.osv):
|
||||||
Return configuration
|
Return configuration
|
||||||
"""
|
"""
|
||||||
res = {}
|
res = {}
|
||||||
|
for fetchmail in self.browse(cursor, uid, ids):
|
||||||
|
global_section_name = 'incoming_mail'
|
||||||
|
|
||||||
for conf in self.browse(cursor, uid, ids):
|
key_types = {'port': int,
|
||||||
res_dict = dict(serv_config.items('incoming_mail'))
|
'is_ssl': lambda a: bool(int(a)),
|
||||||
res_dict['port'] = int(res_dict.get('port', 993))
|
'attach': lambda a: bool(int(a)),
|
||||||
res_dict['is_ssl'] = bool(int(res_dict.get('is_ssl', 0)))
|
'original': lambda a: bool(int(a)),}
|
||||||
res_dict['attach'] = bool(int(res_dict.get('attach', 0)))
|
|
||||||
res_dict['original'] = bool(int(res_dict.get('original', 0)))
|
# default vals
|
||||||
res[conf.id] = res_dict
|
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
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
@ -89,54 +133,52 @@ class FetchmailServer(osv.osv):
|
||||||
method=True,
|
method=True,
|
||||||
string='Server',
|
string='Server',
|
||||||
type="char",
|
type="char",
|
||||||
multi='server',
|
multi='income_mail_config',
|
||||||
size=256, help="Hostname or IP of the mail server"),
|
size=256, help="Hostname or IP of the mail server"),
|
||||||
'port': fields.function(_get_incom_conf,
|
'port': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Port',
|
string='Port',
|
||||||
type="integer",
|
type="integer",
|
||||||
multi='port',
|
multi='income_mail_config',
|
||||||
help="Hostname or IP of the mail server"),
|
help="Hostname or IP of the mail server"),
|
||||||
'type': fields.function(_get_incom_conf,
|
'type': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Type',
|
string='Type',
|
||||||
type="char",
|
type="char",
|
||||||
multi='type',
|
multi='income_mail_config',
|
||||||
size=64,
|
size=64,
|
||||||
help="pop, imap, local"),
|
help="pop, imap, local"),
|
||||||
'is_ssl': fields.function(_get_incom_conf,
|
'is_ssl': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Is SSL',
|
string='Is SSL',
|
||||||
type="boolean",
|
type="boolean",
|
||||||
multi='is_ssl',
|
multi='income_mail_config',
|
||||||
help='Connections are encrypted with SSL/TLS through'
|
help='Connections are encrypted with SSL/TLS through'
|
||||||
' a dedicated port (default: IMAPS=993, POP3S=995)'),
|
' a dedicated port (default: IMAPS=993, POP3S=995)'),
|
||||||
'attach': fields.function(_get_incom_conf,
|
'attach': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Keep Attachments',
|
string='Keep Attachments',
|
||||||
type="boolean",
|
type="boolean",
|
||||||
multi='attach',
|
multi='income_mail_config',
|
||||||
help="Whether attachments should be downloaded. "
|
help="Whether attachments should be downloaded. "
|
||||||
"If not enabled, incoming emails will be stripped of any attachments before being processed"),
|
"If not enabled, incoming emails will be stripped of any attachments before being processed"),
|
||||||
'original': fields.function(_get_incom_conf,
|
'original': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Keep Original',
|
string='Keep Original',
|
||||||
type="boolean",
|
type="boolean",
|
||||||
multi='attach',
|
multi='income_mail_config',
|
||||||
help="Whether a full original copy of each email should be kept for reference"
|
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."),
|
"and attached to each processed message. This will usually double the size of your message database."),
|
||||||
'user': fields.function(_get_incom_conf,
|
'user': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='Username',
|
string='Username',
|
||||||
type="char",
|
type="char",
|
||||||
multi='user',
|
multi='income_mail_config',
|
||||||
size=64),
|
size=64),
|
||||||
'password': fields.function(_get_incom_conf,
|
'password': fields.function(_get_incom_conf,
|
||||||
method=True,
|
method=True,
|
||||||
string='password',
|
string='password',
|
||||||
type="char",
|
type="char",
|
||||||
multi='password',
|
multi='income_mail_config',
|
||||||
size=64)}
|
size=64)}
|
||||||
FetchmailServer()
|
FetchmailServer()
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue