mail-storage.c revision 1ee688af5aecb3baa4268f05f4023ed257aaf18b
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenextern struct mail_search_register *mail_search_register_imap;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenextern struct mail_search_register *mail_search_register_human;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenstruct mail_storage_module_register mail_storage_module_register = { 0 };
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenstruct mail_module_register mail_module_register = { 0 };
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenstruct mail_storage_mail_index_module mail_storage_mail_index_module =
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen MODULE_CONTEXT_INIT(&mail_index_module_register);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen mail_search_register_deinit(&mail_search_register_human);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen mail_search_register_deinit(&mail_search_register_imap);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class)
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen i_assert(mail_storage_find_class(storage_class->name) == NULL);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* append it after the list, so the autodetection order is correct */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen array_append(&mail_storage_classes, &storage_class, 1);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class)
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen unsigned int i, count;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen classes = array_get(&mail_storage_classes, &count);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen for (i = 0; i < count; i++) {
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenstruct mail_storage *mail_storage_find_class(const char *name)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen unsigned int i, count;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen classes = array_get(&mail_storage_classes, &count);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen for (i = 0; i < count; i++) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenmail_storage_autodetect(const struct mail_namespace *ns,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen unsigned int i, count;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen classes = array_get(&mail_storage_classes, &count);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen for (i = 0; i < count; i++) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenmail_storage_set_autodetection(const char **data, const char **driver)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen const char *p;
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* check if data is in driver:data format (eg. mbox:~/mail) */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* no autodetection if the storage driver is given. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenmail_storage_get_class(struct mail_namespace *ns, const char *driver,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen enum mail_storage_flags flags, const char **error_r)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* no mail_location, autodetect */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* explicit autodetection with "auto" driver. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* handle the same as with driver=NULL */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen storage_class = mail_user_get_storage_class(ns->user, driver);
f8da06de93e28b5d3e039a427cdde7e1e15daec8Timo Sirainen if (list_set->root_dir == NULL || *list_set->root_dir == '\0') {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* no root directory given. is this allowed? */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (flags & MAIL_STORAGE_FLAG_NO_AUTODETECTION) == 0) {
f8da06de93e28b5d3e039a427cdde7e1e15daec8Timo Sirainen /* autodetection should take care of this */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (storage_class->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* root not required for this storage */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (list->props & MAILBOX_LIST_PROP_NO_ROOT) != 0) {
return NULL;
return storage_class;
return storage_class;
return NULL;
} else if (!autocreate) {
bool autocreate;
int ret;
if (ret == 0) {
error_r);
return FALSE;
return FALSE;
return FALSE;
return TRUE;
static struct mail_storage *
return storage;
return NULL;
const char **error_r)
error_r) < 0)
error_r);
T_BEGIN {
} T_END;
const char *str;
const char *fmt, ...)
error_r);
const char *str;
const char *str;
const struct mail_storage_settings *
void *context)
return error;
const char *error_string;
return FALSE;
return FALSE;
return TRUE;
const struct mailbox_settings *
return NULL;
return *box_set;
return NULL;
T_BEGIN {
if (open_error != 0)
} T_END;
return box;
const char *vname;
&metadata) < 0) {
return box;
return box;
return TRUE;
const char *errstr;
MAILBOX_SET_AUTO_SUBSCRIBE) == 0) {
int ret;
return ret;
const char **error_r)
if (prev_sep) {
return FALSE;
if (prev_sep && i > 0) {
return FALSE;
return TRUE;
vname++;
const char *path;
&path) < 0)
return TRUE;
return FALSE;
const char *name;
name++;
const char *name)
NAMESPACE_FLAG_LIST_CHILDREN)) == 0)
return TRUE;
return FALSE;
case MAIL_ERROR_NOTFOUND:
int ret;
case MAIL_ERROR_NOTFOUND:
MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) == 0) {
T_BEGIN {
} T_END;
} T_END;
if (ret < 0) {
return FALSE;
return FALSE;
return FALSE;
if (ret < 0)
return FALSE;
return TRUE;
const char *index_dir;
int ret;
&index_dir);
if (ret <= 0)
int ret;
return ret;
const char *name1;
return FALSE;
return TRUE;
bool directory)
int ret;
if (ret == 0) {
return ret;
int ret;
return ret;
int ret;
if (ret < 0)
if (del)
if (del) {
if (ret < 0)
int ret;
return ret;
int ret;
return ret;
const char **error_r)
return TRUE;
return FALSE;
return FALSE;
return TRUE;
const char **error_r)
return FALSE;
return FALSE;
return FALSE;
return TRUE;
int ret = 0;
return ret;
struct mail_namespace *
return FALSE;
i_unreached();
struct mailbox_sync_context *
return ctx;
T_BEGIN {
} T_END;
return ctx;
return FALSE;
const char *errormsg;
int ret;
if (ret == 0)
return ret;
struct mail_search_context *
int ret;
return ret;
bool tryagain;
if (!tryagain)
return FALSE;
return TRUE;
return FALSE;
return TRUE;
int ret;
if (ret < 0)
return ret;
struct mailbox_transaction_context *
return trans;
int ret;
return ret;
int ret;
T_BEGIN {
} T_END;
return ret;
const char *reason)
struct mailbox *
return t->box;
struct mail_save_context *
T_BEGIN {
} T_END;
return ctx;
const char *const *keywords_list;
const char *envelope)
unsigned int order)
int ret;
} else T_BEGIN {
} T_END;
if (ret < 0) {
int ret;
T_BEGIN {
} T_END;
return ret;
int ret;
T_BEGIN {
} T_END;
if (pvt_flags != 0)
t->save_count++;
return ret;
T_BEGIN {
} T_END;
struct mailbox_transaction_context *
int ret;
T_BEGIN {
} T_END;
if (ret == 0) {
if (pvt_flags != 0)
t->save_count++;
return ret;
int ret;
return ret;
int ret;
if (ret < 0) {
return ret;
const char **path_r)
int *fd_r)
int fd;
const char *root_dir;
int ret;
return ret;
&mail_dir) < 0)
unsigned int secs)
#ifndef MMAP_CONFLICTS_WRITE
return index_flags;
bool *utc_r)
unsigned int secs;
const char *error;
T_BEGIN {
} T_END;
const char **error_r)
const char *lock_path;
bool created;