pop3c-storage.c revision c69a177207ed18d0f0210347430a60957136bd6c
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2011-2017 Dovecot authors, see the included COPYING file */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic struct mail_storage *pop3c_storage_alloc(void)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen pool = pool_alloconly_create("pop3c storage", 512+256);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen storage = p_new(pool, struct pop3c_storage, 1);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenpop3c_storage_create(struct mail_storage *_storage,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen const char **error_r)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek struct pop3c_storage *storage = POP3C_STORAGE(_storage);
46e917c9fa05cbe7bddf805d3a9838b61e3960e1Timo Sirainen storage->set = mail_namespace_get_driver_settings(ns, _storage);
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainenpop3c_client_create_from_set(struct mail_storage *storage,
0ca3b9cb0f2a322a25ce7f229dc3d3a0b46be17bTimo Sirainen client_set.master_user = set->pop3c_master_user;
7a88e726e7300fb0273cb4e55b43c27fbd90bdbdTimo Sirainen storage->user->set->base_dir[0] == '\0' ? "" :
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen t_strconcat(storage->user->set->base_dir, "/",
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen mail_user_set_get_temp_prefix(str, storage->user->set);
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen mail_user_home_expand(storage->user, set->pop3c_rawlog_dir);
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen client_set.ssl_ca_dir = storage->set->ssl_client_ca_dir;
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainen client_set.ssl_ca_file = storage->set->ssl_client_ca_file;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen client_set.ssl_verify = set->pop3c_ssl_verify;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_IMMEDIATE;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen else if (strcmp(set->pop3c_ssl, "starttls") == 0)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_STARTTLS;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_NONE;
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen client_set.ssl_crypto_device = storage->set->ssl_crypto_device;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenpop3c_storage_get_list_settings(const struct mail_namespace *ns,
56aa97d74071f3a2987140c2ff1cfd5a59cb35aaTimo Sirainen if (set->root_dir != NULL && *set->root_dir != '\0' &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* we don't really care about root_dir, but we
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen just need to get index_dir autocreated.
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen it happens when index_dir differs from root_dir. */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic struct mailbox *
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenpop3c_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen pool = pool_alloconly_create("pop3c mailbox", 1024*3);
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen index_storage_mailbox_alloc(&mbox->box, vname, flags, MAIL_INDEX_PREFIX);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenpop3c_mailbox_exists(struct mailbox *box, bool auto_boxes ATTR_UNUSED,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void pop3c_login_callback(enum pop3c_command_state state,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* authentication failure probably */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen "pop3c: Disconnected from remote server");
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic int pop3c_mailbox_open(struct mailbox *box)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (index_storage_mailbox_open(box, FALSE) < 0)
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen mbox->client = pop3c_client_create_from_set(box->storage,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen pop3c_client_login(mbox->client, pop3c_login_callback, mbox);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void pop3c_mailbox_close(struct mailbox *box)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen const struct mailbox_update *update ATTR_UNUSED,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen "POP3 mailbox creation isn't supported");
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen const struct mailbox_update *update ATTR_UNUSED)
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen if (!guid_128_is_empty(update->mailbox_guid) ||
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen update->uid_validity != 0 || update->min_next_uid != 0 ||
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen "POP3 mailbox update isn't supported");
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen return index_storage_mailbox_update(box, update);
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainenstatic int pop3c_mailbox_get_status(struct mailbox *box,
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen if (index_storage_get_status(box, items, status_r) < 0)
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen if ((pop3c_client_get_capabilities(mbox->client) &
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainenstatic int pop3c_mailbox_get_metadata(struct mailbox *box,
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen /* a bit ugly way to do this, but better than nothing for now.
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen FIXME: if indexes are enabled, keep this there. */
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen mail_generate_guid_128_hash(box->name, metadata_r->guid);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen if (index_mailbox_get_metadata(box, items, metadata_r) < 0)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void pop3c_notify_changes(struct mailbox *box ATTR_UNUSED)
2e708f348f20caa47210cf46cf7654f167fa47bbTimo Sirainenpop3c_save_alloc(struct mailbox_transaction_context *t)
1ee74d70bb758637e560d556c7240563967d22c8Timo Sirainenpop3c_save_begin(struct mail_save_context *ctx,
2e708f348f20caa47210cf46cf7654f167fa47bbTimo Sirainen mail_storage_set_error(ctx->transaction->box->storage,
2e708f348f20caa47210cf46cf7654f167fa47bbTimo Sirainen MAIL_ERROR_NOTPOSSIBLE, "POP3 doesn't support saving mails");
2e708f348f20caa47210cf46cf7654f167fa47bbTimo Sirainenstatic int pop3c_save_continue(struct mail_save_context *ctx ATTR_UNUSED)
1ee74d70bb758637e560d556c7240563967d22c8Timo Sirainenstatic int pop3c_save_finish(struct mail_save_context *ctx)
1ee74d70bb758637e560d556c7240563967d22c8Timo Sirainenpop3c_save_cancel(struct mail_save_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic bool pop3c_storage_is_inconsistent(struct mailbox *box)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek struct pop3c_mailbox *mbox = POP3C_MAILBOX(box);