Example #1
0
File: imap.py Project: jre21/inbox
def remove_deleted_uids(account_id, db_session, log, folder_name, local_uids, remote_uids, syncmanager_lock, c):
    """ Works as follows:
        1. Do a LIST on the current folder to see what messages are on the
            server.
        2. Compare to message uids stored locally.
        3. Purge messages we have locally but not on the server. Ignore
            messages we have on the server that aren't local.
    """
    if len(remote_uids) > 0 and len(local_uids) > 0:
        for elt in remote_uids:
            assert not isinstance(elt, str)

    to_delete = set(local_uids) - set(remote_uids)
    if to_delete:
        # We need to grab the lock for this because deleting ImapUids may
        # cascade to Messages and FolderItems and Threads. No one else messes
        # with ImapUids, but the exposed datastore elements are another story.
        with syncmanager_lock:
            account.remove_messages(account_id, db_session, to_delete, folder_name)
            db_session.commit()

        log.info("Deleted {0} removed messages from {1}".format(len(to_delete), folder_name))

    return to_delete