mbox-storage.c revision 9c66dd5c3e2ba484a5c7cdb98a139bda31fdfaa4
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen/* How often to touch the dotlock file when using KEEP_LOCKED flag */
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen/* Assume that if atime < mtime, there are new mails. If it's good enough for
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen UW-IMAP, it's good enough for us. */
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen (st).st_atime < (st).st_mtime ? MAILBOX_MARKED : MAILBOX_UNMARKED)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen/* NOTE: must be sorted for istream-header-filter. Note that it's not such
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen a good idea to change this list, as the messages will then change from
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen client's point of view. So if you do it, change all mailboxes' UIDVALIDITY
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen so all caches are reset. */
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenconst char *mbox_hide_headers[] = {
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "Content-Length",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "X-IMAPbase",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "X-Keywords",
a9b3887f4d9ed75a76fed964c1930432bf84f4f5Timo Sirainenunsigned int mbox_hide_headers_count = N_ELEMENTS(mbox_hide_headers);
a9b3887f4d9ed75a76fed964c1930432bf84f4f5Timo Sirainen/* A bit ugly duplification of the above list. It's safe to modify this list
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen without bad side effects, just keep the list sorted. */
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "Content-Length",
a9b3887f4d9ed75a76fed964c1930432bf84f4f5Timo Sirainen "X-Delivery-ID"
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "X-IMAPbase",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "X-Keywords",
a9b3887f4d9ed75a76fed964c1930432bf84f4f5Timo Sirainenunsigned int mbox_save_drop_headers_count = N_ELEMENTS(mbox_save_drop_headers);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(mbox_mailbox_list_module,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenint mbox_set_syscall_error(struct mbox_mailbox *mbox, const char *function)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen mail_storage_set_error(&mbox->storage->storage,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen mail_storage_set_critical(&mbox->storage->storage,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "%s failed with mbox file %s: %m",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic const char *
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenmbox_list_get_path(struct mailbox_list *list, const char *name,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen struct mbox_mailbox_list *mlist = MBOX_LIST_CONTEXT(list);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen const char *path, *p;
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen path = mlist->module_ctx.super.get_path(list, name, type);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen return t_strconcat(path, "/"MBOX_INDEX_DIR_NAME, NULL);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic struct mail_storage *mbox_storage_alloc(void)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen pool = pool_alloconly_create("mbox storage", 512+256);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen storage = p_new(pool, struct mbox_storage, 1);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenmbox_storage_create(struct mail_storage *_storage, struct mail_namespace *ns,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen struct mbox_storage *storage = (struct mbox_storage *)_storage;
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen const char *dir;
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen storage->set = mail_storage_get_driver_settings(_storage);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen _storage->temp_path_prefix = p_strconcat(_storage->pool, dir,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen "/", mailbox_list_get_temp_prefix(ns->list), NULL);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic void mbox_storage_get_list_settings(const struct mail_namespace *ns,
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen set->subscription_fname = MBOX_SUBSCRIPTION_FILE_NAME;
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen set->inbox_path = t_strconcat(set->root_dir, "/inbox", NULL);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox: INBOX defaulted to %s", set->inbox_path);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic bool mbox_is_file(const char *path, const char *name, bool debug)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: stat(%s) failed: %m",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: is a directory (%s)",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: no R/W access (%s)",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: yes (%s)", name, path);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic bool mbox_is_dir(const char *path, const char *name, bool debug)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: stat(%s) failed: %m",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: is not a directory (%s)",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: no R/W/X access (%s)",
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox autodetect: %s: yes (%s)", name, path);
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic bool mbox_storage_is_root_dir(const char *dir, bool debug)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen if (mbox_is_dir(t_strconcat(dir, "/"MBOX_INDEX_DIR_NAME, NULL),
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen if (mbox_is_file(t_strconcat(dir, "/inbox", NULL), "has inbox", debug))
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen if (mbox_is_file(t_strconcat(dir, "/mbox", NULL), "has mbox", debug))
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic const char *mbox_storage_find_root_dir(const struct mail_namespace *ns)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen if (mail_user_get_home(ns->user, &home) <= 0) {
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenstatic const char *
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainenmbox_storage_find_inbox_file(const char *user, bool debug)
c865b0e9c65fd77f7b2ab6f8616d3def5501ecb3Timo Sirainen i_debug("mbox: INBOX: access(%s, rw) failed: %m", path);
if (debug)
return path;
if (debug)
return NULL;
return FALSE;
if (debug)
return FALSE;
debug);
return TRUE;
return FALSE;
return FALSE;
static struct mailbox *
int fd;
(void)restrict_access_use_priv_gid();
rootdir);
const char *rootdir;
int ret;
else if (ret == 0) {
int ret;
return ret;
bool directory)
int fd;
if (p != NULL) {
&origin);
if (directory) {
const char *inbox_path;
return FALSE;
const char *name)
static struct mailbox_transaction_context *
if (lock_id != 0)
(struct mbox_transaction_context *)t;
int ret;
return ret;
(struct mbox_transaction_context *)t;
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,