diff --git a/Mailnag/common/config.py b/Mailnag/common/config.py index 7486a85..c88815c 100644 --- a/Mailnag/common/config.py +++ b/Mailnag/common/config.py @@ -3,7 +3,7 @@ # # config.py # -# Copyright 2011 - 2013 Patrick Ulbrich +# Copyright 2011 - 2014 Patrick Ulbrich # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,8 @@ from common.i18n import _ mailnag_defaults = { 'core': { - 'check_interval' : '10', + 'poll_interval' : '10', + 'imap_idle_timeout' : '10', 'autostart' : '1', 'enabled_plugins' : 'dbusplugin, soundplugin' } diff --git a/Mailnag/daemon/idlers.py b/Mailnag/daemon/idlers.py index 7adfc8c..42d9d2c 100644 --- a/Mailnag/daemon/idlers.py +++ b/Mailnag/daemon/idlers.py @@ -3,7 +3,7 @@ # # idlers.py # -# Copyright 2011 - 2013 Patrick Ulbrich +# Copyright 2011 - 2014 Patrick Ulbrich # Copyright 2011 Leighton Earl # # This program is free software; you can redistribute it and/or modify @@ -32,13 +32,14 @@ from daemon.imaplib2 import AUTH # Idler class # class Idler(object): - def __init__(self, account, sync_callback): + def __init__(self, account, sync_callback, idle_timeout): self.RECONNECT_RETRY_INTERVAL = 5 # minutes self._thread = threading.Thread(target=self._idle) self._event = threading.Event() self._sync_callback = sync_callback self._account = account + self._idle_timeout = idle_timeout # use_existing = True: # connection has been opened in mailnag.py already (immediate check) self._conn = account.get_connection(use_existing = True) @@ -90,8 +91,9 @@ class Idler(object): self._conn_closed = False # register idle callback that is called whenever an idle event arrives (new mail / mail deleted). - # the callback is called after 10 minutes at the latest. gmail sends keepalive events every 5 minutes. - self._conn.idle(callback = self._idle_callback, timeout = 60 * 10) + # the callback is called after minutes at the latest. + # gmail sends keepalive events every 5 minutes. + self._conn.idle(callback = self._idle_callback, timeout = 60 * self._idle_timeout) # waits for the event to be set # (in idle callback or in dispose()) @@ -161,17 +163,18 @@ class Idler(object): # IdlerRunner class # class IdlerRunner: - def __init__(self, accounts, sync_callback): + def __init__(self, accounts, sync_callback, idle_timeout): self._idlerlist = [] self._accounts = accounts self._sync_callback = sync_callback + self._idle_timeout = idle_timeout def run(self): for acc in self._accounts: if acc.imap and acc.idle: try: - idler = Idler(acc, self._sync_callback) + idler = Idler(acc, self._sync_callback, self._idle_timeout) idler.run() self._idlerlist.append(idler) except Exception as ex: diff --git a/Mailnag/mailnag.py b/Mailnag/mailnag.py index 5677644..80df59b 100644 --- a/Mailnag/mailnag.py +++ b/Mailnag/mailnag.py @@ -3,7 +3,7 @@ # # mailnag.py # -# Copyright 2011 - 2013 Patrick Ulbrich +# Copyright 2011 - 2014 Patrick Ulbrich # Copyright 2011 Leighton Earl # Copyright 2011 Ralf Hersel # @@ -262,12 +262,12 @@ def start(cfg, hookreg): # start polling thread for POP3 accounts and # IMAP accounts without idle support if len(non_idle_accounts) > 0: - check_interval = int(cfg.get('core', 'check_interval')) + poll_interval = int(cfg.get('core', 'poll_interval')) def poll_func(): try: while True: - poll_thread_stop.wait(timeout = 60.0 * check_interval) + poll_thread_stop.wait(timeout = 60.0 * poll_interval) if poll_thread_stop.is_set(): break @@ -288,7 +288,8 @@ def start(cfg, hookreg): logging.exception('Caught an exception.') - idlrunner = IdlerRunner(idle_accounts, sync_func) + idle_timeout = int(cfg.get('core', 'imap_idle_timeout')) + idlrunner = IdlerRunner(idle_accounts, sync_func, idle_timeout) idlrunner.run() except: logging.exception('Caught an exception.')