convert-storage.c revision c979eeda1f46483d9c963e265786b701d7683d77
/* Copyright (C) 2006 Timo Sirainen */
#include "lib.h"
#include "file-lock.h"
#include "file-dotlock.h"
#include "mail-storage-private.h"
#include "mail-namespace.h"
#include "mail-search.h"
#include "convert-storage.h"
#include <stdio.h>
#define CONVERT_LOCK_FILENAME ".dovecot.convert"
struct dotlock_settings dotlock_settings = {
};
{
struct mailbox_sync_context *ctx;
struct mailbox_sync_rec sync_rec;
;
}
{
struct mail_search_context *ctx;
struct mail_search_arg search_arg;
int ret = 0;
if (sync_mailbox(srcbox) < 0)
return -1;
struct mail_keywords *keywords;
const char *const *keywords_list;
/* touch the lock file so that if there are tons of
mails another process won't override our lock. */
(void)file_dotlock_touch(dotlock);
}
if (ret < 0)
break;
}
if (mailbox_search_deinit(&ctx) < 0)
ret = -1;
if (ret < 0)
else
/* source transaction committing isn't all that important.
ignore if it fails. */
if (ret < 0)
else
(void)mailbox_transaction_commit(&src_trans, 0);
return ret;
}
{
enum mail_error error;
}
static const char *
struct mail_storage *source_storage,
{
return name;
for (p = dest_name; *p != '\0'; p++) {
if (*p == dest_sep)
*p = set->alt_hierarchy_char;
else if (*p == src_sep)
*p = dest_sep;
}
return dest_name;
}
struct mail_storage *dest_storage,
const struct mailbox_info *info,
const struct convert_settings *set)
{
int ret = 0;
return 0;
/* \NoSelect mailbox, so it's probably a "directory" */
return 0;
TRUE) < 0) {
i_error("Mailbox conversion: Couldn't create mailbox "
"directory %s", dest_name);
return -1;
}
return 0;
}
/* First open the source mailbox. If we can't open it, don't create
the destination mailbox either. */
if (set->skip_broken_mailboxes)
return 0;
i_error("Mailbox conversion: "
"Couldn't open source mailbox %s: %s",
return -1;
}
/* Create and open the destination mailbox. */
FALSE) < 0) {
i_error("Mailbox conversion: "
"Couldn't create mailbox %s: %s",
return -1;
}
}
i_error("Mailbox conversion: Couldn't open dest mailbox %s: %s",
return -1;
}
i_error("Mailbox conversion: Couldn't copy mailbox %s: %s",
}
return ret;
}
struct mail_storage *dest_storage,
const struct convert_settings *set)
{
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
int ret = 0;
ret = -1;
break;
}
/* In case there are lots of mailboxes. Also the other touch
is done only after 100 mails. */
(void)file_dotlock_touch(dotlock);
}
if (mailbox_list_iter_deinit(&iter) < 0)
ret = -1;
return ret;
}
struct mail_storage *dest_storage,
const struct convert_settings *set)
{
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
struct mailbox_list *dest_list;
const char *dest_name;
int ret = 0;
TRUE) < 0) {
ret = -1;
break;
}
}
if (mailbox_list_iter_deinit(&iter) < 0)
ret = -1;
return ret;
}
const struct convert_settings *set)
{
enum file_lock_method lock_method;
int ret;
/* No need for conversion. */
return 0;
}
/* If home directory doesn't exist, creating the destination storage
will most likely create it. So do this before locking. */
i_error("Mailbox conversion: Failed to create destination "
return -1;
}
if (ret <= 0) {
if (ret == 0)
i_error("Mailbox conversion: Lock creation timeouted");
return -1;
}
/* just in case if another process just had converted the mailbox,
reopen the source storage */
/* No need for conversion anymore. */
return 0;
}
if (ret == 0) {
}
if (ret == 0) {
/* all finished. rename the source directory to mark the
move as finished. */
bool is_file;
&is_file);
i_error("Mailbox conversion: "
/* return success anyway */
}
}
ret = 1;
}
return ret;
}