From: Timo Sirainen Date: Mon, 14 Jun 2004 23:35:17 +0000 (+0300) Subject: more syncing fixes X-Git-Tag: 1.1.alpha1~3980 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db7c9201c88e3d9bee10485194ee5b0c67249916;p=thirdparty%2Fdovecot%2Fcore.git more syncing fixes --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.c b/src/lib-storage/index/mbox/istream-raw-mbox.c index a3e010269c..ed6837009d 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.c +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c @@ -140,21 +140,22 @@ static ssize_t _read(struct _istream *stream) i = 0; if (pos >= 31) { - if (memcmp(buf, "\nFrom ", 6) == 0 && - mbox_from_parse(buf+6, pos-6, - &received_time, &sender) == 0) { - rstream->next_received_time = received_time; - rstream->mail_size = stream->istream.v_offset - - rstream->hdr_offset; - - i_free(rstream->next_sender); - rstream->next_sender = sender; - i_assert(stream->pos == 0); - return -1; - } + if (memcmp(buf, "\nFrom ", 6) == 0) { + if (mbox_from_parse(buf+6, pos-6, + &received_time, &sender) == 0) { + rstream->next_received_time = received_time; + rstream->mail_size = stream->istream.v_offset - + rstream->hdr_offset; + + i_free(rstream->next_sender); + rstream->next_sender = sender; + i_assert(stream->pos == 0); + return -1; + } - /* we don't want to get stuck at invalid From-line */ - i += 6; + /* we don't want to get stuck at invalid From-line */ + i += 6; + } } else if (ret == -1) { /* last few bytes, can't contain From-line */ if (buf[pos-1] == '\n') { @@ -162,6 +163,19 @@ static ssize_t _read(struct _istream *stream) pos--; } + if (rstream->body_offset == (uoff_t)-1) { + /* find body_offset */ + for (; i < pos; i++) { + if (buf[i] == '\n' && i > 0 && + buf[i-1] == '\n') { + rstream->body_offset = + stream->istream.v_offset + + i + 1; + break; + } + } + } + ret = pos <= stream->pos ? -1 : (ssize_t) (pos - stream->pos); diff --git a/src/lib-storage/index/mbox/mbox-mail.c b/src/lib-storage/index/mbox/mbox-mail.c index 2ac5cd4ccc..2eb85f8acd 100644 --- a/src/lib-storage/index/mbox/mbox-mail.c +++ b/src/lib-storage/index/mbox/mbox-mail.c @@ -91,6 +91,7 @@ static struct istream *mbox_mail_get_stream(struct mail *_mail, struct index_mail *mail = (struct index_mail *)_mail; struct index_mail_data *data = &mail->data; struct istream *raw_stream; + uoff_t offset; if (data->stream == NULL) { if (mbox_mail_seek(mail) < 0) @@ -98,11 +99,9 @@ static struct istream *mbox_mail_get_stream(struct mail *_mail, // FIXME: need to hide the headers raw_stream = mail->ibox->mbox_stream; - (void)i_stream_read(raw_stream); /* fix v_offset */ - data->stream = i_stream_create_limit(default_pool, - raw_stream, - raw_stream->v_offset, - (uoff_t)-1); + offset = istream_raw_mbox_get_header_offset(raw_stream); + data->stream = i_stream_create_limit(default_pool, raw_stream, + offset, (uoff_t)-1); } return index_mail_init_stream(mail, hdr_size, body_size); diff --git a/src/lib-storage/index/mbox/mbox-sync-rewrite.c b/src/lib-storage/index/mbox/mbox-sync-rewrite.c index c37c101e31..a6b4c64e8b 100644 --- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c +++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c @@ -174,7 +174,11 @@ int mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff) } } - i_assert(ctx->header_first_change != (size_t)-1 || move_diff != 0); + if (ctx->header_first_change == (size_t)-1 && move_diff == 0) { + /* no changes actually. we get here if index sync record told + us to do something that was already there */ + return 1; + } if (move_diff != 0) { /* we're moving the header, forget about partial write diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index c992b2f358..51b1381c18 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -248,8 +248,11 @@ static void mbox_sync_apply_index_syncs(buffer_t *syncs_buf, uint8_t *flags, sync = buffer_get_data(syncs_buf, &size); size /= sizeof(*sync); - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { + if (sync[i].type != MAIL_INDEX_SYNC_TYPE_FLAGS) + continue; mail_index_sync_flags_apply(&sync[i], flags, keywords); + } } static int @@ -600,9 +603,20 @@ mbox_sync_seek_to_uid(struct mbox_sync_context *sync_ctx, uint32_t uid) /* set to -1, since they're always increased later */ sync_ctx->seq = sync_ctx->idx_seq = seq-1; istream_raw_mbox_seek(sync_ctx->input, offset); + (void)istream_raw_mbox_get_body_offset(sync_ctx->input); return 0; } +static void mbox_sync_fake_headers(struct mbox_sync_context *sync_ctx) +{ + /* we didn't go through everything. fake the headers and all */ + i_assert(sync_ctx->next_uid <= sync_ctx->hdr->next_uid); + + sync_ctx->next_uid = sync_ctx->hdr->next_uid; + sync_ctx->base_uid_last = sync_ctx->hdr->next_uid-1; + sync_ctx->base_uid_validity = sync_ctx->hdr->uid_validity; +} + static int mbox_sync_loop(struct mbox_sync_context *sync_ctx, struct mbox_sync_mail_context *mail_ctx, uint32_t min_message_count) @@ -625,6 +639,7 @@ static int mbox_sync_loop(struct mbox_sync_context *sync_ctx, if (sync_ctx->sync_rec.uid1 == 0) { /* nothing to do */ + mbox_sync_fake_headers(sync_ctx); return 0; } @@ -709,11 +724,7 @@ static int mbox_sync_loop(struct mbox_sync_context *sync_ctx, while (sync_ctx->idx_seq < messages_count) mail_index_expunge(sync_ctx->t, ++sync_ctx->idx_seq); } else { - /* we didn't go through everything. fake the headers and all */ - i_assert(sync_ctx->next_uid <= sync_ctx->hdr->next_uid); - sync_ctx->next_uid = sync_ctx->hdr->next_uid; - sync_ctx->base_uid_last = sync_ctx->hdr->next_uid-1; - sync_ctx->base_uid_validity = sync_ctx->hdr->uid_validity; + mbox_sync_fake_headers(sync_ctx); } return 0; @@ -790,6 +801,7 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx, return -1; } + sync_ctx->expunged_space = 0; istream_raw_mbox_flush(sync_ctx->input); } return 0; @@ -888,6 +900,16 @@ static int mbox_sync_do(struct mbox_sync_context *sync_ctx) if (mbox_sync_handle_eof_updates(sync_ctx, &mail_ctx) < 0) return -1; + /* only syncs left should be just appends (and their updates) + which weren't synced yet for some reason (crash). we'll just + ignore them, as we've overwritten them above. */ + while (mail_index_sync_next(sync_ctx->index_sync_ctx, + &sync_ctx->sync_rec) > 0) + ; + + buffer_set_used_size(sync_ctx->syncs, 0); + memset(&sync_ctx->sync_rec, 0, sizeof(sync_ctx->sync_rec)); + if (sync_ctx->base_uid_last != sync_ctx->next_uid-1) { /* rewrite X-IMAPbase header */ if (mbox_sync_check_excl_lock(sync_ctx) == -1) @@ -902,13 +924,6 @@ static int mbox_sync_do(struct mbox_sync_context *sync_ctx) return -1; } - /* only syncs left should be just appends (and their updates) - which weren't synced yet for some reason (crash). we'll just - ignore them, as we've overwritten them above. */ - while (mail_index_sync_next(sync_ctx->index_sync_ctx, - &sync_ctx->sync_rec) > 0) - ; - if (mbox_sync_update_index_header(sync_ctx) < 0) return -1;