From: Timo Sirainen Date: Mon, 22 Jun 2009 21:58:23 +0000 (-0400) Subject: Added mailbox_save_copy_flags(). Use it wherever possible. X-Git-Tag: 2.0.alpha1~543 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48f9069853ebb59fd9fe22ab1647cf735e6bbe37;p=thirdparty%2Fdovecot%2Fcore.git Added mailbox_save_copy_flags(). Use it wherever possible. --HG-- branch : HEAD --- diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index d9fed38302..ff18a00e9f 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -27,7 +27,7 @@ static void client_send_sendalive_if_needed(struct client *client) } } -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, @@ -36,8 +36,6 @@ static int fetch_and_copy(struct client *client, struct mailbox *destbox, 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; @@ -62,18 +60,11 @@ static int fetch_and_copy(struct client *client, struct mailbox *destbox, 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); } @@ -145,8 +136,7 @@ bool cmd_copy(struct client_command_context *cmd) 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) diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 48fa1c4f33..5f7c36b373 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -916,6 +916,19 @@ void mailbox_save_set_flags(struct mail_save_context *ctx, { 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, @@ -974,25 +987,41 @@ int mailbox_save_continue(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) diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 99fb0adec2..e020068df9 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -490,6 +490,8 @@ mailbox_save_alloc(struct mailbox_transaction_context *t); 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. */ diff --git a/src/plugins/convert/convert-storage.c b/src/plugins/convert/convert-storage.c index 9c337475ca..31a46c3a94 100644 --- a/src/plugins/convert/convert-storage.c +++ b/src/plugins/convert/convert-storage.c @@ -60,25 +60,15 @@ static int mailbox_copy_mails(struct mailbox *srcbox, struct mailbox *destbox, 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; diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index a823ee3bc8..bb4516f3ca 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -131,8 +131,7 @@ static void lazy_expunge_mail_expunge(struct mail *_mail) 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) { @@ -158,17 +157,9 @@ static void lazy_expunge_mail_expunge(struct mail *_mail) } 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); }