dovecot-2.0: Added mailbox_save_copy_flags(). Use it wherever po...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jun 23 00:58:33 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/15e427021619
changeset: 9509:15e427021619
user: Timo Sirainen <tss at iki.fi>
date: Mon Jun 22 17:58:23 2009 -0400
description:
Added mailbox_save_copy_flags(). Use it wherever possible.
diffstat:
5 files changed, 39 insertions(+), 37 deletions(-)
src/imap/cmd-copy.c | 16 ++---------
src/lib-storage/mail-storage.c | 33 ++++++++++++++++++++++--
src/lib-storage/mail-storage.h | 2 +
src/plugins/convert/convert-storage.c | 12 --------
src/plugins/lazy-expunge/lazy-expunge-plugin.c | 13 +--------
diffs (192 lines):
diff -r 094ad127d132 -r 15e427021619 src/imap/cmd-copy.c
--- 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 void client_send_sendalive_if_nee
}
}
-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
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
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_cont
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 -r 094ad127d132 -r 15e427021619 src/lib-storage/mail-storage.c
--- 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 @@ void mailbox_save_set_flags(struct mail_
{
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
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 -r 094ad127d132 -r 15e427021619 src/lib-storage/mail-storage.h
--- 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_
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 -r 094ad127d132 -r 15e427021619 src/plugins/convert/convert-storage.c
--- 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 @@ static int mailbox_copy_mails(struct mai
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 -r 094ad127d132 -r 15e427021619 src/plugins/lazy-expunge/lazy-expunge-plugin.c
--- 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 @@ static void lazy_expunge_mail_expunge(st
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(st
}
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);
}
More information about the dovecot-cvs
mailing list