[dovecot-cvs] dovecot/src/lib-storage/index index-copy.c,1.17,1.18 index-fetch.c,1.29,1.30 index-msgcache.c,1.10,1.11 index-search.c,1.34,1.35 index-storage.c,1.16,1.17 index-storage.h,1.16,1.17

cras at procontrol.fi cras at procontrol.fi
Sun Oct 27 08:37:20 EET 2002


Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv17951/lib-storage/index

Modified Files:
	index-copy.c index-fetch.c index-msgcache.c index-search.c 
	index-storage.c index-storage.h 
Log Message:
Moved several fields from .imap.index file to .imap.index.data file. Fixed
code so that most of the fields do not need to be set when building index,
allowing the index building to be fast (just readdir()s with maildir). This
still needs some configuration and ability to update the fields whenever it
can grab exclusive lock.

Also fixed SEARCH LARGER, SMALLER and KEYWORD.



Index: index-copy.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-copy.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- index-copy.c	24 Oct 2002 00:15:39 -0000	1.17
+++ index-copy.c	27 Oct 2002 06:37:18 -0000	1.18
@@ -19,15 +19,16 @@
 {
 	CopyContext *ctx = context;
 	IBuffer *inbuf;
+	time_t internal_date;
 	int failed, deleted;
 
-	inbuf = index->open_mail(index, rec, &deleted);
+	inbuf = index->open_mail(index, rec, &internal_date, &deleted);
 	if (inbuf == NULL)
 		return FALSE;
 
 	/* save it in destination mailbox */
 	failed = !ctx->dest->save(ctx->dest, rec->msg_flags,
-				  ctx->custom_flags, rec->internal_date, 0,
+				  ctx->custom_flags, internal_date, 0,
 				  inbuf, inbuf->v_size);
 
 	i_buffer_unref(inbuf);

Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- index-fetch.c	20 Oct 2002 00:17:21 -0000	1.29
+++ index-fetch.c	27 Oct 2002 06:37:18 -0000	1.30
@@ -14,6 +14,23 @@
 
 #include <unistd.h>
 
+static int index_fetch_internaldate(MailIndexRecord *rec, FetchContext *ctx)
+{
+	time_t date;
+
+	date = imap_msgcache_get_internal_date(ctx->cache);
+	if (date != (time_t)-1) {
+		t_string_printfa(ctx->str, "INTERNALDATE \"%s\" ",
+				 imap_to_datetime(date));
+		return TRUE;
+	} else {
+		mail_storage_set_critical(ctx->storage,
+			"Couldn't generate INTERNALDATE for UID %u (index %s)",
+			rec->uid, ctx->index->filepath);
+		return FALSE;
+	}
+}
+
 static int index_fetch_body(MailIndexRecord *rec, FetchContext *ctx)
 {
 	const char *body;
@@ -65,18 +82,17 @@
 
 static int index_fetch_rfc822_size(MailIndexRecord *rec, FetchContext *ctx)
 {
-	MessageSize hdr_size, body_size;
+	uoff_t size;
 
-	if (!imap_msgcache_get_rfc822(ctx->cache, NULL,
-				      &hdr_size, &body_size)) {
+	size = imap_msgcache_get_virtual_size(ctx->cache);
+	if (size == (uoff_t)-1) {
 		mail_storage_set_critical(ctx->storage,
 			"Couldn't get RFC822.SIZE for UID %u (index %s)",
 			rec->uid, ctx->index->filepath);
 		return FALSE;
 	}
 
-	t_string_printfa(ctx->str, "RFC822.SIZE %"PRIuUOFF_T" ",
-			 hdr_size.virtual_size + body_size.virtual_size);
+	t_string_printfa(ctx->str, "RFC822.SIZE %"PRIuUOFF_T" ", size);
 	return TRUE;
 }
 
@@ -95,12 +111,6 @@
 					  ctx->custom_flags_count));
 }
 
-static void index_fetch_internaldate(MailIndexRecord *rec, FetchContext *ctx)
-{
-	t_string_printfa(ctx->str, "INTERNALDATE \"%s\" ",
-			 imap_to_datetime(rec->internal_date));
-}
-
 static void index_fetch_uid(MailIndexRecord *rec, FetchContext *ctx)
 {
 	t_string_printfa(ctx->str, "UID %u ", rec->uid);
@@ -194,11 +204,11 @@
 		field |= IMAP_CACHE_BODYSTRUCTURE;
 	if (fetch_data->envelope)
 		field |= IMAP_CACHE_ENVELOPE;
+	if (fetch_data->internaldate)
+		field |= IMAP_CACHE_INTERNALDATE;
 
-	if (fetch_data->rfc822_size) {
-		field |= IMAP_CACHE_MESSAGE_HDR_SIZE |
-			IMAP_CACHE_MESSAGE_BODY_SIZE;
-	}
+	if (fetch_data->rfc822_size)
+		field |= IMAP_CACHE_VIRTUAL_SIZE;
 	if (fetch_data->rfc822) {
 		field |= IMAP_CACHE_MESSAGE_OPEN | IMAP_CACHE_MESSAGE_HDR_SIZE |
 			IMAP_CACHE_MESSAGE_BODY_SIZE;
@@ -215,33 +225,15 @@
 	return field;
 }
 
-static int index_msgcache_open(FetchContext *ctx, MailIndexRecord *rec)
+static int fetch_msgcache_open(FetchContext *ctx, MailIndexRecord *rec)
 {
 	ImapCacheField fields;
-	uoff_t virtual_header_size, virtual_body_size;
-	void *mail_cache_context;
 
 	fields = index_get_cache(ctx->fetch_data);
 	if (fields == 0)
 		return TRUE;
 
-	mail_cache_context = index_msgcache_get_context(ctx->index, rec);
-
-	if (rec->header_size == 0) {
-		virtual_header_size = 0;
-		virtual_body_size = 0;
-	} else {
-		virtual_header_size =
-			(rec->index_flags & INDEX_MAIL_FLAG_BINARY_HEADER) ?
-			rec->header_size : 0;
-		virtual_body_size =
-			(rec->index_flags & INDEX_MAIL_FLAG_BINARY_BODY) ?
-			rec->body_size : 0;
-	}
-
-	return imap_msgcache_open(ctx->cache, rec->uid, fields,
-				  virtual_header_size, virtual_body_size,
-				  mail_cache_context);
+	return index_msgcache_open(ctx->cache, ctx->index, rec, fields);
 }
 
 static int index_fetch_mail(MailIndex *index __attr_unused__,
@@ -258,7 +250,7 @@
 	/* first see what we need to do. this way we don't first do some
 	   light parsing and later notice that we need to do heavier parsing
 	   anyway */
-	if (!index_msgcache_open(ctx, rec)) {
+	if (!fetch_msgcache_open(ctx, rec)) {
 		/* most likely message not found, just ignore it. */
 		imap_msgcache_close(ctx->cache);
 		ctx->failed = TRUE;
@@ -286,10 +278,11 @@
 			index_fetch_uid(rec, ctx);
 		if (ctx->fetch_data->flags || fetch_flags)
 			index_fetch_flags(rec, ctx);
-		if (ctx->fetch_data->internaldate)
-			index_fetch_internaldate(rec, ctx);
 
 		/* rest can */
+		if (ctx->fetch_data->internaldate)
+			if (!index_fetch_internaldate(rec, ctx))
+				break;
 		if (ctx->fetch_data->body)
 			if (!index_fetch_body(rec, ctx))
 				break;

Index: index-msgcache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-msgcache.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- index-msgcache.c	20 Oct 2002 01:36:46 -0000	1.10
+++ index-msgcache.c	27 Oct 2002 06:37:18 -0000	1.11
@@ -2,26 +2,73 @@
 
 #include "lib.h"
 #include "ibuffer.h"
+#include "imap-date.h"
 #include "imap-message-cache.h"
 #include "message-part-serialize.h"
 #include "mail-index.h"
 #include "mail-index-util.h"
+#include "index-storage.h"
 
 #include <unistd.h>
 
 typedef struct {
 	MailIndex *index;
 	MailIndexRecord *rec;
+	time_t internal_date;
 } IndexMsgcacheContext;
 
-void *index_msgcache_get_context(MailIndex *index, MailIndexRecord *rec)
+int index_msgcache_open(ImapMessageCache *cache, MailIndex *index,
+			MailIndexRecord *rec, ImapCacheField fields)
 {
 	IndexMsgcacheContext *ctx;
+	uoff_t vp_header_size, vp_body_size, full_virtual_size;
+	const uoff_t *uoff_p;
+	size_t size;
 
 	ctx = t_new(IndexMsgcacheContext, 1);
 	ctx->index = index;
 	ctx->rec = rec;
-	return ctx;
+	ctx->internal_date = (time_t)-1;
+
+	full_virtual_size = (uoff_t)-1;
+	vp_header_size = (uoff_t)-1;
+	vp_body_size = (uoff_t)-1;
+
+	if ((ctx->rec->index_flags & INDEX_MAIL_FLAG_BINARY_HEADER)) {
+		uoff_p = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
+						      DATA_HDR_HEADER_SIZE,
+						      &size);
+		if (uoff_p != NULL) {
+			i_assert(size == sizeof(*uoff_p));
+			vp_header_size = *uoff_p;
+		}
+	}
+
+	if ((ctx->rec->index_flags & INDEX_MAIL_FLAG_BINARY_BODY)) {
+		uoff_p = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
+						      DATA_HDR_BODY_SIZE,
+						      &size);
+		if (uoff_p != NULL) {
+			i_assert(size == sizeof(*uoff_p));
+			vp_body_size = *uoff_p;
+		}
+	}
+
+	if (vp_header_size != (uoff_t)-1 && vp_body_size != (uoff_t)-1)
+		full_virtual_size = vp_header_size + vp_body_size;
+	else {
+		uoff_p = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
+						      DATA_HDR_VIRTUAL_SIZE,
+						      &size);
+		if (uoff_p != NULL) {
+			i_assert(size == sizeof(*uoff_p));
+			full_virtual_size = *uoff_p;
+		}
+	}
+
+	return imap_msgcache_open(cache, rec->uid, fields,
+				  vp_header_size, vp_body_size,
+				  full_virtual_size, ctx);
 }
 
 static IBuffer *index_msgcache_open_mail(void *context)
@@ -29,7 +76,8 @@
 	IndexMsgcacheContext *ctx = context;
 	int deleted;
 
-	return ctx->index->open_mail(ctx->index, ctx->rec, &deleted);
+	return ctx->index->open_mail(ctx->index, ctx->rec,
+				     &ctx->internal_date, &deleted);
 }
 
 static IBuffer *index_msgcache_inbuf_rewind(IBuffer *inbuf,
@@ -49,26 +97,43 @@
 						   void *context)
 {
 	IndexMsgcacheContext *ctx = context;
-	MailField index_field;
+	MailDataField data_field;
+	const time_t *time_p;
 	const char *ret;
+	size_t size;
 
 	switch (field) {
+	case IMAP_CACHE_INTERNALDATE:
+		if (ctx->internal_date != (time_t)-1)
+			return imap_to_datetime(ctx->internal_date);
+
+		time_p = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
+						      DATA_HDR_INTERNAL_DATE,
+						      &size);
+		if (time_p == NULL) {
+			i_assert(size == sizeof(*time_p));
+			return imap_to_datetime(*time_p);
+		} else {
+			ctx->index->cache_fields_later(ctx->index,
+						       DATA_HDR_INTERNAL_DATE);
+			return NULL;
+		}
 	case IMAP_CACHE_BODY:
-		index_field = FIELD_TYPE_BODY;
+		data_field = DATA_FIELD_BODY;
 		break;
 	case IMAP_CACHE_BODYSTRUCTURE:
-		index_field = FIELD_TYPE_BODYSTRUCTURE;
+		data_field = DATA_FIELD_BODYSTRUCTURE;
 		break;
 	case IMAP_CACHE_ENVELOPE:
-		index_field = FIELD_TYPE_ENVELOPE;
+		data_field = DATA_FIELD_ENVELOPE;
 		break;
 	default:
 		return NULL;
 	}
 
-	ret = ctx->index->lookup_field(ctx->index, ctx->rec, index_field);
+	ret = ctx->index->lookup_field(ctx->index, ctx->rec, data_field);
 	if (ret == NULL)
-		ctx->index->cache_fields_later(ctx->index, index_field);
+		ctx->index->cache_fields_later(ctx->index, data_field);
 	return ret;
 }
 
@@ -80,11 +145,11 @@
 	size_t part_size;
 
 	part_data = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
-						 FIELD_TYPE_MESSAGEPART,
+						 DATA_FIELD_MESSAGEPART,
 						 &part_size);
 	if (part_data == NULL) {
 		ctx->index->cache_fields_later(ctx->index,
-					       FIELD_TYPE_MESSAGEPART);
+					       DATA_FIELD_MESSAGEPART);
 		return NULL;
 	}
 
@@ -98,9 +163,20 @@
 	return part;
 }
 
+static time_t index_msgcache_get_internal_date(void *context)
+{
+	IndexMsgcacheContext *ctx = context;
+
+	if (ctx->internal_date != (time_t)-1)
+		return ctx->internal_date;
+
+	return ctx->index->get_internal_date(ctx->index, ctx->rec);
+}
+
 ImapMessageCacheIface index_msgcache_iface = {
 	index_msgcache_open_mail,
 	index_msgcache_inbuf_rewind,
 	index_msgcache_get_cached_field,
-	index_msgcache_get_cached_parts
+	index_msgcache_get_cached_parts,
+	index_msgcache_get_internal_date
 };

Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- index-search.c	25 Oct 2002 01:57:20 -0000	1.34
+++ index-search.c	27 Oct 2002 06:37:18 -0000	1.35
@@ -12,6 +12,7 @@
 #include "index-storage.h"
 #include "mail-index-util.h"
 #include "mail-modifylog.h"
+#include "mail-custom-flags.h"
 #include "mail-search.h"
 
 #include <stdlib.h>
@@ -26,6 +27,7 @@
 	IndexMailbox *ibox;
 	MailIndexRecord *rec;
 	unsigned int client_seq;
+	int cached;
 } SearchIndexContext;
 
 typedef struct {
@@ -105,19 +107,38 @@
 			return 0;
 
 		num = num*10 + (*str - '0');
+		str++;
 	}
 
 	return num;
 }
 
+static int search_keyword(MailIndex *index, MailIndexRecord *rec,
+			  const char *value)
+{
+	const char **custom_flags;
+	int i;
+
+	if ((rec->msg_flags & MAIL_CUSTOM_FLAGS_MASK) == 0)
+		return FALSE;
+
+	custom_flags = mail_custom_flags_list_get(index->custom_flags);
+	for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
+		if (custom_flags[i] != NULL &&
+		    strcasecmp(custom_flags[i], value) == 0) {
+			return rec->msg_flags &
+				(1 << (MAIL_CUSTOM_FLAG_1_BIT+i));
+		}
+	}
+
+	return FALSE;
+}
+
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
 static int search_arg_match_index(IndexMailbox *ibox, MailIndexRecord *rec,
 				  unsigned int client_seq,
 				  MailSearchArgType type, const char *value)
 {
-	time_t t;
-	uoff_t size, user_size;
-
 	switch (type) {
 	case SEARCH_ALL:
 		return TRUE;
@@ -142,53 +163,99 @@
 	case SEARCH_RECENT:
 		return rec->uid >= ibox->index->first_recent_uid;
 	case SEARCH_KEYWORD:
-		return FALSE;
+		return search_keyword(ibox->index, rec, value);
 
-	/* dates */
+	default:
+		return -1;
+	}
+}
+
+static void search_index_arg(MailSearchArg *arg, void *context)
+{
+	SearchIndexContext *ctx = context;
+
+	switch (search_arg_match_index(ctx->ibox, ctx->rec, ctx->client_seq,
+				       arg->type, arg->value.str)) {
+	case -1:
+		/* unknown */
+		break;
+	case 0:
+		ARG_SET_RESULT(arg, -1);
+		break;
+	default:
+		ARG_SET_RESULT(arg, 1);
+		break;
+	}
+}
+
+static ImapMessageCache *search_open_cache(SearchIndexContext *ctx)
+{
+	if (!ctx->cached) {
+		(void)index_msgcache_open(ctx->ibox->cache,
+					  ctx->ibox->index, ctx->rec, 0);
+		ctx->cached = TRUE;
+	}
+	return ctx->ibox->cache;
+}
+
+/* Returns >0 = matched, 0 = not matched, -1 = unknown */
+static int search_arg_match_cached(SearchIndexContext *ctx,
+				   MailSearchArgType type, const char *value)
+{
+	time_t internal_date, search_time;
+	uoff_t virtual_size, search_size;
+
+	switch (type) {
+	/* internal dates */
 	case SEARCH_BEFORE:
-		if (!imap_parse_date(value, &t))
-			return FALSE;
-		return rec->internal_date < t;
 	case SEARCH_ON:
-		if (!imap_parse_date(value, &t))
-			return FALSE;
-		return rec->internal_date >= t &&
-			rec->internal_date < t + 3600*24;
 	case SEARCH_SINCE:
-		if (!imap_parse_date(value, &t))
-			return FALSE;
-		return rec->internal_date >= t;
-
-	/* sizes, only with fastscanning */
-	case SEARCH_SMALLER:
-		user_size = str_to_uoff_t(value);
-		if (mail_index_get_virtual_size(ibox->index, rec, TRUE, &size))
-			return size > 0 && size < user_size;
+		internal_date = imap_msgcache_get_internal_date(
+					search_open_cache(ctx));
+		if (internal_date == (time_t)-1)
+			return -1;
 
-		/* knowing physical size may be enough */
-		if (rec->header_size + rec->body_size >= user_size)
+		if (!imap_parse_date(value, &search_time))
 			return 0;
-		return -1;
+
+		switch (type) {
+		case SEARCH_BEFORE:
+			return internal_date < search_time;
+		case SEARCH_ON:
+			return internal_date >= search_time &&
+				internal_date < search_time + 3600*24;
+		case SEARCH_SINCE:
+			return internal_date >= search_time;
+		default:
+			/* unreachable */
+			break;
+		}
+
+	/* sizes */
+	case SEARCH_SMALLER:
 	case SEARCH_LARGER:
-		user_size = str_to_uoff_t(value);
-		if (mail_index_get_virtual_size(ibox->index, rec, TRUE, &size))
-			return size > user_size;
+		virtual_size = imap_msgcache_get_virtual_size(
+					search_open_cache(ctx));
+		if (virtual_size == (uoff_t)-1)
+			return -1;
+
+		search_size = str_to_uoff_t(value);
+		if (type == SEARCH_SMALLER)
+			return virtual_size < search_size;
+		else
+			return virtual_size > search_size;
 
-		/* knowing physical size may be enough */
-		if (rec->header_size + rec->body_size > user_size)
-			return 1;
-		return -1;
 	default:
 		return -1;
 	}
 }
 
-static void search_index_arg(MailSearchArg *arg, void *context)
+static void search_cached_arg(MailSearchArg *arg, void *context)
 {
 	SearchIndexContext *ctx = context;
 
-	switch (search_arg_match_index(ctx->ibox, ctx->rec, ctx->client_seq,
-				       arg->type, arg->value.str)) {
+	switch (search_arg_match_cached(ctx, arg->type,
+					arg->value.str)) {
 	case -1:
 		/* unknown */
 		break;
@@ -244,8 +311,8 @@
 }
 
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_cached(MailIndex *index, MailIndexRecord *rec,
-				   MailSearchArgType type, const char *value)
+static int search_arg_match_envelope(MailIndex *index, MailIndexRecord *rec,
+				     MailSearchArgType type, const char *value)
 {
         ImapEnvelopeField env_field;
 	const char *envelope, *field;
@@ -287,11 +354,11 @@
 	t_push();
 
 	/* get field from hopefully cached envelope */
-	envelope = index->lookup_field(index, rec, FIELD_TYPE_ENVELOPE);
+	envelope = index->lookup_field(index, rec, DATA_FIELD_ENVELOPE);
 	if (envelope != NULL)
 		field = imap_envelope_parse(envelope, env_field);
 	else {
-		index->cache_fields_later(index, FIELD_TYPE_ENVELOPE);
+		index->cache_fields_later(index, DATA_FIELD_ENVELOPE);
 		field = NULL;
 	}
 
@@ -311,52 +378,12 @@
 	return ret;
 }
 
-static void search_cached_arg(MailSearchArg *arg, void *context)
-{
-	SearchIndexContext *ctx = context;
-
-	switch (search_arg_match_cached(ctx->ibox->index, ctx->rec,
-					arg->type, arg->value.str)) {
-	case -1:
-		/* unknown */
-		break;
-	case 0:
-		ARG_SET_RESULT(arg, -1);
-		break;
-	default:
-		ARG_SET_RESULT(arg, 1);
-		break;
-	}
-}
-
-/* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_slow(MailIndex *index, MailIndexRecord *rec,
-				 MailSearchArgType type, const char *value)
-{
-	uoff_t size;
-
-	switch (type) {
-	/* sizes, only with fastscanning */
-	case SEARCH_SMALLER:
-		if (!mail_index_get_virtual_size(index, rec, FALSE, &size))
-			return -1;
-		return size > 0 && size < str_to_uoff_t(value);
-	case SEARCH_LARGER:
-		if (!mail_index_get_virtual_size(index, rec, FALSE, &size))
-			return -1;
-		return size > str_to_uoff_t(value);
-
-	default:
-		return -1;
-	}
-}
-
-static void search_slow_arg(MailSearchArg *arg, void *context)
+static void search_envelope_arg(MailSearchArg *arg, void *context)
 {
 	SearchIndexContext *ctx = context;
 
-	switch (search_arg_match_slow(ctx->ibox->index, ctx->rec,
-				      arg->type, arg->value.str)) {
+	switch (search_arg_match_envelope(ctx->ibox->index, ctx->rec,
+					  arg->type, arg->value.str)) {
 	case -1:
 		/* unknown */
 		break;
@@ -544,8 +571,7 @@
 		search_text(arg, ctx);
 }
 
-static void search_arg_match_data(IBuffer *inbuf, uoff_t max_size,
-				  MailSearchArg *args,
+static void search_arg_match_data(IBuffer *inbuf, MailSearchArg *args,
 				  MailSearchForeachFunc search_func)
 {
 	SearchTextContext ctx;
@@ -559,8 +585,6 @@
 	mail_search_args_foreach(args, search_func, &ctx);
         max_searchword_len = ctx.max_searchword_len;
 
-	i_buffer_set_read_limit(inbuf, inbuf->v_offset + max_size);
-
 	/* do this in blocks: read data, compare it for all search words, skip
 	   for block size - (strlen(largest_searchword)-1) and continue. */
 	while (i_buffer_read_data(inbuf, &data, &size,
@@ -582,20 +606,20 @@
 	i_buffer_set_read_limit(inbuf, 0);
 }
 
-static int search_arg_match_text(IndexMailbox *ibox, MailIndexRecord *rec,
-				 MailSearchArg *args)
+static int search_arg_match_text(MailSearchArg *args, SearchIndexContext *ctx)
 {
 	IBuffer *inbuf;
 	MessageSize hdr_size;
-	int have_headers, have_body, have_text, deleted;
+	uoff_t old_limit;
+	int have_headers, have_body, have_text;
 
 	/* first check what we need to use */
 	mail_search_args_analyze(args, &have_headers, &have_body, &have_text);
 	if (!have_headers && !have_body && !have_text)
 		return TRUE;
 
-	inbuf = ibox->index->open_mail(ibox->index, rec, &deleted);
-	if (inbuf == NULL)
+	if (!imap_msgcache_get_rfc822(search_open_cache(ctx), &inbuf,
+				      have_headers ? NULL : &hdr_size, NULL))
 		return FALSE;
 
 	if (have_headers) {
@@ -608,13 +632,6 @@
 		ctx.args = args;
 		message_parse_header(NULL, inbuf, &hdr_size,
 				     search_header, &ctx);
-
-		i_assert(rec->header_size == 0 ||
-			 hdr_size.physical_size == rec->header_size);
-	} else if (rec->header_size == 0) {
-		message_get_header_size(inbuf, &hdr_size);
-	} else {
-		hdr_size.physical_size = rec->header_size;
 	}
 
 	if (have_text) {
@@ -627,8 +644,10 @@
 			}
 		}
 
-		search_arg_match_data(inbuf, hdr_size.physical_size,
-				      args, search_text_header);
+		old_limit = inbuf->v_limit;
+		i_buffer_set_read_limit(inbuf, hdr_size.physical_size);
+		search_arg_match_data(inbuf, args, search_text_header);
+		i_buffer_set_read_limit(inbuf, old_limit);
 	}
 
 	if (have_text || have_body) {
@@ -637,8 +656,7 @@
 			i_buffer_skip(inbuf, hdr_size.physical_size);
 		}
 
-		search_arg_match_data(inbuf, rec->body_size, args,
-				      search_text_body);
+		search_arg_match_data(inbuf, args, search_text_body);
 	}
 
 	i_buffer_unref(inbuf);
@@ -819,7 +837,7 @@
 	const ModifyLogExpunge *expunges;
 	unsigned int first_uid, last_uid, client_seq, expunges_before;
 	char num[MAX_LARGEST_T_STRLEN+10];
-	int found;
+	int found, failed;
 
 	if (ibox->synced_messages_count == 0)
 		return TRUE;
@@ -851,14 +869,19 @@
 
 		ctx.rec = rec;
 		ctx.client_seq = client_seq;
+		ctx.cached = FALSE;
 
 		mail_search_args_reset(args);
 
+		t_push();
 		mail_search_args_foreach(args, search_index_arg, &ctx);
 		mail_search_args_foreach(args, search_cached_arg, &ctx);
-		mail_search_args_foreach(args, search_slow_arg, &ctx);
+		mail_search_args_foreach(args, search_envelope_arg, &ctx);
+		failed = !search_arg_match_text(args, &ctx);
+                imap_msgcache_close(ibox->cache);
+		t_pop();
 
-		if (search_arg_match_text(ibox, rec, args)) {
+		if (!failed) {
 			found = TRUE;
 			for (arg = args; arg != NULL; arg = arg->next) {
 				if (arg->result != 1) {

Index: index-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- index-storage.c	20 Oct 2002 02:35:51 -0000	1.16
+++ index-storage.c	27 Oct 2002 06:37:18 -0000	1.17
@@ -76,7 +76,7 @@
 	i_assert(0);
 }
 
-static MailField get_cache_fields(const char *fields)
+static MailDataField get_data_fields(const char *fields)
 {
 	static const char *field_names[] = {
 		"Location",
@@ -89,7 +89,7 @@
 	};
 
 	char *const *arr;
-	MailField ret;
+	MailDataField ret;
 	int i;
 
 	if (fields == NULL || *fields == '\0')
@@ -115,28 +115,28 @@
 	return ret;
 }
 
-static MailField get_default_cache_fields(void)
+static MailDataField get_default_cache_fields(void)
 {
-	static MailField ret = 0;
+	static MailDataField ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
 		return ret;
 
-	ret = get_cache_fields(getenv("MAIL_CACHE_FIELDS"));
+	ret = get_data_fields(getenv("MAIL_CACHE_FIELDS"));
 	ret_set = TRUE;
 	return ret;
 }
 
-static MailField get_never_cache_fields(void)
+static MailDataField get_never_cache_fields(void)
 {
-	static MailField ret = 0;
+	static MailDataField ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
 		return ret;
 
-	ret = get_cache_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
+	ret = get_data_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
 	ret_set = TRUE;
 	return ret;
 }

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- index-storage.h	21 Oct 2002 00:09:29 -0000	1.16
+++ index-storage.h	27 Oct 2002 06:37:18 -0000	1.17
@@ -53,7 +53,8 @@
 int index_storage_save(MailStorage *storage, const char *path,
 		       IBuffer *inbuf, OBuffer *outbuf, uoff_t data_size);
 
-void *index_msgcache_get_context(MailIndex *index, MailIndexRecord *rec);
+int index_msgcache_open(ImapMessageCache *cache, MailIndex *index,
+			MailIndexRecord *rec, ImapCacheField fields);
 
 /* Mailbox methods: */
 void index_storage_set_sync_callbacks(Mailbox *box,




More information about the dovecot-cvs mailing list