Mercurial > dovecot > core-2.2
changeset 9509:15e427021619 HEAD
Added mailbox_save_copy_flags(). Use it wherever possible.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 22 Jun 2009 17:58:23 -0400 |
parents | 094ad127d132 |
children | 5ef9cca6fa27 |
files | src/imap/cmd-copy.c src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/plugins/convert/convert-storage.c src/plugins/lazy-expunge/lazy-expunge-plugin.c |
diffstat | 5 files changed, 39 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/cmd-copy.c Mon Jun 22 17:45:56 2009 -0400 +++ b/src/imap/cmd-copy.c Mon Jun 22 17:58:23 2009 -0400 @@ -27,7 +27,7 @@ } } -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 @@ 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 @@ 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 @@ 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)
--- a/src/lib-storage/mail-storage.c Mon Jun 22 17:45:56 2009 -0400 +++ b/src/lib-storage/mail-storage.c Mon Jun 22 17:58:23 2009 -0400 @@ -916,6 +916,19 @@ { 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_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)
--- a/src/lib-storage/mail-storage.h Mon Jun 22 17:45:56 2009 -0400 +++ b/src/lib-storage/mail-storage.h Mon Jun 22 17:58:23 2009 -0400 @@ -490,6 +490,8 @@ 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. */
--- a/src/plugins/convert/convert-storage.c Mon Jun 22 17:45:56 2009 -0400 +++ b/src/plugins/convert/convert-storage.c Mon Jun 22 17:58:23 2009 -0400 @@ -60,25 +60,15 @@ 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;
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c Mon Jun 22 17:45:56 2009 -0400 +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c Mon Jun 22 17:58:23 2009 -0400 @@ -131,8 +131,7 @@ 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 @@ } 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); }