bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainenraw_storage_create_from_set(const struct setting_parser_info *set_info,
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainen user = mail_user_alloc(NULL, "raw mail user", set_info, set);
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainen i_fatal("Raw user initialization failed: %s", error);
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainen ns_set = p_new(user->pool, struct mail_namespace_settings, 1);
744543d840a229fe893843046d143186971560e2Timo Sirainen /* raw storage doesn't have INBOX. We especially don't want LIST to
744543d840a229fe893843046d143186971560e2Timo Sirainen return INBOX. */
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainen ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL;
8dc39d6dd0ee768e611b13694c339fe601ec7337Timo Sirainen /* absolute paths are ok with raw storage */
8dc39d6dd0ee768e611b13694c339fe601ec7337Timo Sirainen mail_set = p_new(user->pool, struct mail_storage_settings, 1);
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainen if (mail_storage_create(ns, "raw", 0, &error) < 0)
34e9dfbce01a2807df8e2050b1cd7ae2cf014cd5Timo Sirainen i_fatal("Couldn't create internal raw storage: %s", error);
fc4e528886f47bf4d2dd0276fb8705c085c3b9aeTimo Sirainen if (mail_namespaces_init_finish(ns, &error) < 0)
fc4e528886f47bf4d2dd0276fb8705c085c3b9aeTimo Sirainen i_fatal("Couldn't create internal raw namespace: %s", error);
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainenraw_mailbox_alloc_common(struct mail_user *user, struct istream *input,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen const char *envelope_sender, struct mailbox **box_r)
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen name = path != NULL ? path : i_stream_get_name(input);
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen i_assert(strcmp(box->storage->name, RAW_STORAGE_NAME) == 0);
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainenint raw_mailbox_alloc_stream(struct mail_user *user, struct istream *input,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen time_t received_time, const char *envelope_sender,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen return raw_mailbox_alloc_common(user, input, NULL, received_time,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainenint raw_mailbox_alloc_path(struct mail_user *user, const char *path,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen time_t received_time, const char *envelope_sender,
15dd1857d40544e2c356d4f1c87c42a0579c665cTimo Sirainen return raw_mailbox_alloc_common(user, NULL, path, received_time,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenstatic struct mail_storage *raw_storage_alloc(void)
4146f38412c650f4d0e100cf22d7b32e7d24b2b6Timo Sirainen pool = pool_alloconly_create("raw storage", 512+256);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenraw_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen set->subscription_fname = RAW_SUBSCRIPTION_FILE_NAME;
4146f38412c650f4d0e100cf22d7b32e7d24b2b6Timo Sirainenstatic struct mailbox *
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainenraw_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen flags |= MAILBOX_FLAG_READONLY | MAILBOX_FLAG_NO_INDEX_FILES;
3b32bc12710240f86465a00fbb2bd1ef030e6c40Timo Sirainen pool = pool_alloconly_create("raw mailbox", 1024*3);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen index_storage_mailbox_alloc(&mbox->box, vname, flags, "dovecot.index");
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainenstatic int raw_mailbox_open(struct mailbox *box)
8af1a286fb27446eeb0e7a8764cd3ed8d35ff2acJosef 'Jeff' Sipek struct raw_mailbox *mbox = RAW_MAILBOX(box);
d22301419109ed4a38351715e6760011421dadecTimo Sirainen return index_storage_mailbox_open(box, FALSE);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen } else if (!mail_storage_set_error_from_errno(box->storage)) {
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mailbox_set_critical(box, "open(%s) failed: %m", path);
bace943c67e6cd14ce6c994f533d82a3caad5bf1Timo Sirainen box->input = i_stream_create_fd_autoclose(&fd, MAIL_READ_FULL_BLOCK_SIZE);
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen i_stream_set_init_buffer_size(box->input, MAIL_READ_FULL_BLOCK_SIZE);
d22301419109ed4a38351715e6760011421dadecTimo Sirainen return index_storage_mailbox_open(box, FALSE);
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen const struct mailbox_update *update ATTR_UNUSED,
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
4146f38412c650f4d0e100cf22d7b32e7d24b2b6Timo Sirainen "Raw mailbox creation isn't supported");
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen const struct mailbox_update *update ATTR_UNUSED)
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainen "Raw mailbox update isn't supported");
4146f38412c650f4d0e100cf22d7b32e7d24b2b6Timo Sirainenstatic void raw_notify_changes(struct mailbox *box ATTR_UNUSED)