|
@ -19,21 +19,20 @@ |
|
|
# |
|
|
# |
|
|
############################################################################## |
|
|
############################################################################## |
|
|
|
|
|
|
|
|
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" |
|
|
_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 |
|
|
Return configuration |
|
|
""" |
|
|
""" |
|
|
res = {} |
|
|
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' |
|
|
global_section_name = 'outgoing_mail' |
|
|
|
|
|
|
|
|
# default vals |
|
|
# default vals |
|
@ -41,7 +40,8 @@ class IrMail(osv.osv): |
|
|
if serv_config.has_section(global_section_name): |
|
|
if serv_config.has_section(global_section_name): |
|
|
config_vals.update((serv_config.items(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): |
|
|
if serv_config.has_section(custom_section_name): |
|
|
config_vals.update(serv_config.items(custom_section_name)) |
|
|
config_vals.update(serv_config.items(custom_section_name)) |
|
|
|
|
|
|
|
@ -54,60 +54,64 @@ class IrMail(osv.osv): |
|
|
_columns = { |
|
|
_columns = { |
|
|
'smtp_host': fields.function( |
|
|
'smtp_host': fields.function( |
|
|
_get_smtp_conf, |
|
|
_get_smtp_conf, |
|
|
method=True, |
|
|
|
|
|
string='SMTP Server', |
|
|
string='SMTP Server', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='outgoing_mail_config', |
|
|
multi='outgoing_mail_config', |
|
|
size=128), |
|
|
|
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
|
|
|
help="Hostname or IP of SMTP server"), |
|
|
'smtp_port': fields.function( |
|
|
'smtp_port': fields.function( |
|
|
_get_smtp_conf, |
|
|
_get_smtp_conf, |
|
|
method=True, |
|
|
|
|
|
string='SMTP Port', |
|
|
string='SMTP Port', |
|
|
type="integer", |
|
|
type="integer", |
|
|
multi='outgoing_mail_config', |
|
|
multi='outgoing_mail_config', |
|
|
help="SMTP Port. Usually 465 for SSL, and 25 or 587 for other cases.", |
|
|
|
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
|
|
|
help="SMTP Port. Usually 465 for SSL, " |
|
|
|
|
|
"and 25 or 587 for other cases.", |
|
|
size=5), |
|
|
size=5), |
|
|
'smtp_user': fields.function( |
|
|
'smtp_user': fields.function( |
|
|
_get_smtp_conf, |
|
|
_get_smtp_conf, |
|
|
method=True, |
|
|
|
|
|
string='Username', |
|
|
string='Username', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='outgoing_mail_config', |
|
|
multi='outgoing_mail_config', |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
help="Optional username for SMTP authentication", |
|
|
help="Optional username for SMTP authentication", |
|
|
size=64), |
|
|
size=64), |
|
|
'smtp_pass': fields.function( |
|
|
'smtp_pass': fields.function( |
|
|
_get_smtp_conf, |
|
|
_get_smtp_conf, |
|
|
method=True, |
|
|
|
|
|
string='Password', |
|
|
string='Password', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='outgoing_mail_config', |
|
|
multi='outgoing_mail_config', |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
help="Optional password for SMTP authentication", |
|
|
help="Optional password for SMTP authentication", |
|
|
size=64), |
|
|
size=64), |
|
|
'smtp_encryption': fields.function( |
|
|
'smtp_encryption': fields.function( |
|
|
_get_smtp_conf, |
|
|
_get_smtp_conf, |
|
|
method=True, |
|
|
|
|
|
string='smtp_encryption', |
|
|
string='smtp_encryption', |
|
|
type="char", |
|
|
|
|
|
|
|
|
type="selection", |
|
|
multi='outgoing_mail_config', |
|
|
multi='outgoing_mail_config', |
|
|
|
|
|
selection=[('none', 'None'), |
|
|
|
|
|
('starttls', 'TLS (STARTTLS)'), |
|
|
|
|
|
('ssl', 'SSL/TLS')], |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
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" |
|
|
|
|
|
"- ssl: SMTP sessions are encrypted with SSL/TLS through a dedicated port (default: 465)", |
|
|
|
|
|
size=64)} |
|
|
|
|
|
|
|
|
|
|
|
IrMail() |
|
|
|
|
|
|
|
|
"- 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(osv.osv): |
|
|
|
|
|
|
|
|
class FetchmailServer(orm.Model): |
|
|
"""Incoming POP/IMAP mail server account""" |
|
|
"""Incoming POP/IMAP mail server account""" |
|
|
_inherit = 'fetchmail.server' |
|
|
_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 |
|
|
Return configuration |
|
|
""" |
|
|
""" |
|
|
res = {} |
|
|
res = {} |
|
|
for fetchmail in self.browse(cursor, uid, ids): |
|
|
|
|
|
|
|
|
for fetchmail in self.browse(cr, uid, ids, context=context): |
|
|
global_section_name = 'incoming_mail' |
|
|
global_section_name = 'incoming_mail' |
|
|
|
|
|
|
|
|
key_types = {'port': int, |
|
|
key_types = {'port': int, |
|
@ -125,7 +129,8 @@ class FetchmailServer(osv.osv): |
|
|
if serv_config.has_section(global_section_name): |
|
|
if serv_config.has_section(global_section_name): |
|
|
config_vals.update(serv_config.items(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): |
|
|
if serv_config.has_section(custom_section_name): |
|
|
config_vals.update(serv_config.items(custom_section_name)) |
|
|
config_vals.update(serv_config.items(custom_section_name)) |
|
|
|
|
|
|
|
@ -135,9 +140,9 @@ class FetchmailServer(osv.osv): |
|
|
res[fetchmail.id] = config_vals |
|
|
res[fetchmail.id] = config_vals |
|
|
return res |
|
|
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 = [] |
|
|
result_ids = [] |
|
|
# read all incomming servers values |
|
|
|
|
|
|
|
|
# read all incoming servers values |
|
|
all_ids = self.search(cr, uid, [], context=context) |
|
|
all_ids = self.search(cr, uid, [], context=context) |
|
|
results = self.read(cr, uid, all_ids, ['id', 'type'], context=context) |
|
|
results = self.read(cr, uid, all_ids, ['id', 'type'], context=context) |
|
|
args = args[:] |
|
|
args = args[:] |
|
@ -146,12 +151,14 @@ class FetchmailServer(osv.osv): |
|
|
operator = args[i][1] |
|
|
operator = args[i][1] |
|
|
if operator == '=': |
|
|
if operator == '=': |
|
|
for res in results: |
|
|
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']) |
|
|
result_ids.append(res['id']) |
|
|
elif operator == 'in': |
|
|
elif operator == 'in': |
|
|
for search_vals in args[i][2]: |
|
|
for search_vals in args[i][2]: |
|
|
for res in results: |
|
|
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']) |
|
|
result_ids.append(res['id']) |
|
|
else: |
|
|
else: |
|
|
continue |
|
|
continue |
|
@ -161,65 +168,65 @@ class FetchmailServer(osv.osv): |
|
|
_columns = { |
|
|
_columns = { |
|
|
'server': fields.function( |
|
|
'server': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Server', |
|
|
string='Server', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='income_mail_config', |
|
|
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( |
|
|
'port': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Port', |
|
|
string='Port', |
|
|
type="integer", |
|
|
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( |
|
|
'type': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Type', |
|
|
string='Type', |
|
|
type="char", |
|
|
|
|
|
|
|
|
type="selection", |
|
|
|
|
|
selection=[('pop', 'POP Server'), |
|
|
|
|
|
('imap', 'IMAP Server'), |
|
|
|
|
|
('local', 'Local Server'), |
|
|
|
|
|
], |
|
|
multi='income_mail_config', |
|
|
multi='income_mail_config', |
|
|
fnct_search=_type_search, |
|
|
fnct_search=_type_search, |
|
|
size=64, |
|
|
|
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
help="pop, imap, local"), |
|
|
help="pop, imap, local"), |
|
|
'is_ssl': fields.function( |
|
|
'is_ssl': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Is SSL', |
|
|
string='Is SSL', |
|
|
type="boolean", |
|
|
type="boolean", |
|
|
multi='income_mail_config', |
|
|
multi='income_mail_config', |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
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( |
|
|
'attach': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Keep Attachments', |
|
|
string='Keep Attachments', |
|
|
type="boolean", |
|
|
type="boolean", |
|
|
multi='income_mail_config', |
|
|
multi='income_mail_config', |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
help="Whether attachments should be downloaded. " |
|
|
help="Whether attachments should be downloaded. " |
|
|
"If not enabled, incoming emails will be stripped of any " |
|
|
"If not enabled, incoming emails will be stripped of any " |
|
|
"attachments before being processed"), |
|
|
"attachments before being processed"), |
|
|
'original': fields.function( |
|
|
'original': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Keep Original', |
|
|
string='Keep Original', |
|
|
type="boolean", |
|
|
type="boolean", |
|
|
multi='income_mail_config', |
|
|
multi='income_mail_config', |
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
help="Whether a full original copy of each email should be kept " |
|
|
help="Whether a full original copy of each email should be kept " |
|
|
"for reference and attached to each processed message. This " |
|
|
"for reference and attached to each processed message. This " |
|
|
"will usually double the size of your message database."), |
|
|
"will usually double the size of your message database."), |
|
|
'user': fields.function( |
|
|
'user': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='Username', |
|
|
string='Username', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='income_mail_config', |
|
|
|
|
|
size=64), |
|
|
|
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
|
|
|
multi='income_mail_config'), |
|
|
'password': fields.function( |
|
|
'password': fields.function( |
|
|
_get_incom_conf, |
|
|
_get_incom_conf, |
|
|
method=True, |
|
|
|
|
|
string='password', |
|
|
string='password', |
|
|
type="char", |
|
|
type="char", |
|
|
multi='income_mail_config', |
|
|
|
|
|
size=64)} |
|
|
|
|
|
FetchmailServer() |
|
|
|
|
|
|
|
|
states={'draft': [('readonly', True)]}, |
|
|
|
|
|
multi='income_mail_config') |
|
|
|
|
|
} |