From: Timo Sirainen Date: Sun, 20 Jun 2004 13:48:34 +0000 (+0300) Subject: fixes for From-line offset updating X-Git-Tag: 1.1.alpha1~3892 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5c08648676d1989f6e70b95e5990c26b3e8b96b;p=thirdparty%2Fdovecot%2Fcore.git fixes for From-line offset updating --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/mbox/mbox-sync-parse.c b/src/lib-storage/index/mbox/mbox-sync-parse.c index 396e5c41e0..73fbd33073 100644 --- a/src/lib-storage/index/mbox/mbox-sync-parse.c +++ b/src/lib-storage/index/mbox/mbox-sync-parse.c @@ -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; diff --git a/src/lib-storage/index/mbox/mbox-sync-private.h b/src/lib-storage/index/mbox/mbox-sync-private.h index cbfdc14008..ca172c3967 100644 --- a/src/lib-storage/index/mbox/mbox-sync-private.h +++ b/src/lib-storage/index/mbox/mbox-sync-private.h @@ -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, diff --git a/src/lib-storage/index/mbox/mbox-sync-rewrite.c b/src/lib-storage/index/mbox/mbox-sync-rewrite.c index 2b27d87759..71139cc54e 100644 --- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c +++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c @@ -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 { diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index 394c08f521..11f3327e63 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -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);