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') {
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);
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)
// 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);
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
/* 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)
if (sync_ctx->sync_rec.uid1 == 0) {
/* nothing to do */
+ mbox_sync_fake_headers(sync_ctx);
return 0;
}
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;
return -1;
}
+ sync_ctx->expunged_space = 0;
istream_raw_mbox_flush(sync_ctx->input);
}
return 0;
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)
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;