'Safely remove a mailbox from the cache, saving any state changes to
the encrypted pickles.
If the mailbox is still in use somewhere in the app (as measured by
the Python reference counter), we DON\'T remove from cache, to ensure
each mailbox is represented by exactly one object at a time.'

def uncache_mailbox(self, session, entry, drop=True, force_save=False):

    (pfn, mbx_id) = entry[:2]
    if pfn:
        def dropit(l):
            return [c for c in l if (c[0] != pfn)]
    else:
        def dropit(l):
            return [c for c in l if (c[1] != mbx_id)]
    with self._lock:
        mboxes = [c[2] for c in self._mbox_cache if ((c[0] == pfn) if pfn else (c[1] == mbx_id))]
        if (len(mboxes) < 1):
            return
        if (sys.getrefcount(mboxes[0]) > 3):
            if force_save:
                self.save_mailbox(session, pfn, mboxes[0])
            return
        self.save_mailbox(session, pfn, mboxes[0])
        if drop:
            self._mbox_cache = dropit(self._mbox_cache)
        else:
            keep2 = self._mbox_cache[(- MAX_CACHED_MBOXES):]
            keep1 = dropit(self._mbox_cache[:(- MAX_CACHED_MBOXES)])
            self._mbox_cache = (keep1 + keep2)
