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__)
stream->istream.v_offset +
(stream->pos - stream->skip);
}
- stream->istream.eof = rstream->next_eof;
return -1;
}
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;
}
/* 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;
}
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)
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)
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 &&
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;
+}
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));
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 */
}
}
- 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);
{
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;
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);
&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,
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)