mirror of
https://github.com/pulb/mailnag.git
synced 2026-08-31 03:36:27 +02:00
read imap idle timeout from the config file, just like the pop3 poll interval (fixes issue #60)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# config.py
|
||||
#
|
||||
# Copyright 2011 - 2013 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
|
||||
#
|
||||
# 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'
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# idlers.py
|
||||
#
|
||||
# Copyright 2011 - 2013 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2011 Leighton Earl <leighton.earl@gmx.com>
|
||||
#
|
||||
# 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 <idle_timeout> 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:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# mailnag.py
|
||||
#
|
||||
# Copyright 2011 - 2013 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2011 - 2014 Patrick Ulbrich <zulu99@gmx.net>
|
||||
# Copyright 2011 Leighton Earl <leighton.earl@gmx.com>
|
||||
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
|
||||
#
|
||||
@@ -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.')
|
||||
|
||||
Reference in New Issue
Block a user