dbox-storage.c revision 32ee977e189266744ef69ac4e832fd3111d6f949
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2007 Dovecot authors, see the included COPYING file */
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen#define CREATE_MODE 0770 /* umask() should limit it more */
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(dbox_mailbox_list_module,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainendbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainendbox_get_list_settings(struct mailbox_list_settings *list_set,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char *data, enum mail_storage_flags flags,
29543188462c9348f365ec29115d777ffe4769d3Timo Sirainen const char **layout_r, const char **alt_dir_r,
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen const char **error_r)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (data == NULL || *data == '\0' || *data == ':') {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen /* we won't do any guessing for this format. */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen return mailbox_list_settings_parse(data, list_set, layout_r, alt_dir_r,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen pool = pool_alloconly_create("dbox storage", 512+256);
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainen storage = p_new(pool, struct dbox_storage, 1);
cf05592015b99607095f970bf914f5d069bf0666Timo Sirainenstatic int dbox_create(struct mail_storage *_storage, const char *data,
cf05592015b99607095f970bf914f5d069bf0666Timo Sirainen const char **error_r)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct dbox_storage *storage = (struct dbox_storage *)_storage;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (dbox_get_list_settings(&list_set, data, _storage->flags,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen list_set.mail_storage_flags = &_storage->flags;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen list_set.lock_method = &_storage->lock_method;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen "stat(%s) failed: %m",
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen "Root mail directory doesn't exist: %s",
85c9cf2c39903ecb102d701e8b19a7cf364dce83Timo Sirainen if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen *error_r = t_strdup_printf("mkdir(%s) failed: %m",
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (mailbox_list_alloc(layout, &_storage->list, error_r) < 0)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen storage->list_module_ctx.super = _storage->list->v;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen storage->alt_dir = p_strdup(_storage->pool, alt_dir);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen _storage->list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen _storage->list->v.delete_mailbox = dbox_list_delete_mailbox;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen MODULE_CONTEXT_SET_FULL(_storage->list, dbox_mailbox_list_module,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen /* finish list init after we've overridden vfuncs */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mailbox_list_init(_storage->list, _storage->ns, &list_set,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mail_storage_get_list_flags(_storage->flags));
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic int create_dbox(struct mail_storage *storage, const char *path)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (!mail_storage_set_error_from_errno(storage)) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic const char *
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainendbox_get_alt_path(struct dbox_storage *storage, const char *path)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen unsigned int len;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen if (strncmp(path, storage->alt_dir, len) != 0)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen return t_strconcat(storage->alt_dir, path + len, NULL);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic struct mailbox *
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainendbox_open(struct dbox_storage *storage, const char *name,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen struct mail_storage *_storage = &storage->storage;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen path = mailbox_list_get_path(_storage->list, name,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen index = index_storage_alloc(_storage, name, flags, DBOX_INDEX_PREFIX);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mail_index_set_fsync_types(index, MAIL_INDEX_SYNC_TYPE_APPEND |
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen pool = pool_alloconly_create("dbox mailbox", 1024+512);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mbox->alt_path = p_strdup(pool, dbox_get_alt_path(storage, path));
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mbox->rotate_size = (uoff_t)strtoul(value, NULL, 10) * 1024;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mbox->rotate_size = 0; /* FIXME: currently anything else doesn't work */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mbox->rotate_min_size = (uoff_t)strtoul(value, NULL, 10) * 1024;
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainen mbox->rotate_min_size = DBOX_DEFAULT_ROTATE_MIN_SIZE;
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainen if (mbox->rotate_min_size > mbox->rotate_size)
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen mbox->rotate_days = (unsigned int)strtoul(value, NULL, 10);
sizeof(struct dbox_mail_index_record),
sizeof(uint32_t));
sizeof(struct dbox_index_header), 0, 0);
static struct mailbox *
const char *path;
return NULL;
return NULL;
return NULL;
path);
return NULL;
int ret;
const char *path;
const char *name)
struct dirent *d;
unsigned int dir_len;
errno = 0;
path);
if (!unlinked_something) {
const char *mail_path;
t_push();
ret = 0;
t_pop();
return ret;
static void dbox_class_init(void)
static void dbox_class_deinit(void)
NULL,
NULL,
NULL,
NULL,
NULL,