From: Timo Sirainen Date: Fri, 18 Jun 2004 00:33:08 +0000 (+0300) Subject: Added istream_raw_mbox_is_eof() and fixed updating UIDVALIDITY in index X-Git-Tag: 1.1.alpha1~3945 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e59a1f3f095b3099478562cf3f3970a24736970;p=thirdparty%2Fdovecot%2Fcore.git Added istream_raw_mbox_is_eof() and fixed updating UIDVALIDITY in index --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 5cb9a57198..906077c8dd 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.c +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c @@ -18,7 +18,7 @@ struct raw_mbox_istream { unsigned int corrupted:1; unsigned int eom:1; - unsigned int next_eof:1; + unsigned int eof:1; }; static void _close(struct _iostream *stream __attr_unused__) @@ -139,7 +139,6 @@ static ssize_t _read(struct _istream *stream) stream->istream.v_offset + (stream->pos - stream->skip); } - stream->istream.eof = rstream->next_eof; return -1; } @@ -173,7 +172,7 @@ static ssize_t _read(struct _istream *stream) stream->pos = pos; rstream->eom = TRUE; - rstream->next_eof = TRUE; + rstream->eof = TRUE; handle_end_of_mail(rstream, pos); return ret < 0 ? _read(stream) : ret; } @@ -182,7 +181,7 @@ static ssize_t _read(struct _istream *stream) /* beginning of message, we haven't yet read our From-line */ if (mbox_read_from_line(rstream) < 0) { stream->pos = 0; - stream->istream.eof = TRUE; + rstream->eof = TRUE; rstream->corrupted = TRUE; return -1; } @@ -270,7 +269,7 @@ static void _seek(struct _istream *stream, uoff_t v_offset) rstream->input_peak_offset = 0; rstream->eom = FALSE; - rstream->next_eof = FALSE; + rstream->eof = FALSE; } struct istream *i_stream_create_raw_mbox(pool_t pool, struct istream *input) @@ -447,14 +446,13 @@ void istream_raw_mbox_next(struct istream *stream, uoff_t body_size) rstream->hdr_offset = rstream->from_offset; rstream->body_offset = (uoff_t)-1; - /* don't clear stream->eof if we don't have to */ if (stream->v_offset != rstream->from_offset) i_stream_seek(stream, rstream->from_offset); i_stream_seek(rstream->input, rstream->from_offset); rstream->input_peak_offset = 0; rstream->eom = FALSE; - rstream->next_eof = FALSE; + rstream->eof = FALSE; } int istream_raw_mbox_seek(struct istream *stream, uoff_t offset) @@ -465,7 +463,7 @@ int istream_raw_mbox_seek(struct istream *stream, uoff_t offset) rstream->corrupted = FALSE; rstream->eom = FALSE; - rstream->next_eof = FALSE; + rstream->eof = FALSE; rstream->input_peak_offset = 0; if (rstream->mail_size != (uoff_t)-1 && @@ -514,3 +512,11 @@ void istream_raw_mbox_flush(struct istream *stream) rstream->istream.skip = 0; rstream->istream.pos = 0; } + +int istream_raw_mbox_is_eof(struct istream *stream) +{ + struct raw_mbox_istream *rstream = + (struct raw_mbox_istream *)stream->real_stream; + + return rstream->eof; +} diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.h b/src/lib-storage/index/mbox/istream-raw-mbox.h index e428d6bb80..ad647cae33 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.h +++ b/src/lib-storage/index/mbox/istream-raw-mbox.h @@ -36,4 +36,7 @@ int istream_raw_mbox_seek(struct istream *stream, uoff_t offset); /* Flush all buffering. Call if you modify the mbox. */ void istream_raw_mbox_flush(struct istream *stream); +/* Returns TRUE if we've read the whole mbox. */ +int istream_raw_mbox_is_eof(struct istream *stream); + #endif diff --git a/src/lib-storage/index/mbox/mbox-sync-private.h b/src/lib-storage/index/mbox/mbox-sync-private.h index c852e690e4..d93db049dd 100644 --- a/src/lib-storage/index/mbox/mbox-sync-private.h +++ b/src/lib-storage/index/mbox/mbox-sync-private.h @@ -94,6 +94,7 @@ struct mbox_sync_context { off_t expunged_space, space_diff; unsigned int dest_first_mail:1; + unsigned int seen_first_mail:1; }; int mbox_sync(struct index_mailbox *ibox, int last_commit, int lock); diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index b48453f555..47f939f925 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -185,9 +185,9 @@ static int mbox_sync_read_next_mail(struct mbox_sync_context *sync_ctx, struct mbox_sync_mail_context *mail_ctx) { - /* set input->eof */ + /* get EOF */ (void)istream_raw_mbox_get_header_offset(sync_ctx->input); - if (sync_ctx->input->eof) + if (istream_raw_mbox_is_eof(sync_ctx->input)) return 0; memset(mail_ctx, 0, sizeof(*mail_ctx)); @@ -200,6 +200,8 @@ mbox_sync_read_next_mail(struct mbox_sync_context *sync_ctx, mail_ctx->mail.offset = istream_raw_mbox_get_header_offset(sync_ctx->input); + if (mail_ctx->seq == 1) + sync_ctx->seen_first_mail = TRUE; if (mail_ctx->seq > 1 && sync_ctx->dest_first_mail) { /* First message was expunged and this is the next one. Skip \n header */ @@ -758,7 +760,7 @@ static int mbox_sync_loop(struct mbox_sync_context *sync_ctx, } } - if (sync_ctx->input->eof) { + if (istream_raw_mbox_is_eof(sync_ctx->input)) { /* rest of the messages in index don't exist -> expunge them */ messages_count = mail_index_view_get_message_count(sync_ctx->sync_view); @@ -774,7 +776,7 @@ static int mbox_sync_handle_eof_updates(struct mbox_sync_context *sync_ctx, { uoff_t offset, extra_space, trailer_size; - if (!sync_ctx->input->eof) { + if (!istream_raw_mbox_is_eof(sync_ctx->input)) { i_assert(sync_ctx->need_space_seq == 0); i_assert(sync_ctx->expunged_space == 0); return 0; @@ -860,8 +862,8 @@ static int mbox_sync_update_index_header(struct mbox_sync_context *sync_ctx) if ((sync_ctx->base_uid_validity != 0 && sync_ctx->base_uid_validity != sync_ctx->hdr->uid_validity) || - sync_ctx->hdr->uid_validity == 0) { - if (sync_ctx->hdr->uid_validity == 0) { + (sync_ctx->hdr->uid_validity == 0 && sync_ctx->seen_first_mail)) { + if (sync_ctx->base_uid_validity == 0) { /* we couldn't rewrite X-IMAPbase because it's a read-only mbox */ i_assert(sync_ctx->ibox->mbox_readonly); @@ -872,7 +874,8 @@ static int mbox_sync_update_index_header(struct mbox_sync_context *sync_ctx) &sync_ctx->base_uid_validity, sizeof(sync_ctx->base_uid_validity)); } - if (sync_ctx->input->eof && + + if (istream_raw_mbox_is_eof(sync_ctx->input) && sync_ctx->next_uid != sync_ctx->hdr->next_uid) { i_assert(sync_ctx->next_uid != 0); mail_index_update_header(sync_ctx->t, @@ -907,7 +910,8 @@ static void mbox_sync_restart(struct mbox_sync_context *sync_ctx) sync_ctx->prev_msg_uid = 0; sync_ctx->seq = sync_ctx->idx_seq = 0; - sync_ctx->dest_first_mail = TRUE; + sync_ctx->dest_first_mail = TRUE; + sync_ctx->seen_first_mail = FALSE; } static int mbox_sync_do(struct mbox_sync_context *sync_ctx)