[dovecot-cvs]
dovecot/src/lib-storage/index/mbox istream-raw-mbox.c, 1.4,
1.5 mbox-sync-parse.c, 1.5, 1.6 mbox-sync-private.h, 1.5,
1.6 mbox-sync-rewrite.c, 1.4, 1.5 mbox-sync.c, 1.7, 1.8
cras at procontrol.fi
cras at procontrol.fi
Sun May 23 04:58:34 EEST 2004
Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv9086/lib-storage/index/mbox
Modified Files:
istream-raw-mbox.c mbox-sync-parse.c mbox-sync-private.h
mbox-sync-rewrite.c mbox-sync.c
Log Message:
mbox syncing fixes
Index: istream-raw-mbox.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/istream-raw-mbox.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/istream-raw-mbox.c 10 May 2004 15:12:38 -0000 1.4
+++ b/istream-raw-mbox.c 23 May 2004 01:58:32 -0000 1.5
@@ -105,7 +105,7 @@
const char *fromp;
char *sender, eoh_char;
time_t received_time;
- size_t i, pos;
+ size_t i, pos, new_pos;
ssize_t ret;
i_stream_seek(rstream->input, stream->istream.v_offset);
@@ -137,6 +137,8 @@
return _read(stream);
}
+ i = 0;
+
if (pos >= 31) {
if (memcmp(buf, "\nFrom ", 6) == 0 &&
mbox_from_parse(buf+6, pos-6,
@@ -150,6 +152,9 @@
i_assert(stream->pos == 0);
return -1;
}
+
+ /* 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') {
@@ -172,7 +177,7 @@
/* See if we have From-line here - note that it works right only
because all characters are different in mbox_from. */
eoh_char = rstream->body_offset == (uoff_t)-1 ? '\n' : '\0';
- for (i = 0, fromp = mbox_from; i < pos; i++) {
+ for (fromp = mbox_from; i < pos; i++) {
if (buf[i] == eoh_char && i > 0 && buf[i-1] == '\n') {
rstream->body_offset = stream->istream.v_offset + i + 1;
eoh_char = '\0';
@@ -189,12 +194,18 @@
fromp++;
}
}
- pos = i - (fromp - mbox_from);
+ new_pos = i - (fromp - mbox_from);
- ret = pos <= stream->pos ? -1 :
+ ret = new_pos <= stream->pos ? -1 :
(ssize_t) (pos - stream->pos);
stream->buffer = buf;
- stream->pos = pos;
+ stream->pos = new_pos;
+
+ if (i < pos && new_pos == stream->pos) {
+ /* beginning from From-line, try again */
+ ret = 0;
+ }
+
return ret;
}
Index: mbox-sync-parse.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/mbox-sync-parse.c 22 May 2004 00:48:45 -0000 1.5
+++ b/mbox-sync-parse.c 23 May 2004 01:58:32 -0000 1.6
@@ -130,8 +130,7 @@
}
if (space > ctx->mail.space) {
- ctx->mail.offset = ctx->hdr_offset +
- hdr->full_value_offset + i;
+ ctx->mail.offset = hdr->full_value_offset + i;
ctx->mail.space = space;
}
@@ -179,8 +178,7 @@
if (extra_space != 0 && ctx->mail.space == 0) {
/* set it only if X-Keywords hasn't been seen. spaces in X-UID
should be removed when writing X-Keywords. */
- ctx->mail.offset = ctx->hdr_offset +
- hdr->full_value_offset + space_pos;
+ ctx->mail.offset = hdr->full_value_offset + space_pos;
ctx->mail.space = extra_space;
}
return TRUE;
@@ -236,7 +234,8 @@
}
void mbox_sync_parse_next_mail(struct istream *input,
- struct mbox_sync_mail_context *ctx)
+ struct mbox_sync_mail_context *ctx,
+ int rewriting)
{
struct message_header_parser_ctx *hdr_ctx;
struct message_header_line *hdr;
@@ -283,10 +282,12 @@
}
continue;
}
+ buffer_append(ctx->header, hdr->full_value,
+ hdr->full_value_len);
+ } else {
+ buffer_append(ctx->header, hdr->value,
+ hdr->value_len);
}
-
- buffer_append(ctx->header, hdr->full_value,
- hdr->full_value_len);
if (!hdr->no_newline)
str_append_c(ctx->header, '\n');
}
@@ -296,10 +297,11 @@
/* missing X-IMAPbase */
ctx->need_rewrite = TRUE;
}
- if (ctx->mail.uid == 0) {
+ if (ctx->mail.uid == 0 && !rewriting) {
/* missing X-UID */
ctx->need_rewrite = TRUE;
ctx->mail.uid = ctx->sync_ctx->next_uid++;
+ ctx->sync_ctx->prev_msg_uid = ctx->mail.uid;
}
ctx->body_offset = input->v_offset;
Index: mbox-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/mbox-sync-private.h 9 May 2004 21:06:48 -0000 1.5
+++ b/mbox-sync-private.h 23 May 2004 01:58:32 -0000 1.6
@@ -66,7 +66,8 @@
int mbox_sync(struct index_mailbox *ibox, int last_commit);
void mbox_sync_parse_next_mail(struct istream *input,
- struct mbox_sync_mail_context *ctx);
+ struct mbox_sync_mail_context *ctx,
+ int rewriting);
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,
Index: mbox-sync-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/mbox-sync-rewrite.c 9 May 2004 21:06:48 -0000 1.4
+++ b/mbox-sync-rewrite.c 23 May 2004 01:58:32 -0000 1.5
@@ -204,7 +204,7 @@
mail_ctx.mail.offset = mails[idx].offset;
mail_ctx.mail.body_size = mails[idx].body_size;
- mbox_sync_parse_next_mail(sync_ctx->file_input, &mail_ctx);
+ mbox_sync_parse_next_mail(sync_ctx->file_input, &mail_ctx, TRUE);
mbox_sync_update_header_from(&mail_ctx, &mails[idx]);
i_assert(mail_ctx.mail.space == mails[idx].space);
@@ -249,7 +249,7 @@
{
struct mbox_sync_mail *mails;
size_t size;
- uoff_t offset, end_offset;
+ uoff_t offset, end_offset, dest_offset;
uint32_t idx, extra_per_mail;
int ret = 0;
@@ -264,7 +264,7 @@
extra_per_mail = (extra_space / (last_seq - first_seq + 1));
mails[last_seq-1].space -= extra_per_mail;
- i_assert(mails[last_seq-1].space > 0);
+ i_assert(mails[last_seq-1].space >= 0);
end_offset = mails[last_seq-1].offset + mails[last_seq-1].space;
/* start moving backwards */
@@ -288,8 +288,9 @@
move data forward so mails before us gets the extra
space (ie. we temporarily get more space to us) */
offset = mails[idx].offset + mails[idx].space;
- if (mbox_move(sync_ctx, offset + mails[idx+1].space,
- offset, end_offset - offset)) {
+ dest_offset = offset + mails[idx+1].space;
+ if (mbox_move(sync_ctx, dest_offset, offset,
+ end_offset - dest_offset)) {
// FIXME: error handling
ret = -1;
break;
Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/mbox-sync.c 22 May 2004 00:48:45 -0000 1.7
+++ b/mbox-sync.c 23 May 2004 01:58:32 -0000 1.8
@@ -116,7 +116,7 @@
mail_ctx->mail.offset =
istream_raw_mbox_get_header_offset(sync_ctx->input);
- mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx);
+ mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx, FALSE);
i_assert(sync_ctx->input->v_offset != from_offset);
mail_ctx->mail.body_size =
@@ -182,6 +182,7 @@
sync_ctx.input = ibox->mbox_stream;
sync_ctx.fd = ibox->mbox_fd;
sync_ctx.header = str_new(default_pool, 4096);
+ sync_ctx.next_uid = 1;
input = sync_ctx.input;
istream_raw_mbox_seek(input, 0);
@@ -193,11 +194,12 @@
messages_count = mail_index_view_get_message_count(sync_view);
space_diff = 0; need_space_seq = 0; idx_seq = 0; rec = NULL;
- for (seq = 1;; seq++) {
+ for (seq = 0;;) {
/* set input->eof */
(void)istream_raw_mbox_get_header_offset(input);
if (input->eof)
break;
+ seq++;
mbox_sync_next_mail(&sync_ctx, &mail_ctx, seq);
@@ -325,7 +327,6 @@
ret = -1;
break;
}
-
/* mail_ctx may contain wrong data after
rewrite, so make sure we don't try to access
it */
@@ -339,13 +340,14 @@
if (need_space_seq != 0) {
i_assert(space_diff < 0);
extra_space = MBOX_HEADER_EXTRA_SPACE *
- ((seq-1) - need_space_seq);
+ (seq - need_space_seq + 1);
+
if (mbox_sync_grow_file(&sync_ctx, &mail_ctx,
-space_diff + extra_space) < 0)
ret = -1;
else if (mbox_sync_try_rewrite(&mail_ctx) < 0)
ret = -1;
- else if (--seq != need_space_seq) {
+ else if (seq != need_space_seq) {
buffer_set_used_size(mails,
(seq-1) * sizeof(mail_ctx.mail));
buffer_append(mails, &mail_ctx.mail,
More information about the dovecot-cvs
mailing list