mailbox-guid-cache.c revision 6feb0ff583c425dbe5b77ad99bc5ecbd2e508f29
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenstatic unsigned int guid_cache_rec_hash(const void *_rec)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen const struct mailbox_guid_cache_rec *rec = _rec;
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen return mem_hash(rec->guid, sizeof(rec->guid));
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenstatic int guid_cache_rec_cmp(const void *_r1, const void *_r2)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen const struct mailbox_guid_cache_rec *r1 = _r1, *r2 = _r2;
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen return memcmp(r1->guid, r2->guid, sizeof(r1->guid));
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenint mailbox_guid_cache_find(struct mailbox_list *list,
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen const char **vname_r)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen memcpy(lookup_rec.guid, guid, sizeof(lookup_rec.guid));
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen rec = hash_table_lookup(list->guid_cache, &lookup_rec);
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen rec = hash_table_lookup(list->guid_cache, &lookup_rec);
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen rec = hash_table_lookup(list->guid_cache, &lookup_rec);
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenvoid mailbox_guid_cache_refresh(struct mailbox_list *list)
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen list->guid_cache = hash_table_create(default_pool,
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen while ((info = mailbox_list_iter_next(ctx)) != NULL) {
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen (MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) != 0)
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen box = mailbox_alloc(list, info->name, MAILBOX_FLAG_KEEP_RECENT);
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen info->name, mailbox_get_last_error(box, NULL));
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen memcpy(rec->guid, metadata.guid, sizeof(rec->guid));
108340ffacae3b7d09fa51b566d77aa51dd6483bTimo Sirainen rec->vname = p_strdup(list->guid_cache_pool, info->name);