pop3c-storage.c revision 7a88e726e7300fb0273cb4e55b43c27fbd90bdbd
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (c) 2011-2014 Dovecot authors, see the included COPYING file */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic struct mail_storage *pop3c_storage_alloc(void)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen pool = pool_alloconly_create("pop3c storage", 512+256);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen storage = p_new(pool, struct pop3c_storage, 1);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenpop3c_storage_create(struct mail_storage *_storage,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const char **error_r)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct pop3c_storage *storage = (struct pop3c_storage *)_storage;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen storage->set = mail_storage_get_driver_settings(_storage);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (storage->set->pop3c_password[0] == '\0') {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenpop3c_client_create_from_set(struct mail_storage *storage,
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen client_set.master_user = set->pop3c_master_user;
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen storage->user->set->base_dir[0] == '\0' ? "" :
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen t_strconcat(storage->user->set->base_dir, "/",
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen mail_user_set_get_temp_prefix(str, storage->user->set);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_user_home_expand(storage->user, set->pop3c_rawlog_dir);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen client_set.ssl_ca_dir = storage->set->ssl_client_ca_dir;
af81f402ddc897c74c1e85abd02879612ce44882Timo Sirainen client_set.ssl_ca_file = storage->set->ssl_client_ca_file;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen client_set.ssl_verify = set->pop3c_ssl_verify;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_IMMEDIATE;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen else if (strcmp(set->pop3c_ssl, "starttls") == 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_STARTTLS;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen client_set.ssl_mode = POP3C_CLIENT_SSL_MODE_NONE;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen client_set.ssl_crypto_device = storage->set->ssl_crypto_device;
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainenpop3c_storage_get_list_settings(const struct mail_namespace *ns,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (set->root_dir != NULL && *set->root_dir != '\0' &&
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* we don't really care about root_dir, but we
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen just need to get index_dir autocreated.
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen it happens when index_dir differs from root_dir. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic struct mailbox *
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainenpop3c_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen pool = pool_alloconly_create("pop3c mailbox", 1024*3);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen mbox->storage = (struct pop3c_storage *)storage;
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen index_storage_mailbox_alloc(&mbox->box, vname, flags, MAIL_INDEX_PREFIX);
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainenpop3c_mailbox_exists(struct mailbox *box, bool auto_boxes ATTR_UNUSED,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic void pop3c_login_callback(enum pop3c_command_state state,
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen /* authentication failure probably */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "pop3c: Disconnected from remote server");
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstatic int pop3c_mailbox_open(struct mailbox *box)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen if (index_storage_mailbox_open(box, FALSE) < 0)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen mbox->client = pop3c_client_create_from_set(box->storage,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen pop3c_client_login(mbox->client, pop3c_login_callback, mbox);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstatic void pop3c_mailbox_close(struct mailbox *box)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen const struct mailbox_update *update ATTR_UNUSED,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen "POP3 mailbox creation isn't supported");
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen const struct mailbox_update *update ATTR_UNUSED)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (!guid_128_is_empty(update->mailbox_guid) ||
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen update->uid_validity != 0 || update->min_next_uid != 0 ||
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen "POP3 mailbox update isn't supported");
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen return index_storage_mailbox_update(box, update);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic int pop3c_mailbox_get_status(struct mailbox *box,
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen if (index_storage_get_status(box, items, status_r) < 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if ((pop3c_client_get_capabilities(mbox->client) &
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstatic int pop3c_mailbox_get_metadata(struct mailbox *box,
411d6baa37f31d90730e90c4a28c43e1974bbe58Timo Sirainen /* a bit ugly way to do this, but better than nothing for now.
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen FIXME: if indexes are enabled, keep this there. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_generate_guid_128_hash(box->name, metadata_r->guid);
if (items != 0) {
static struct mail_save_context *
return ctx;
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,