bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#include "lib.h"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#include "mail-namespace.h"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#include "mail-storage.h"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#include "dsync-mailbox-tree.h"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#include "dsync-brain-private.h"
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstatic int
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainensync_create_box(struct dsync_brain *brain, struct mailbox *box,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen const guid_128_t mailbox_guid, uint32_t uid_validity,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen enum mail_error *error_r)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen{
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct mailbox_metadata metadata;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct mailbox_update update;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen enum mail_error error;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen const char *errstr;
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen int ret;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&update);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen memcpy(update.mailbox_guid, mailbox_guid, sizeof(update.mailbox_guid));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen update.uid_validity = uid_validity;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (mailbox_create(box, &update, FALSE) < 0) {
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi errstr = mailbox_get_last_internal_error(box, &error);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (error != MAIL_ERROR_EXISTS) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Can't create mailbox %s: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_get_vname(box), errstr);
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen *error_r = error;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
329c2181e609b39294cc9cc76921a96a15e8f8a2Timo Sirainen if (brain->no_mail_sync) {
329c2181e609b39294cc9cc76921a96a15e8f8a2Timo Sirainen /* trust that create worked, we can't actually open it
329c2181e609b39294cc9cc76921a96a15e8f8a2Timo Sirainen and verify. */
329c2181e609b39294cc9cc76921a96a15e8f8a2Timo Sirainen return 0;
329c2181e609b39294cc9cc76921a96a15e8f8a2Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* sync the mailbox so we can look up its latest status */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Can't sync mailbox %s: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_get_vname(box),
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, error_r));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* verify that the GUID is what we wanted. if it's not, it probably
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen means that the mailbox had already been created. then we'll use the
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen GUID that is higher.
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mismatching UIDVALIDITY is handled later, because we choose it by
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen checking which mailbox has more messages */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Can't get mailbox GUID %s: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_get_vname(box),
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, error_r));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen ret = memcmp(mailbox_guid, metadata.guid, sizeof(metadata.guid));
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi /* if THEIR guid is bigger than OUR guid, and we are not doing
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi backup in either direction, OR GUID did not match and we are
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi receiving backup, try change the mailbox GUID.
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi */
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi if ((ret > 0 && !brain->backup_recv &&
b78c41586816833aee1de8de732e542aac7b940dAki Tuomi !brain->backup_send) || (ret != 0 && brain->backup_recv)) {
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen if (brain->debug) {
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen i_debug("brain %c: Changing mailbox %s GUID %s -> %s",
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen brain->master_brain ? 'M' : 'S',
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen mailbox_get_vname(box),
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen guid_128_to_string(metadata.guid),
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen guid_128_to_string(mailbox_guid));
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen }
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&update);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen memcpy(update.mailbox_guid, mailbox_guid,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen sizeof(update.mailbox_guid));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (mailbox_update(box, &update) < 0) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Can't update mailbox GUID %s: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_get_vname(box),
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, error_r));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen /* verify that the update worked */
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen &metadata) < 0) {
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen i_error("Can't get mailbox GUID %s: %s",
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen mailbox_get_vname(box),
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, error_r));
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen return -1;
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen }
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen if (memcmp(mailbox_guid, metadata.guid,
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen sizeof(metadata.guid)) != 0) {
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen i_error("Backend didn't update mailbox %s GUID",
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen mailbox_get_vname(box));
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen *error_r = MAIL_ERROR_TEMP;
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen return -1;
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen }
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen } else if (ret < 0) {
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen if (brain->debug) {
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen i_debug("brain %c: Other brain should change mailbox "
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen "%s GUID %s -> %s",
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen brain->master_brain ? 'M' : 'S',
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen mailbox_get_vname(box),
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen guid_128_to_string(mailbox_guid),
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen guid_128_to_string(metadata.guid));
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return 0;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen}
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenint dsync_brain_mailbox_tree_sync_change(struct dsync_brain *brain,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen const struct dsync_mailbox_tree_sync_change *change,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen enum mail_error *error_r)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen{
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct mailbox *box = NULL, *destbox;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen const char *errstr, *func_name = NULL, *storage_name;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen enum mail_error error;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen int ret = -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen if (brain->backup_send) {
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen i_assert(brain->no_backup_overwrite);
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen return 0;
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen }
e83126866761632b437e532dfdc30be01d14039dTimo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen switch (change->type) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_DELETE_BOX:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* make sure we're deleting the correct mailbox */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = dsync_brain_mailbox_alloc(brain, change->mailbox_guid,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen &box, &errstr, error_r);
ec047a9c54a02338e85fb1767120b0923f6d4148Timo Sirainen if (ret < 0) {
cabf98de0145c8e233e41073fe3f8c1cc85ed1ebTimo Sirainen i_error("Mailbox sync: Couldn't allocate mailbox %s GUID %s: %s",
cabf98de0145c8e233e41073fe3f8c1cc85ed1ebTimo Sirainen change->full_name,
ec047a9c54a02338e85fb1767120b0923f6d4148Timo Sirainen guid_128_to_string(change->mailbox_guid), errstr);
ec047a9c54a02338e85fb1767120b0923f6d4148Timo Sirainen return -1;
ec047a9c54a02338e85fb1767120b0923f6d4148Timo Sirainen }
ec047a9c54a02338e85fb1767120b0923f6d4148Timo Sirainen if (ret == 0) {
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen dsync_brain_set_changes_during_sync(brain, t_strdup_printf(
b1533bd0dd0787b9c0d879c2d7398b1ff7964570Timo Sirainen "Mailbox %s GUID %s deletion conflict: %s",
cabf98de0145c8e233e41073fe3f8c1cc85ed1ebTimo Sirainen change->full_name,
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen guid_128_to_string(change->mailbox_guid), errstr));
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen return 0;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_DELETE_DIR:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen storage_name = mailbox_list_get_storage_name(change->ns->list,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen change->full_name);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (mailbox_list_delete_dir(change->ns->list, storage_name) == 0)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return 0;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
d4847b921058734e0668bc7690465c91523d9ec0Martti Rannanjärvi errstr = mailbox_list_get_last_internal_error(change->ns->list, &error);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (error == MAIL_ERROR_NOTFOUND ||
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen error == MAIL_ERROR_EXISTS) {
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen dsync_brain_set_changes_during_sync(brain, t_strdup_printf(
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen "Mailbox %s mailbox_list_delete_dir conflict: %s",
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen change->full_name, errstr));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return 0;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen } else {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Mailbox sync: mailbox_list_delete_dir failed: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen errstr);
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen *error_r = error;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return -1;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen default:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen box = mailbox_alloc(change->ns->list, change->full_name, 0);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
19e161dd9e2c3a2ffc96ee8852bec0720cb30d1cTimo Sirainen mailbox_skip_create_name_restrictions(box, TRUE);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen switch (change->type) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_CREATE_BOX:
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen ret = sync_create_box(brain, box, change->mailbox_guid,
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen change->uid_validity, error_r);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_free(&box);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return ret;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_CREATE_DIR:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = mailbox_create(box, NULL, TRUE);
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen if (ret < 0 &&
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen mailbox_get_last_mail_error(box) == MAIL_ERROR_EXISTS) {
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen /* it doesn't matter if somebody else created this
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen directory or we automatically did while creating its
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen child mailbox. it's there now anyway and we don't
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen gain anything by treating this failure any
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen differently from success. */
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen ret = 0;
66f7fc500f134274c67c836a1de1128221b5bcaeTimo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen func_name = "mailbox_create";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_DELETE_BOX:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = mailbox_delete(box);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen func_name = "mailbox_delete";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_DELETE_DIR:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_unreached();
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_RENAME:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen destbox = mailbox_alloc(change->ns->list,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen change->rename_dest_name, 0);
19e161dd9e2c3a2ffc96ee8852bec0720cb30d1cTimo Sirainen mailbox_skip_create_name_restrictions(destbox, TRUE);
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainen ret = mailbox_rename(box, destbox);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen func_name = "mailbox_rename";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_free(&destbox);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_SUBSCRIBE:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = mailbox_set_subscribed(box, TRUE);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen func_name = "mailbox_set_subscribed";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen case DSYNC_MAILBOX_TREE_SYNC_TYPE_UNSUBSCRIBE:
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = mailbox_set_subscribed(box, FALSE);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen func_name = "mailbox_set_subscribed";
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen break;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (ret < 0) {
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi errstr = mailbox_get_last_internal_error(box, &error);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (error == MAIL_ERROR_EXISTS ||
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen error == MAIL_ERROR_NOTFOUND) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* mailbox was already created or was already deleted.
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen let the next sync figure out what to do */
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen dsync_brain_set_changes_during_sync(brain, t_strdup_printf(
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen "Mailbox %s %s conflict: %s",
4f7951e71128c120d8a502d6406cc603fcc8eb0bTimo Sirainen mailbox_get_vname(box), func_name, errstr));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ret = 0;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen } else {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_error("Mailbox %s sync: %s failed: %s",
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_get_vname(box), func_name, errstr);
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen *error_r = error;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen }
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mailbox_free(&box);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen return ret;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen}