summaryrefslogtreecommitdiff
path: root/addons/fetchmail/fetchmail.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2014-09-05 15:28:22 +0200
committerChristophe Simonis <chs@odoo.com>2014-09-05 15:28:22 +0200
commit31bf30d2d0eb78baaa36360b99fe58bf7cd4c9e7 (patch)
treed7be61ecd6bb4c8b5552e39b03e2a64eebbbf323 /addons/fetchmail/fetchmail.py
parentafba9e8817c458640ae446ac7aaaab79be4fe1e9 (diff)
parented1c173971968eaa96693cb4e1547efa6e6c34e0 (diff)
[MERGE] forward port of branch 8.0 up to ed1c173
Diffstat (limited to 'addons/fetchmail/fetchmail.py')
-rw-r--r--addons/fetchmail/fetchmail.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py
index b496b8bca76..d0690520b0e 100644
--- a/addons/fetchmail/fetchmail.py
+++ b/addons/fetchmail/fetchmail.py
@@ -235,12 +235,12 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p
save_original=server.original,
strip_attachments=(not server.attach),
context=context)
+ pop_server.dele(num)
except Exception:
_logger.exception('Failed to process mail from %s server %s.', server.type, server.name)
failed += 1
if res_id and server.action_id:
action_pool.run(cr, uid, [server.action_id.id], {'active_id': res_id, 'active_ids': [res_id], 'active_model': context.get("thread_model", server.object_id.model)})
- pop_server.dele(num)
cr.commit()
_logger.info("Fetched %d email(s) on %s server %s; %d succeeded, %d failed.", numMsgs, server.type, server.name, (numMsgs - failed), failed)
except Exception:
@@ -251,27 +251,33 @@ 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 _update_cron(self, cr, uid, context=None):
+ if context and context.get('fetchmail_cron_running'):
+ return
+
+ try:
+ cron = self.pool['ir.model.data'].get_object(
+ cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action', context=context)
+ except ValueError:
+ # Nevermind if default cron cannot be found
+ return
+
+ # Enabled/Disable cron based on the number of 'done' server of type pop or imap
+ cron.toggle(model=self._name, domain=[('state','=','done'), ('type','in',['pop','imap'])])
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)
+ self._update_cron(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)
+ self._update_cron(cr, uid, context=context)
+ return res
+
+ def unlink(self, cr, uid, ids, context=None):
+ res = super(fetchmail_server, self).unlink(cr, uid, ids, context=context)
+ self._update_cron(cr, uid, context=context)
return res
class mail_mail(osv.osv):