1
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
5
#include "mail-storage.h"
6
#include "mailbox-list-private.h"
7
#include "mailbox-guid-cache.h"
9
struct mailbox_guid_cache_rec {
14
int mailbox_guid_cache_find(struct mailbox_list *list,
15
const guid_128_t guid, const char **vname_r)
17
const struct mailbox_guid_cache_rec *rec;
19
if (list->guid_cache == NULL) {
20
mailbox_guid_cache_refresh(list);
21
rec = hash_table_lookup(list->guid_cache, guid);
23
rec = hash_table_lookup(list->guid_cache, guid);
25
mailbox_guid_cache_refresh(list);
26
rec = hash_table_lookup(list->guid_cache, guid);
31
return list->guid_cache_errors ? -1 : 0;
33
*vname_r = rec->vname;
37
void mailbox_guid_cache_refresh(struct mailbox_list *list)
39
struct mailbox_list_iterate_context *ctx;
40
const struct mailbox_info *info;
42
struct mailbox_metadata metadata;
43
struct mailbox_guid_cache_rec *rec;
45
if (list->guid_cache == NULL) {
46
list->guid_cache_pool =
47
pool_alloconly_create("guid cache", 1024*16);
48
list->guid_cache = hash_table_create(default_pool,
49
list->guid_cache_pool, 0,
53
hash_table_clear(list->guid_cache, TRUE);
54
p_clear(list->guid_cache_pool);
56
list->guid_cache_errors = FALSE;
58
ctx = mailbox_list_iter_init(list, "*",
59
MAILBOX_LIST_ITER_NO_AUTO_BOXES);
60
while ((info = mailbox_list_iter_next(ctx)) != NULL) {
62
(MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) != 0)
65
box = mailbox_alloc(list, info->name, 0);
66
if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
68
i_error("Couldn't get mailbox %s GUID: %s",
69
info->name, mailbox_get_last_error(box, NULL));
70
list->guid_cache_errors = TRUE;
72
rec = p_new(list->guid_cache_pool,
73
struct mailbox_guid_cache_rec, 1);
74
memcpy(rec->guid, metadata.guid, sizeof(rec->guid));
75
rec->vname = p_strdup(list->guid_cache_pool, info->name);
76
hash_table_insert(list->guid_cache, rec->guid, rec);
80
if (mailbox_list_iter_deinit(&ctx) < 0)
81
list->guid_cache_errors = TRUE;