]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fixes for From-line offset updating
authorTimo Sirainen <tss@iki.fi>
Sun, 20 Jun 2004 13:48:34 +0000 (16:48 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 20 Jun 2004 13:48:34 +0000 (16:48 +0300)
--HG--
branch : HEAD

src/lib-storage/index/mbox/mbox-sync-parse.c
src/lib-storage/index/mbox/mbox-sync-private.h
src/lib-storage/index/mbox/mbox-sync-rewrite.c
src/lib-storage/index/mbox/mbox-sync.c

index 396e5c41e0d1a41a8212cb30d6869ded968a1e2b..73fbd330734e9bb21e0eb8ec8b9eed3f9d88e4a6 100644 (file)
@@ -274,8 +274,7 @@ static struct header_func *header_func_find(const char *header)
 }
 
 void mbox_sync_parse_next_mail(struct istream *input,
-                              struct mbox_sync_mail_context *ctx,
-                              int rewriting)
+                              struct mbox_sync_mail_context *ctx)
 {
        struct mbox_sync_context *sync_ctx = ctx->sync_ctx;
        struct message_header_parser_ctx *hdr_ctx;
index cbfdc14008d05a4092d665b7f300fadd43cf8f06..ca172c39674f977fded021dc835fee244506ecb2 100644 (file)
@@ -91,7 +91,7 @@ struct mbox_sync_context {
        struct mail_index_sync_rec sync_rec;
 
        uint32_t prev_msg_uid, next_uid;
-       uint32_t seq, idx_seq, need_space_seq;
+       uint32_t seq, idx_seq, need_space_seq, need_space_idx_seq;
        off_t expunged_space, space_diff;
 
        unsigned int dest_first_mail:1;
@@ -103,8 +103,7 @@ int mbox_sync(struct index_mailbox *ibox, int last_commit,
 int mbox_sync_has_changed(struct index_mailbox *ibox);
 
 void mbox_sync_parse_next_mail(struct istream *input,
-                              struct mbox_sync_mail_context *ctx,
-                              int rewriting);
+                              struct mbox_sync_mail_context *ctx);
 void mbox_sync_update_header(struct mbox_sync_mail_context *ctx,
                             buffer_t *syncs_buf);
 void mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
index 2b27d87759cd5f203478d293b079b18823107b06..71139cc54e2fe3a678154bce09aefb531fb64e0e 100644 (file)
@@ -301,7 +301,7 @@ static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
        sync_ctx->prev_msg_uid = mails[idx].uid-1;
        sync_ctx->dest_first_mail = mails[idx].from_offset == 0;
 
-       mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx, TRUE);
+       mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx);
        if (mails[idx].space != 0)
                mbox_sync_update_header_from(&mail_ctx, &mails[idx]);
        else {
index 394c08f5216b03e314d4e7313ab9637ebf591b9f..11f3327e632c2a2f7e79d41083b7dff28fcba1ba 100644 (file)
@@ -212,7 +212,7 @@ mbox_sync_read_next_mail(struct mbox_sync_context *sync_ctx,
                mail_ctx->from_offset++;
        }
 
-       mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx, FALSE);
+       mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx);
        i_assert(sync_ctx->input->v_offset != mail_ctx->from_offset);
 
        mail_ctx->mail.body_size =
@@ -478,25 +478,30 @@ mbox_write_from_line(struct mbox_sync_mail_context *ctx, off_t move_diff)
        return 0;
 }
 
-static void
-update_from_offsets(struct index_mailbox *ibox,
-                   struct mail_index_transaction *t, buffer_t *mails_buf,
-                   uint32_t seq1, uint32_t seq2)
+static void update_from_offsets(struct mbox_sync_context *sync_ctx)
 {
        const struct mbox_sync_mail *mails;
-       uint32_t extra_idx = ibox->mbox_extra_idx;
+       uint32_t idx, idx_seq, extra_idx = sync_ctx->ibox->mbox_extra_idx;
        uint64_t offset;
        size_t size;
 
-       mails = buffer_get_modifyable_data(mails_buf, &size);
-       i_assert((seq2-seq1+1) * sizeof(*mails) == size);
+       mails = buffer_get_modifyable_data(sync_ctx->mails, &size);
+       size /= sizeof(*mails);
+       i_assert(sync_ctx->need_space_seq - sync_ctx->seq + 1 == size);
 
-       for (; seq1 <= seq2; seq1++, mails++) {
-               if (mails->uid != 0) {
-                       offset = mails->from_offset;
-                       mail_index_update_extra_rec(t, seq1, extra_idx,
-                                                   &offset);
-               }
+       idx = 0;
+       idx_seq = sync_ctx->need_space_idx_seq;
+       if (idx_seq == 0) {
+               idx++; idx_seq++;
+       }
+
+       for (; idx < size; idx++, idx_seq++, mails++) {
+               if (mails->uid == 0)
+                       continue;
+
+               offset = mails->from_offset;
+               mail_index_update_extra_rec(sync_ctx->t, idx_seq, extra_idx,
+                                           &offset);
        }
 }
 
@@ -586,6 +591,7 @@ static int mbox_sync_handle_header(struct mbox_sync_mail_context *mail_ctx)
        if (ret == 0 && sync_ctx->need_space_seq == 0) {
                /* first mail with no space to write it */
                sync_ctx->need_space_seq = sync_ctx->seq;
+               sync_ctx->need_space_idx_seq = sync_ctx->idx_seq;
                sync_ctx->space_diff = 0;
 
                if (sync_ctx->expunged_space > 0) {
@@ -633,8 +639,7 @@ mbox_sync_handle_missing_space(struct mbox_sync_mail_context *mail_ctx)
                              sync_ctx->need_space_seq, sync_ctx->seq) < 0)
                return -1;
 
-       update_from_offsets(sync_ctx->ibox, sync_ctx->t, sync_ctx->mails,
-                           sync_ctx->need_space_seq, sync_ctx->seq);
+       update_from_offsets(sync_ctx);
 
        /* mail_ctx may contain wrong data after rewrite, so make sure we
           don't try to access it */
@@ -870,9 +875,7 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx,
                                return -1;
                }
 
-               update_from_offsets(sync_ctx->ibox, sync_ctx->t,
-                                   sync_ctx->mails,
-                                   sync_ctx->need_space_seq, sync_ctx->seq);
+               update_from_offsets(sync_ctx);
 
                sync_ctx->need_space_seq = 0;
                buffer_set_used_size(sync_ctx->mails, 0);