}
}
-static int fetch_and_copy(struct client *client, struct mailbox *destbox,
+static int fetch_and_copy(struct client *client,
struct mailbox_transaction_context *t,
struct mail_search_args *search_args,
const char **src_uidset_r,
struct mail_search_context *search_ctx;
struct mailbox_transaction_context *src_trans;
struct mail_save_context *save_ctx;
- struct mail_keywords *keywords;
- const char *const *keywords_list;
struct mail *mail;
unsigned int copy_count = 0;
struct msgset_generator_context srcset_ctx;
if ((++copy_count % COPY_CHECK_INTERVAL) == 0)
client_send_sendalive_if_needed(client);
- keywords_list = mail_get_keywords(mail);
- keywords = str_array_length(keywords_list) == 0 ? NULL :
- mailbox_keywords_create_valid(destbox, keywords_list);
-
save_ctx = mailbox_save_alloc(t);
- mailbox_save_set_flags(save_ctx, mail_get_flags(mail),
- keywords);
+ mailbox_save_copy_flags(save_ctx, mail);
if (mailbox_copy(&save_ctx, mail) < 0)
ret = mail->expunged ? 0 : -1;
- if (keywords != NULL)
- mailbox_keywords_unref(destbox, &keywords);
msgset_generator_next(&srcset_ctx, mail->uid);
}
t = mailbox_transaction_begin(destbox,
MAILBOX_TRANSACTION_FLAG_EXTERNAL |
MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS);
- ret = fetch_and_copy(client, destbox, t, search_args,
- &src_uidset, ©_count);
+ ret = fetch_and_copy(client, t, search_args, &src_uidset, ©_count);
mail_search_args_unref(&search_args);
if (ret <= 0)
{
ctx->flags = flags;
ctx->keywords = keywords;
+ if (keywords != NULL)
+ mailbox_keywords_ref(ctx->transaction->box, keywords);
+}
+
+void mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *mail)
+{
+ const char *const *keywords_list;
+
+ keywords_list = mail_get_keywords(mail);
+ ctx->keywords = str_array_length(keywords_list) == 0 ? NULL :
+ mailbox_keywords_create_valid(ctx->transaction->box,
+ keywords_list);
+ ctx->flags = mail_get_flags(mail);
}
void mailbox_save_set_received_date(struct mail_save_context *ctx,
int mailbox_save_finish(struct mail_save_context **_ctx)
{
struct mail_save_context *ctx = *_ctx;
+ struct mailbox *box = ctx->transaction->box;
+ struct mail_keywords *keywords = ctx->keywords;
+ int ret;
*_ctx = NULL;
- return ctx->transaction->box->v.save_finish(ctx);
+ ret = box->v.save_finish(ctx);
+ if (keywords != NULL)
+ mailbox_keywords_unref(box, &keywords);
+ return ret;
}
void mailbox_save_cancel(struct mail_save_context **_ctx)
{
struct mail_save_context *ctx = *_ctx;
+ struct mailbox *box = ctx->transaction->box;
+ struct mail_keywords *keywords = ctx->keywords;
*_ctx = NULL;
ctx->transaction->box->v.save_cancel(ctx);
+ if (keywords != NULL)
+ mailbox_keywords_unref(box, &keywords);
}
int mailbox_copy(struct mail_save_context **_ctx, struct mail *mail)
{
struct mail_save_context *ctx = *_ctx;
+ struct mailbox *box = ctx->transaction->box;
+ struct mail_keywords *keywords = ctx->keywords;
+ int ret;
*_ctx = NULL;
- return ctx->transaction->box->v.copy(ctx, mail);
+ ret = ctx->transaction->box->v.copy(ctx, mail);
+ if (keywords != NULL)
+ mailbox_keywords_unref(box, &keywords);
+ return ret;
}
bool mailbox_is_inconsistent(struct mailbox *box)
void mailbox_save_set_flags(struct mail_save_context *ctx,
enum mail_flags flags,
struct mail_keywords *keywords);
+/* Copy flags and keywords from given mail. */
+void mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *mail);
/* If received date isn't specified the current time is used. timezone_offset
specifies the preferred timezone in minutes, but it may be ignored if
backend doesn't support storing it. */
MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY |
MAIL_FETCH_FROM_ENVELOPE, NULL);
while (mailbox_search_next(ctx, mail) > 0) {
- struct mail_keywords *keywords;
- const char *const *keywords_list;
-
if ((mail->seq % 100) == 0) {
/* touch the lock file so that if there are tons of
mails another process won't override our lock. */
(void)file_dotlock_touch(dotlock);
}
- keywords_list = mail_get_keywords(mail);
- keywords = str_array_length(keywords_list) == 0 ? NULL :
- mailbox_keywords_create_valid(destbox, keywords_list);
-
save_ctx = mailbox_save_alloc(dest_trans);
- mailbox_save_set_flags(save_ctx, mail_get_flags(mail),
- keywords);
+ mailbox_save_copy_flags(save_ctx, mail);
ret = mailbox_copy(&save_ctx, mail);
- if (keywords != NULL)
- mailbox_keywords_unref(destbox, &keywords);
if (ret < 0) {
*error_r = storage_error(destbox->storage);
break;
LAZY_EXPUNGE_CONTEXT(_mail->transaction);
struct mail_namespace *dest_ns;
struct mail_save_context *save_ctx;
- struct mail_keywords *keywords;
- const char *const *keywords_list, *error;
+ const char *error;
dest_ns = get_lazy_ns(ns->user, LAZY_NAMESPACE_EXPUNGE);
if (lt->dest_box == NULL) {
}
save_ctx = mailbox_save_alloc(lt->dest_trans);
- keywords_list = mail_get_keywords(_mail);
- keywords = str_array_length(keywords_list) == 0 ? NULL :
- mailbox_keywords_create_valid(lt->dest_box, keywords_list);
- mailbox_save_set_flags(save_ctx, mail_get_flags(_mail),
- keywords);
-
+ mailbox_save_copy_flags(save_ctx, _mail);
if (mailbox_copy(&save_ctx, _mail) < 0 && !_mail->expunged)
lt->failed = TRUE;
- if (keywords != NULL)
- mailbox_keywords_unref(lt->dest_box, &keywords);
-
mmail->super.expunge(_mail);
}