mail-storage.c revision 81dbd579dc8f2a69c79e9c771adfe9ee27af794e
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct mail_search_register *mail_search_register_imap;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct mail_search_register *mail_search_register_human;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_storage_module_register mail_storage_module_register = { 0 };
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_module_register mail_module_register = { 0 };
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_storage_mail_index_module mail_storage_mail_index_module =
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MODULE_CONTEXT_INIT(&mail_index_module_register);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mail_search_register_deinit(&mail_search_register_human);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mail_search_register_deinit(&mail_search_register_imap);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_assert(mail_storage_find_class(storage_class->name) == NULL);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* append it after the list, so the autodetection order is correct */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen array_append(&mail_storage_classes, &storage_class, 1);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen classes = array_get(&mail_storage_classes, &count);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < count; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstruct mail_storage *mail_storage_find_class(const char *name)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen classes = array_get(&mail_storage_classes, &count);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < count; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenmail_storage_autodetect(const struct mail_namespace *ns,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen classes = array_get(&mail_storage_classes, &count);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < count; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenmail_storage_set_autodetection(const char **data, const char **driver)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char *p;
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen /* check if data is in driver:data format (eg. mbox:~/mail) */
6d2b3ce2c6ef62334985ece4f0ab8b154e0e9560Timo Sirainen while (i_isalnum(*p)) p++;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* no autodetection if the storage driver is given. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenmail_storage_get_class(struct mail_namespace *ns, const char *driver,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen enum mail_storage_flags flags, const char **error_r)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* no mail_location, autodetect */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* explicit autodetection with "auto" driver. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* handle the same as with driver=NULL */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen storage_class = mail_storage_find_class(driver);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (list_set->root_dir == NULL || *list_set->root_dir == '\0') {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* no root directory given. is this allowed? */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (flags & MAIL_STORAGE_FLAG_NO_AUTODETECTION) == 0) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* autodetection should take care of this */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (storage_class->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* root not required for this storage */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen (list->props & MAILBOX_LIST_PROP_NO_ROOT) != 0) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* root not required for this layout */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen storage_class->v.get_list_settings(ns, list_set);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen storage_class = mail_storage_autodetect(ns, list_set);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (home == NULL || *home == '\0') home = "(not set)";
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (ns->set->location == NULL || *ns->set->location == '\0') {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "Mail storage autodetection failed with home=%s", home);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen } else if (strncmp(ns->set->location, "auto:", 5) == 0) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "Autodetection failed for %s (home=%s)",
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "Ambiguous mail location setting, "
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "don't know what to do with it: %s "
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "(try prefixing it with mbox: or maildir:)",
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenmail_storage_verify_root(const char *root_dir, bool autocreate,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen const char **error_r)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen *error_r = mail_error_eacces_msg("stat", root_dir);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen } else if (errno != ENOENT && errno != ENOTDIR) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen *error_r = t_strdup_printf("stat(%s) failed: %m", root_dir);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen } else if (!autocreate) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "Root mail directory doesn't exist: %s", root_dir);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* doesn't exist */
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;
error_r) < 0)
error_r);
T_BEGIN {
} T_END;
const char *str;
const char *fmt, ...)
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 NULL;
return *box_set;
return NULL;
T_BEGIN {
} T_END;
return box;
const char *vname;
&metadata) < 0) {
return box;
return box;
const char *name)
NAMESPACE_FLAG_LIST_CHILDREN)) == 0)
return TRUE;
return FALSE;
return TRUE;
case MAIL_ERROR_NOTFOUND:
vname++;
if (*p == list_sep) {
list_sep));
const char *errstr;
MAILBOX_SET_AUTO_SUBSCRIBE) == 0) {
int ret;
return ret;
int ret;
case MAIL_ERROR_NOTFOUND:
MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) == 0) {
T_BEGIN {
} T_END;
} T_END;
if (ret < 0) {
bool directory)
int ret;
if (directory ||
return ret;
int ret;
if (ret < 0)
if (del)
return FALSE;
return FALSE;
return FALSE;
return TRUE;
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;
bool rename_children)
struct mail_namespace *
return FALSE;
i_unreached();
struct mailbox_sync_context *
T_BEGIN {
} T_END;
return ctx;
const char *errormsg;
int ret;
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;
struct mailbox *
return t->box;
struct mail_save_context *
return ctx;
const char *const *keywords_list;
const char *envelope)
int ret;
if (ret < 0) {
int ret;
return ret;
struct mailbox_transaction_context *
int ret;
return ret;
const char *path;
int *fd_r)
int fd;
unsigned int secs)