Change keepalive() to spawn IdleThreads
This is the commit that enables IDLE support. In order to do this, we hijack the keepalive method. Instead of just sending NOOPs, it now sends IDLE and responds accordingly, thanks to the IdleThread class. This code was originally by James Bunton <jamesbunton@fastmail.fm>. Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
9fa6bcdf82
commit
d47bd1ff89
@ -21,7 +21,6 @@ from offlineimap.ui import getglobalui
|
|||||||
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
from threading import Lock, BoundedSemaphore, Thread, Event, currentThread
|
||||||
from thread import get_ident # python < 2.6 support
|
from thread import get_ident # python < 2.6 support
|
||||||
import offlineimap.accounts
|
import offlineimap.accounts
|
||||||
import time
|
|
||||||
import hmac
|
import hmac
|
||||||
import socket
|
import socket
|
||||||
import base64
|
import base64
|
||||||
@ -330,8 +329,6 @@ class IMAPServer:
|
|||||||
self.ui.debug('imap', 'keepalive thread started')
|
self.ui.debug('imap', 'keepalive thread started')
|
||||||
while 1:
|
while 1:
|
||||||
self.ui.debug('imap', 'keepalive: top of loop')
|
self.ui.debug('imap', 'keepalive: top of loop')
|
||||||
time.sleep(timeout)
|
|
||||||
self.ui.debug('imap', 'keepalive: after wait')
|
|
||||||
if event.isSet():
|
if event.isSet():
|
||||||
self.ui.debug('imap', 'keepalive: event is set; exiting')
|
self.ui.debug('imap', 'keepalive: event is set; exiting')
|
||||||
return
|
return
|
||||||
@ -342,29 +339,27 @@ class IMAPServer:
|
|||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
self.ui.debug('imap', 'keepalive: connectionlock released')
|
self.ui.debug('imap', 'keepalive: connectionlock released')
|
||||||
threads = []
|
threads = []
|
||||||
imapobjs = []
|
|
||||||
|
|
||||||
for i in range(numconnections):
|
for i in range(numconnections):
|
||||||
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
|
self.ui.debug('imap', 'keepalive: processing connection %d of %d' % (i, numconnections))
|
||||||
imapobj = self.acquireconnection()
|
if len(self.idlefolders) > i:
|
||||||
self.ui.debug('imap', 'keepalive: connection %d acquired' % i)
|
idler = IdleThread(self, self.idlefolders[i])
|
||||||
imapobjs.append(imapobj)
|
else:
|
||||||
thr = threadutil.ExitNotifyThread(target = imapobj.noop)
|
idler = IdleThread(self)
|
||||||
thr.setDaemon(1)
|
idler.start()
|
||||||
thr.start()
|
threads.append(idler)
|
||||||
threads.append(thr)
|
|
||||||
self.ui.debug('imap', 'keepalive: thread started')
|
self.ui.debug('imap', 'keepalive: thread started')
|
||||||
|
|
||||||
|
self.ui.debug('imap', 'keepalive: waiting for timeout')
|
||||||
|
event.wait(timeout)
|
||||||
|
self.ui.debug('imap', 'keepalive: after wait')
|
||||||
|
|
||||||
self.ui.debug('imap', 'keepalive: joining threads')
|
self.ui.debug('imap', 'keepalive: joining threads')
|
||||||
|
|
||||||
for thr in threads:
|
for idler in threads:
|
||||||
# Make sure all the commands have completed.
|
# Make sure all the commands have completed.
|
||||||
thr.join()
|
idler.stop()
|
||||||
|
idler.join()
|
||||||
self.ui.debug('imap', 'keepalive: releasing connections')
|
|
||||||
|
|
||||||
for imapobj in imapobjs:
|
|
||||||
self.releaseconnection(imapobj)
|
|
||||||
|
|
||||||
self.ui.debug('imap', 'keepalive: bottom of loop')
|
self.ui.debug('imap', 'keepalive: bottom of loop')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user