changeset 256:73a5f8a34893 HEAD

mail_index_lookup() didn't always return correct record..
author Timo Sirainen <tss@iki.fi>
date Mon, 16 Sep 2002 10:39:26 +0300
parents 518f63be3723
children 90abe1af4c72
files src/lib-index/mail-index.c
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Mon Sep 16 09:50:41 2002 +0300
+++ b/src/lib-index/mail-index.c	Mon Sep 16 10:39:26 2002 +0300
@@ -502,27 +502,35 @@
 	}
 
 	/* we need to walk through the index to get to wanted position */
-	if (seq > index->last_lookup_seq && index->last_lookup != NULL) {
+
+	/* some mails are deleted, jump after the first known hole
+	   and start counting non-deleted messages.. */
+	rec_seq = INDEX_POSITION_INDEX(hdr->first_hole_position+1) + 1;
+	rec += rec_seq-1 + hdr->first_hole_records;
+
+	if (seq > index->last_lookup_seq && index->last_lookup_seq > rec_seq) {
 		/* we want to lookup data after last lookup -
 		   this helps us some */
 		rec = index->last_lookup;
 		rec_seq = index->last_lookup_seq;
-	} else {
-		/* some mails are deleted, jump after the first known hole
-		   and start counting non-deleted messages.. */
-		rec_seq = INDEX_POSITION_INDEX(hdr->first_hole_position+1) + 1;
-		rec += rec_seq-1 + hdr->first_hole_records;
 	}
 
+	i_assert(rec->uid != 0);
+
 	while (rec_seq < seq && rec <= last_rec) {
+		rec++;
+
 		if (rec->uid != 0)
 			rec_seq++;
-		rec++;
 	}
 
-	index->last_lookup = rec;
-	index->last_lookup_seq = rec_seq;
-	return rec_seq == seq ? rec : NULL;
+	if (rec_seq != seq)
+		return NULL;
+	else {
+		index->last_lookup = rec;
+		index->last_lookup_seq = rec_seq;
+		return rec;
+	}
 }
 
 MailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec)