summaryrefslogtreecommitdiff
path: root/addons/fetchmail
diff options
context:
space:
mode:
authorMayur Maheshwari (OpenERP) <mma@tinyerp.com>2012-04-11 11:48:02 +0530
committerMayur Maheshwari (OpenERP) <mma@tinyerp.com>2012-04-11 11:48:02 +0530
commit36099cbf2b5edee9fc7175cfab6f3da9ea9ac7ee (patch)
treec2083290db29cba411977c13c5bdbd91a40bec85 /addons/fetchmail
parent9346a7e8ecc4b3a042af0dcd597945c987bbc92f (diff)
parent5fac93a5f64a450df0f7ca0b1791b6a2c9407cd5 (diff)
[MERGE]Merge with lp:~openerp-dev/openobject-addons/trunk-account_voucher_yml
bzr revid: mma@tinyerp.com-20120411061802-nx2p77prspl6ojz1
Diffstat (limited to 'addons/fetchmail')
-rw-r--r--addons/fetchmail/__init__.py3
-rw-r--r--addons/fetchmail/fetchmail_view.xml1
-rw-r--r--addons/fetchmail/res_config.py123
3 files changed, 126 insertions, 1 deletions
diff --git a/addons/fetchmail/__init__.py b/addons/fetchmail/__init__.py
index 934df9846dd..7703c4d2f5b 100644
--- a/addons/fetchmail/__init__.py
+++ b/addons/fetchmail/__init__.py
@@ -1,7 +1,7 @@
#-*- coding:utf-8 -*-
##############################################################################
#
-# OpenERP, Open Source Management Solution
+# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# mga@tinyerp.com
#
@@ -21,5 +21,6 @@
##############################################################################
import fetchmail
+import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/fetchmail/fetchmail_view.xml b/addons/fetchmail/fetchmail_view.xml
index a9fb94553ed..3344183a92a 100644
--- a/addons/fetchmail/fetchmail_view.xml
+++ b/addons/fetchmail/fetchmail_view.xml
@@ -105,6 +105,7 @@
action="action_email_server_tree"
name="Incoming Mail Servers"
sequence="14"
+ groups="base.group_no_one"
/>
<record model="ir.ui.view" id="email_message_tree_view">
diff --git a/addons/fetchmail/res_config.py b/addons/fetchmail/res_config.py
new file mode 100644
index 00000000000..2b4072a63c3
--- /dev/null
+++ b/addons/fetchmail/res_config.py
@@ -0,0 +1,123 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Business Applications
+# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
+#
+# 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, osv
+
+class fetchmail_config_settings(osv.osv_memory):
+ """ This wizard can be inherited in conjunction with 'res.config.settings', in order to
+ define fields that configure a fetchmail server.
+
+ It relies on the following convention on a set of fields::
+
+ class my_config_wizard(osv.osv_memory):
+ _name = 'my.settings'
+ _inherits = ['res.config.settings', 'fetchmail.config.settings']
+
+ _columns = {
+ 'fetchmail_X': fields.boolean(..., fetchmail_model='my.model', fetchmail_name='Blah'),
+ 'X_server': fields.char('Server Name', size=256),
+ 'X_port': fields.integer('Port'),
+ 'X_type': fields.selection(
+ [('pop', 'POP Server'), ('imap', 'IMAP Server'), ('local', 'Local Server')],
+ 'Server Type'),
+ 'X_is_ssl': fields.boolean('SSL/TLS'),
+ 'X_user': fields.char('Username', size=256),
+ 'X_password': fields.char('Password', size=1024),
+ }
+
+ The method ``get_default_fetchmail_servers`` retrieves the current fetchmail configuration
+ for all fields that start with 'fetchmail_'. It looks up configurations that match the
+ given model name (``fetchmail_model``). The method ``set_fetchmail_servers`` updates the
+ fetchmail configurations by following the same conventions. Both methods are called
+ automatically by the methods of the model 'res.config.settings'.
+
+ The onchange method ``onchange_fetchmail`` can be used to react on changes on the fields
+ 'X_type' and 'X_is_ssl'. Its first parameter is the fields' prefix (here 'X').
+ """
+ _name = 'fetchmail.config.settings'
+
+ def get_default_fetchmail_servers(self, cr, uid, fields, context=None):
+ ir_model = self.pool.get('ir.model')
+ fetchmail_server = self.pool.get('fetchmail.server')
+ fetchmail_fields = [f for f in self._columns if f.startswith('fetchmail_')]
+ res = {}
+ for field in fetchmail_fields:
+ model_name = self._columns[field].fetchmail_model
+ model_id = ir_model.search(cr, uid, [('model', '=', model_name)])[0]
+ server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'done')])
+ if server_ids:
+ server = fetchmail_server.browse(cr, uid, server_ids[0], context)
+ prefix = field[10:]
+ res.update({
+ field: True,
+ prefix + '_server': server.server,
+ prefix + '_port': server.port,
+ prefix + '_type': server.type,
+ prefix + '_is_ssl': server.is_ssl,
+ prefix + '_user': server.user,
+ prefix + '_password': server.password,
+ })
+ return res
+
+ def set_fetchmail_servers(self, cr, uid, ids, context):
+ ir_model = self.pool.get('ir.model')
+ fetchmail_server = self.pool.get('fetchmail.server')
+ fetchmail_fields = [f for f in self._columns if f.startswith('fetchmail_')]
+ config = self.browse(cr, uid, ids[0], context)
+ for field in fetchmail_fields:
+ model_name = self._columns[field].fetchmail_model
+ model_id = ir_model.search(cr, uid, [('model', '=', model_name)])[0]
+ server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'done')])
+ if config[field]:
+ prefix = field[10:]
+ values = {
+ 'server': config[prefix + '_server'],
+ 'port': config[prefix + '_port'],
+ 'type': config[prefix + '_type'],
+ 'is_ssl': config[prefix + '_is_ssl'],
+ 'user': config[prefix + '_user'],
+ 'password': config[prefix + '_password'],
+ }
+ if not server_ids:
+ values.update({
+ 'name': getattr(self._columns[field], 'fetchmail_name', model_name),
+ 'object_id': model_id,
+ })
+ server_ids = [fetchmail_server.create(cr, uid, values, context=context)]
+ else:
+ server_ids = fetchmail_server.search(cr, uid, [('object_id', '=', model_id)], context=context)
+ fetchmail_server.write(cr, uid, server_ids, values, context=context)
+ fetchmail_server.button_confirm_login(cr, uid, server_ids, context)
+ else:
+ fetchmail_server.set_draft(cr, uid, server_ids, context)
+
+ def onchange_fetchmail(self, cr, uid, ids, prefix, server_type, ssl, context=None):
+ values = {}
+ if server_type == 'pop':
+ values[prefix + '_port'] = ssl and 995 or 110
+ elif server_type == 'imap':
+ values[prefix + '_port'] = ssl and 993 or 143
+ else:
+ values[prefix + '_server'] = False
+ values[prefix + '_port'] = 0
+ return {'value': values}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: