'Sends a NOOP to each connection recorded.
It will wait a maximum of timeout seconds between doing this, and will
continue to do so until the Event object as passed is true.  This method
is expected to be invoked in a separate thread, which should be join()\'d
after the event is set.'

def keepalive(self, timeout, event):

    self.ui.debug('imap', 'keepalive    thread    started')
    while (not event.isSet()):
        self.connectionlock.acquire()
        numconnections = (len(self.assignedconnections) + len(self.availableconnections))
        self.connectionlock.release()
        threads = []
        for i in range(numconnections):
            self.ui.debug('imap', ('keepalive:    processing    connection    %d    of    %d' % (i, numconnections)))
            if (len(self.idlefolders) > i):
                idler = IdleThread(self, self.idlefolders[i])
            else:
                idler = IdleThread(self)
            idler.start()
            threads.append(idler)
        self.ui.debug('imap', 'keepalive:    waiting    for    timeout')
        event.wait(timeout)
        self.ui.debug('imap', 'keepalive:    after    wait')
        for idler in threads:
            idler.stop()
            idler.join()
        self.ui.debug('imap', 'keepalive:    all    threads    joined')
    self.ui.debug('imap', 'keepalive:    event    is    set;    exiting')
    return
