# HG changeset patch # User Timo Sirainen # Date 1030190609 -10800 # Node ID 6cefb1763f3eaa230fb6b4fbcc7080a3daee6d58 # Parent a946ce1f09b7c2d913fd75ee44b33a7b211ae60e mbox fixes, fsck and sync seems to work now. diff -r a946ce1f09b7 -r 6cefb1763f3e src/lib-index/mbox/mbox-fsck.c --- a/src/lib-index/mbox/mbox-fsck.c Sat Aug 24 05:04:45 2002 +0300 +++ b/src/lib-index/mbox/mbox-fsck.c Sat Aug 24 15:03:29 2002 +0300 @@ -37,7 +37,7 @@ { MessageSize hdr_size; MboxHeaderContext ctx; - off_t old_offset; + off_t body_offset; unsigned char *data, current_digest[16], old_digest[16]; unsigned int size; const char *md5sum; @@ -51,8 +51,8 @@ message_parse_header(NULL, inbuf, &hdr_size, mbox_header_func, &ctx); md5_final(&ctx.md5, current_digest); + body_offset = inbuf->offset; do { - old_offset = inbuf->offset; do { /* MD5 sums must match */ md5sum = index->lookup_field(index, rec, @@ -66,7 +66,7 @@ /* don't bother parsing the whole body, just make sure it ends properly */ - io_buffer_skip(inbuf, rec->body_size); + io_buffer_seek(inbuf, body_offset + rec->body_size); if (inbuf->offset == inbuf->size) { /* last message */ @@ -89,10 +89,6 @@ return rec; } while (0); - /* get back to beginning of message body */ - if (inbuf->offset != old_offset) - io_buffer_seek(inbuf, old_offset); - /* try next message */ (*seq)++; (void)index->expunge(index, rec, *seq, TRUE); @@ -105,6 +101,7 @@ static int mbox_index_fsck_buf(MailIndex *index, IOBuffer *inbuf) { MailIndexRecord *rec; + off_t from_offset; unsigned char *data; unsigned int seq, size; @@ -135,6 +132,7 @@ rec = index->lookup(index, 1); while (rec != NULL) { + from_offset = inbuf->offset; if (inbuf->offset != 0) { /* we're at the [\r]\n before the From-line, skip it */ @@ -149,8 +147,11 @@ break; rec = match_next_record(index, rec, &seq, inbuf); - if (rec == NULL) + if (rec == NULL) { + /* Get back to line before From */ + io_buffer_seek(inbuf, from_offset); break; + } seq++; rec = index->next(index, rec); diff -r a946ce1f09b7 -r 6cefb1763f3e src/lib-index/mbox/mbox-sync.c --- a/src/lib-index/mbox/mbox-sync.c Sat Aug 24 05:04:45 2002 +0300 +++ b/src/lib-index/mbox/mbox-sync.c Sat Aug 24 15:03:29 2002 +0300 @@ -2,6 +2,7 @@ #include "lib.h" #include "iobuffer.h" +#include "hex-binary.h" #include "mbox-index.h" #include "mail-index-util.h" @@ -14,7 +15,7 @@ { MailIndexRecord *rec, *prev; const char *location; - unsigned long size; + off_t size; if (index->lock_type == MAIL_LOCK_UNLOCK) { if (!mail_index_set_lock(index, MAIL_LOCK_SHARED)) @@ -44,15 +45,21 @@ index_set_error(index, "Corrupted index file %s: " "Missing location field for record %u", index->filepath, rec->uid); + } else if (strlen(location) != sizeof(size)*2 || + hex_to_binary(location, + (unsigned char *) &size) <= 0) { + INDEX_MARK_CORRUPTED(index); + index_set_error(index, "Corrupted index file %s: " + "Invalid location field for record %u", + index->filepath, rec->uid); } else { - size = strtoul(location, NULL, 10) + - rec->header_size + rec->body_size; + size += rec->header_size + rec->body_size; } } if (index->lock_type == MAIL_LOCK_SHARED) (void)mail_index_set_lock(index, MAIL_LOCK_UNLOCK); - return (off_t)size; + return size; } static int mbox_check_new_mail(MailIndex *index)