summaryrefslogtreecommitdiff
path: root/addons/fetchmail
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2013-04-15 12:34:31 +0200
committerChristophe Matthieu <chm@openerp.com>2013-04-15 12:34:31 +0200
commited4b70dfe33605fde42cccd788bb0f43ffefbec6 (patch)
tree970ec3a89a382a0d2d8182710081206fb815ef4d /addons/fetchmail
parent177f51cb541f6f635d445ca24ce4453d79eb6d39 (diff)
parent53f168daaf989d97a4e514934afc7fe04d21193b (diff)
[MERGE] from trunk
bzr revid: chm@openerp.com-20130415103431-y96fhba0502b6aqc
Diffstat (limited to 'addons/fetchmail')
-rw-r--r--addons/fetchmail/fetchmail.py27
-rw-r--r--addons/fetchmail/fetchmail_data.xml2
2 files changed, 27 insertions, 2 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py
index 397ca893bae..cce1f77856e 100644
--- a/addons/fetchmail/fetchmail.py
+++ b/addons/fetchmail/fetchmail.py
@@ -89,7 +89,6 @@ class fetchmail_server(osv.osv):
'script': '/mail/static/scripts/openerp_mailgate.py',
}
-
def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False, object_id=False):
port = 0
values = {}
@@ -175,13 +174,14 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p
def _fetch_mails(self, cr, uid, ids=False, context=None):
if not ids:
- ids = self.search(cr, uid, [('state','=','done')])
+ ids = self.search(cr, uid, [('state','=','done'),('type','in',['pop','imap'])])
return self.fetch_mail(cr, uid, ids, context=context)
def fetch_mail(self, cr, uid, ids, context=None):
"""WARNING: meant for cron usage only - will commit() after each email!"""
if context is None:
context = {}
+ context['fetchmail_cron_running'] = True
mail_thread = self.pool.get('mail.thread')
action_pool = self.pool.get('ir.actions.server')
for server in self.browse(cr, uid, ids, context=context):
@@ -240,6 +240,29 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p
server.write({'date': time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)})
return True
+ def cron_update(self, cr, uid, context=None):
+ if context is None:
+ context = {}
+ if not context.get('fetchmail_cron_running'):
+ # Enabled/Disable cron based on the number of 'done' server of type pop or imap
+ ids = self.search(cr, uid, [('state','=','done'),('type','in',['pop','imap'])])
+ try:
+ cron_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action')[1]
+ self.pool.get('ir.cron').write(cr, 1, [cron_id], {'active': bool(ids)})
+ except ValueError:
+ # Nevermind if default cron cannot be found
+ pass
+
+ def create(self, cr, uid, values, context=None):
+ res = super(fetchmail_server, self).create(cr, uid, values, context=context)
+ self.cron_update(cr, uid, context=context)
+ return res
+
+ def write(self, cr, uid, ids, values, context=None):
+ res = super(fetchmail_server, self).write(cr, uid, ids, values, context=context)
+ self.cron_update(cr, uid, context=context)
+ return res
+
class mail_mail(osv.osv):
_inherit = "mail.mail"
_columns = {
diff --git a/addons/fetchmail/fetchmail_data.xml b/addons/fetchmail/fetchmail_data.xml
index d77aadc12de..3f6592b340f 100644
--- a/addons/fetchmail/fetchmail_data.xml
+++ b/addons/fetchmail/fetchmail_data.xml
@@ -10,6 +10,8 @@
<field name="model">fetchmail.server</field>
<field name="function">_fetch_mails</field>
<field name="args">()</field>
+ <!-- Active flag is set on fetchmail_server.create/write -->
+ <field name="active" eval="False"/>
</record>
</data>
</openerp>