Skip to content

Commit

Permalink
lib-storage: simplify mailbox_get_path_to()
Browse files Browse the repository at this point in the history
Instead of special casing MAILBOX_LIST_PATH_TYPE_{MAILBOX,INDEX}, we can use
a common helper to remove code duplication.
  • Loading branch information
Josef 'Jeff' Sipek committed Jun 8, 2017
1 parent b01d001 commit df3ba63
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/lib-storage/mail-storage.c
Expand Up @@ -2485,39 +2485,39 @@ void mailbox_set_deleted(struct mailbox *box)
box->mailbox_deleted = TRUE;
}

int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
const char **path_r)
static int get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
const char **internal_path, const char **path_r)
{
int ret;

if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path != NULL) {
if (box->_path[0] == '\0') {
*path_r = NULL;
return 0;
}
*path_r = box->_path;
return 1;
}
if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path != NULL) {
if (box->_index_path[0] == '\0') {
if (internal_path != NULL && *internal_path != NULL) {
if ((*internal_path)[0] == '\0') {
*path_r = NULL;
return 0;
}
*path_r = box->_index_path;
*path_r = *internal_path;
return 1;
}
ret = mailbox_list_get_path(box->list, box->name, type, path_r);
if (ret < 0) {
mail_storage_copy_list_error(box->storage, box->list);
return -1;
}
if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path == NULL)
box->_path = ret == 0 ? "" : p_strdup(box->pool, *path_r);
if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path == NULL)
box->_index_path = ret == 0 ? "" : p_strdup(box->pool, *path_r);
if (internal_path != NULL && *internal_path == NULL)
*internal_path = ret == 0 ? "" : p_strdup(box->pool, *path_r);
return ret;
}

int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type,
const char **path_r)
{
if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX)
return get_path_to(box, type, &box->_path, path_r);
if (type == MAILBOX_LIST_PATH_TYPE_INDEX)
return get_path_to(box, type, &box->_index_path, path_r);
return get_path_to(box, type, NULL, path_r);
}

const char *mailbox_get_path(struct mailbox *box)
{
i_assert(box->_path != NULL);
Expand Down

0 comments on commit df3ba63

Please sign in to comment.