[dovecot-cvs] dovecot/src/lib-storage/index index-expunge.c,1.19,1.20 index-fetch.c,1.50,1.51 index-mail.c,1.13,1.14 index-mail.h,1.5,1.6 index-search.c,1.77,1.78 index-storage.c,1.38,1.39 index-storage.h,1.46,1.47

cras at procontrol.fi cras at procontrol.fi
Thu Aug 7 00:15:36 EEST 2003


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

Modified Files:
	index-expunge.c index-fetch.c index-mail.c index-mail.h 
	index-search.c index-storage.c index-storage.h 
Log Message:
Index cache file rewrite. It's not finished yet and mbox support is
completely broken. But it's getting difficult to maintain outside cvs :)



Index: index-expunge.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-expunge.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- index-expunge.c	26 Jul 2003 16:55:11 -0000	1.19
+++ index-expunge.c	6 Aug 2003 20:15:33 -0000	1.20
@@ -34,7 +34,7 @@
 				hdr->first_deleted_uid_lowwater);
 
 			/* fsck should be enough to fix it */
-			ibox->index->set_flags |= MAIL_INDEX_FLAG_FSCK;
+			ibox->index->set_flags |= MAIL_INDEX_HDR_FLAG_FSCK;
 			return FALSE;
 		}
 	} else {
@@ -144,7 +144,7 @@
 	ctx->mail.mail.seq = ctx->seq;
 	ctx->mail.mail.uid = ctx->rec->uid;
 
-	if (!index_mail_next(&ctx->mail, ctx->rec, ctx->seq)) {
+	if (index_mail_next(&ctx->mail, ctx->rec, ctx->seq, FALSE) < 0) {
 		ctx->failed = TRUE;
 		return NULL;
 	}

Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- index-fetch.c	23 Jul 2003 02:55:12 -0000	1.50
+++ index-fetch.c	6 Aug 2003 20:15:33 -0000	1.51
@@ -23,6 +23,7 @@
 struct mail_fetch_context *
 index_storage_fetch_init(struct mailbox *box,
 			 enum mail_fetch_field wanted_fields,
+			 const char *const *wanted_headers,
 			 const char *messageset, int uidset)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
@@ -41,7 +42,7 @@
 	ctx->ibox = ibox;
 	ctx->index = ibox->index;
 
-	index_mail_init(ibox, &ctx->mail, wanted_fields, NULL);
+	index_mail_init(ibox, &ctx->mail, wanted_fields, wanted_headers);
 	ctx->msgset_ctx = index_messageset_init(ibox, messageset, uidset, TRUE);
 	return ctx;
 }
@@ -55,12 +56,14 @@
 	if (all_found != NULL)
 		*all_found = ret > 0;
 
+	if (ctx->ibox->fetch_mail.pool != NULL)
+		index_mail_deinit(&ctx->ibox->fetch_mail);
+	if (ctx->mail.pool != NULL)
+		index_mail_deinit(&ctx->mail);
+
 	if (!index_storage_lock(ctx->ibox, ctx->old_lock))
 		ret = -1;
 
-	if (ctx->ibox->fetch_mail.pool != NULL)
-		index_mail_deinit(&ctx->ibox->fetch_mail);
-	index_mail_deinit(&ctx->mail);
 	i_free(ctx);
 	return ret >= 0;
 }
@@ -72,17 +75,25 @@
 
 	do {
 		msgset_mail = index_messageset_next(ctx->msgset_ctx);
-		if (msgset_mail == NULL)
-			return NULL;
+		if (msgset_mail == NULL) {
+			ret = -1;
+			break;
+		}
 
 		ctx->mail.mail.seq = msgset_mail->client_seq;
 		ctx->mail.mail.uid = msgset_mail->rec->uid;
 
 		ret = index_mail_next(&ctx->mail, msgset_mail->rec,
-				      msgset_mail->idx_seq);
+				      msgset_mail->idx_seq, FALSE);
 	} while (ret == 0);
 
-	return ret < 0 ? NULL : &ctx->mail.mail;
+	if (ret < 0) {
+		/* error or last record */
+		index_mail_deinit(&ctx->mail);
+		return NULL;
+	}
+
+	return &ctx->mail.mail;
 }
 
 static struct mail *
@@ -93,7 +104,7 @@
 		index_mail_deinit(&ibox->fetch_mail);
 
 	index_mail_init(ibox, &ibox->fetch_mail, wanted_fields, NULL);
-	if (index_mail_next(&ibox->fetch_mail, rec, idx_seq) <= 0)
+	if (index_mail_next(&ibox->fetch_mail, rec, idx_seq, FALSE) <= 0)
 		return NULL;
 
 	return &ibox->fetch_mail.mail;

Index: index-mail.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- index-mail.c	26 Jul 2003 16:33:22 -0000	1.13
+++ index-mail.c	6 Aug 2003 20:15:33 -0000	1.14
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
+#include "buffer.h"
 #include "istream.h"
 #include "str.h"
 #include "message-address.h"
@@ -11,6 +12,7 @@
 #include "mail-index.h"
 #include "mail-index-util.h"
 #include "mail-custom-flags.h"
[...1211 lines suppressed...]
+		data->save_envelope = TRUE;
+
 	t_pop();
 	return ret;
 }
 
 void index_mail_deinit(struct index_mail *mail)
 {
-	if (mail->data.stream != NULL) {
-		i_stream_unref(mail->data.stream);
-		mail->data.stream = NULL;
-	}
+	t_push();
+	index_mail_close(mail);
+	t_pop();
 
 	pool_unref(mail->pool);
-	mail->pool = NULL;
+	memset(mail, 0, sizeof(*mail));
 }

Index: index-mail.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- index-mail.h	26 Jul 2003 16:33:22 -0000	1.5
+++ index-mail.h	6 Aug 2003 20:15:33 -0000	1.6
@@ -2,6 +2,7 @@
 #define __INDEX_MAIL_H
 
 #include "message-size.h"
+#include "mail-cache.h"
 
 struct message_header_line;
 
@@ -9,18 +10,25 @@
 	struct cached_header *next;
 
 	size_t name_len;
-	const char *name, *value;
+	const char *name;
+	size_t value_idx; /* in header_data */
+
+	unsigned int parsing:1;
+	unsigned int fully_saved:1;
 };
 
 struct index_mail_data {
 	struct mail_full_flags flags;
-	time_t received_date;
+	time_t date, received_date;
 	uoff_t size;
 
-	time_t sent_time;
-	int sent_timezone;
+	enum mail_cache_field cached_fields;
+	struct mail_sent_date sent_date;
 
 	struct cached_header *headers;
+	string_t *header_data;
+	int header_idx, save_header_idx;
+
 	struct message_part *parts;
 	const char *envelope, *body, *bodystructure;
         struct message_part_envelope_data *envelope_data;
@@ -32,10 +40,13 @@
         struct message_size hdr_size, body_size;
 
 	unsigned int parse_header:1;
-	unsigned int save_sent_time:1;
+	unsigned int headers_read:1;
+	unsigned int save_cached_headers:1;
+	unsigned int save_sent_date:1;
 	unsigned int save_envelope:1;
 	unsigned int hdr_size_set:1;
 	unsigned int body_size_set:1;
+	unsigned int deleted:1;
 };
 
 struct index_mail {
@@ -49,16 +60,18 @@
 
 	enum mail_fetch_field wanted_fields;
 	const char *const *wanted_headers;
+	int wanted_headers_idx;
 };
 
 void index_mail_init(struct index_mailbox *ibox, struct index_mail *mail,
 		     enum mail_fetch_field wanted_fields,
 		     const char *const wanted_headers[]);
 int index_mail_next(struct index_mail *mail, struct mail_index_record *rec,
-		    unsigned int idx_seq);
+		    unsigned int idx_seq, int delay_open);
 void index_mail_deinit(struct index_mail *mail);
 
-void index_mail_init_parse_header(struct index_mail *mail);
+void index_mail_parse_header_init(struct index_mail *mail,
+				  const char *const *headers);
 void index_mail_parse_header(struct message_part *part,
 			     struct message_header_line *hdr, void *context);
 

Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- index-search.c	23 Jul 2003 01:44:16 -0000	1.77
+++ index-search.c	6 Aug 2003 20:15:33 -0000	1.78
@@ -8,7 +8,6 @@
 #include "message-body-search.h"
 #include "message-header-search.h"
 #include "imap-date.h"
-#include "imap-envelope.h"
 #include "index-storage.h"
 #include "index-messageset.h"
 #include "index-mail.h"
@@ -216,16 +215,17 @@
 				   enum mail_search_arg_type type,
 				   const char *value)
 {
-	time_t internal_date, search_time;
+	time_t date, search_time;
 	uoff_t virtual_size, search_size;
+	int timezone_offset;
 
 	switch (type) {
 	/* internal dates */
 	case SEARCH_BEFORE:
 	case SEARCH_ON:
 	case SEARCH_SINCE:
-		internal_date = ctx->mail->get_received_date(ctx->mail);
-		if (internal_date == (time_t)-1)
+		date = ctx->mail->get_received_date(ctx->mail);
+		if (date == (time_t)-1)
 			return -1;
 
 		if (!imap_parse_date(value, &search_time))
@@ -233,12 +233,39 @@
 
 		switch (type) {
 		case SEARCH_BEFORE:
-			return internal_date < search_time;
+			return date < search_time;
 		case SEARCH_ON:
-			return internal_date >= search_time &&
-				internal_date < search_time + 3600*24;
+			return date >= search_time &&
+				date < search_time + 3600*24;
 		case SEARCH_SINCE:
-			return internal_date >= search_time;
+			return date >= search_time;
+		default:
+			/* unreachable */
+			break;
+		}
+
+	/* sent dates */
+	case SEARCH_SENTBEFORE:
+	case SEARCH_SENTON:
+	case SEARCH_SENTSINCE:
+		/* NOTE: RFC-3501 specifies that timezone is ignored
+		   in searches. date is returned as UTC, so change it. */
+		date = ctx->mail->get_date(ctx->mail, &timezone_offset);
+		if (date == (time_t)-1)
+			return -1;
+		date += timezone_offset * 60;
+
+		if (!imap_parse_date(value, &search_time))
+			return 0;
+
+		switch (type) {
+		case SEARCH_SENTBEFORE:
+			return date < search_time;
+		case SEARCH_SENTON:
+			return date >= search_time &&
+				date < search_time + 3600*24;
+		case SEARCH_SENTSINCE:
+			return date >= search_time;
 		default:
 			/* unreachable */
 			break;
@@ -339,120 +366,6 @@
 	return arg->context;
 }
 
-/* Returns >0 = matched, 0 = not matched, -1 = unknown */
-static int search_arg_match_envelope(struct mail_search_context *ctx,
-				     struct mail_search_arg *arg)
-{
-	struct mail_index *index = ctx->ibox->index;
-	enum imap_envelope_field env_field;
-        struct header_search_context *hdr_search_ctx;
-	const char *envelope, *field;
-	int ret;
-
-	switch (arg->type) {
-	case SEARCH_SENTBEFORE:
-	case SEARCH_SENTON:
-	case SEARCH_SENTSINCE:
-                env_field = IMAP_ENVELOPE_DATE;
-		break;
-
-	case SEARCH_FROM:
-                env_field = IMAP_ENVELOPE_FROM;
-		break;
-	case SEARCH_TO:
-                env_field = IMAP_ENVELOPE_TO;
-		break;
-	case SEARCH_CC:
-                env_field = IMAP_ENVELOPE_CC;
-		break;
-	case SEARCH_BCC:
-                env_field = IMAP_ENVELOPE_BCC;
-		break;
-	case SEARCH_SUBJECT:
-                env_field = IMAP_ENVELOPE_SUBJECT;
-		break;
-
-	case SEARCH_IN_REPLY_TO:
-                env_field = IMAP_ENVELOPE_IN_REPLY_TO;
-		break;
-	case SEARCH_MESSAGE_ID:
-                env_field = IMAP_ENVELOPE_MESSAGE_ID;
-		break;
-	default:
-		return -1;
-	}
-
-	t_push();
-
-	/* get field from hopefully cached envelope */
-	envelope = index->lookup_field(index, ctx->imail.data.rec,
-				       DATA_FIELD_ENVELOPE);
-	if (envelope != NULL) {
-		ret = imap_envelope_parse(envelope, env_field,
-					  IMAP_ENVELOPE_RESULT_TYPE_STRING,
-					  &field) ? 1 : -1;
-	} else {
-		index->cache_fields_later(index, DATA_FIELD_ENVELOPE);
-		field = NULL;
-		ret = -1;
-	}
-
-	if (ret != -1) {
-		switch (arg->type) {
-		case SEARCH_SENTBEFORE:
-		case SEARCH_SENTON:
-		case SEARCH_SENTSINCE:
-			ret = search_sent(arg->type, arg->value.str,
-					  (const unsigned char *) field,
-					  (size_t)-1);
-			break;
-		default:
-			if (arg->value.str[0] == '\0') {
-				/* we're just testing existence of the field.
-				   assume it matches with non-NIL values. */
-				ret = field != NULL ? 1 : 0;
-				break;
-			}
-
-			if (field == NULL) {
-				/* doesn't exist */
-				ret = 0;
-				break;
-			}
-
-			hdr_search_ctx = search_header_context(ctx, arg);
-			if (hdr_search_ctx == NULL) {
-				ret = 0;
-				break;
-			}
-
-			ret = message_header_search(
-						(const unsigned char *) field,
-						strlen(field),
-						hdr_search_ctx) ? 1 : 0;
-		}
-	}
-	t_pop();
-	return ret;
-}
-
-static void search_envelope_arg(struct mail_search_arg *arg, void *context)
-{
-	struct mail_search_context *ctx = context;
-
-	switch (search_arg_match_envelope(ctx, arg)) {
-	case -1:
-		/* unknown */
-		break;
-	case 0:
-		ARG_SET_RESULT(arg, 0);
-		break;
-	default:
-		ARG_SET_RESULT(arg, 1);
-		break;
-	}
-}
-
 static void search_header_arg(struct mail_search_arg *arg, void *context)
 {
 	struct search_header_context *ctx = context;
@@ -477,35 +390,8 @@
 		}
 		return;
 
-	case SEARCH_FROM:
-		if (strcasecmp(ctx->hdr->name, "From") != 0)
-			return;
-		break;
-	case SEARCH_TO:
-		if (strcasecmp(ctx->hdr->name, "To") != 0)
-			return;
-		break;
-	case SEARCH_CC:
-		if (strcasecmp(ctx->hdr->name, "Cc") != 0)
-			return;
-		break;
-	case SEARCH_BCC:
-		if (strcasecmp(ctx->hdr->name, "Bcc") != 0)
-			return;
-		break;
-	case SEARCH_SUBJECT:
-		if (strcasecmp(ctx->hdr->name, "Subject") != 0)
-			return;
-		break;
-	case SEARCH_IN_REPLY_TO:
-		if (strcasecmp(ctx->hdr->name, "In-Reply-To") != 0)
-			return;
-		break;
-	case SEARCH_MESSAGE_ID:
-		if (strcasecmp(ctx->hdr->name, "Message-ID") != 0)
-			return;
-		break;
 	case SEARCH_HEADER:
+	case SEARCH_HEADER_ADDRESS:
 		ctx->custom_header = TRUE;
 
 		if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0)
@@ -532,8 +418,7 @@
 		hdr_search_ctx = search_header_context(ctx->index_context, arg);
 		if (hdr_search_ctx == NULL)
 			ret = 0;
-		else if (arg->type == SEARCH_FROM || arg->type == SEARCH_TO ||
-			 arg->type == SEARCH_CC || arg->type == SEARCH_BCC) {
+		else if (arg->type == SEARCH_HEADER_ADDRESS) {
 			/* we have to match against normalized address */
 			struct message_address *addr;
 			string_t *str;
@@ -574,14 +459,8 @@
 			ARG_SET_RESULT(arg, 0);
 		}
 		break;
-	case SEARCH_FROM:
-	case SEARCH_TO:
-	case SEARCH_CC:
-	case SEARCH_BCC:
-	case SEARCH_SUBJECT:
 	case SEARCH_HEADER:
-	case SEARCH_IN_REPLY_TO:
-	case SEARCH_MESSAGE_ID:
+	case SEARCH_HEADER_ADDRESS:
 		ARG_SET_RESULT(arg, 0);
 		break;
 	default:
@@ -605,15 +484,7 @@
 
 	index_mail_parse_header(part, hdr, ctx->index_context->mail);
 
-	if (ctx->custom_header ||
-	    strcasecmp(hdr->name, "Date") == 0 ||
-	    strcasecmp(hdr->name, "From") == 0 ||
-	    strcasecmp(hdr->name, "To") == 0 ||
-	    strcasecmp(hdr->name, "Cc") == 0 ||
-	    strcasecmp(hdr->name, "Bcc") == 0 ||
-	    strcasecmp(hdr->name, "Subject") == 0 ||
-	    strcasecmp(hdr->name, "In-Reply-To") == 0 ||
-	    strcasecmp(hdr->name, "Message-ID") == 0) {
+	if (ctx->custom_header || strcasecmp(hdr->name, "Date") == 0) {
 		ctx->hdr = hdr;
 
 		ctx->custom_header = FALSE;
@@ -649,17 +520,23 @@
 				 struct mail_search_context *ctx)
 {
 	struct istream *input;
-	int have_headers, have_body, have_text;
+	const char *const *headers;
+	int have_headers, have_body;
 
 	/* 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)
+	headers = mail_search_args_analyze(args, &have_headers, &have_body);
+	if (!have_headers && !have_body)
 		return TRUE;
 
-	if (have_headers || have_text) {
+	if (have_headers) {
 		struct search_header_context hdr_ctx;
 
-		input = ctx->mail->get_stream(ctx->mail, NULL, NULL);
+		if (have_body)
+			headers = NULL;
+
+		input = headers == NULL ?
+			ctx->mail->get_stream(ctx->mail, NULL, NULL) :
+			ctx->mail->get_headers(ctx->mail, headers);
 		if (input == NULL)
 			return FALSE;
 
@@ -668,7 +545,7 @@
 		hdr_ctx.custom_header = TRUE;
 		hdr_ctx.args = args;
 
-		index_mail_init_parse_header(&ctx->imail);
+		index_mail_parse_header_init(&ctx->imail, headers);
 		message_parse_header(NULL, input, NULL,
 				     search_header, &hdr_ctx);
 	} else {
@@ -681,7 +558,7 @@
 		i_stream_seek(input, hdr_size.physical_size);
 	}
 
-	if (have_text || have_body) {
+	if (have_body) {
 		struct search_body_context body_ctx;
 
 		memset(&body_ctx, 0, sizeof(body_ctx));
@@ -967,6 +844,11 @@
 			ret = FALSE;
 	}
 
+	if (ctx->ibox->fetch_mail.pool != NULL)
+		index_mail_deinit(&ctx->ibox->fetch_mail);
+	if (ctx->imail.pool != NULL)
+		index_mail_deinit(&ctx->imail);
+
 	if (!index_storage_lock(ctx->ibox, MAIL_LOCK_UNLOCK))
 		ret = FALSE;
 
@@ -978,18 +860,42 @@
 	if (ctx->hdr_pool != NULL)
 		pool_unref(ctx->hdr_pool);
 
-	if (ctx->ibox->fetch_mail.pool != NULL)
-		index_mail_deinit(&ctx->ibox->fetch_mail);
-        index_mail_deinit(&ctx->imail);
 	i_free(ctx);
 	return ret;
 }
 
+static int search_match_next(struct mail_search_context *ctx)
+{
+        struct mail_search_arg *arg;
+	int ret;
+
+	/* check the index matches first */
+	mail_search_args_reset(ctx->args);
+	ret = mail_search_args_foreach(ctx->args, search_index_arg, ctx);
+	if (ret >= 0)
+		return ret > 0;
+
+	/* next search only from cached arguments */
+	ret = mail_search_args_foreach(ctx->args, search_cached_arg, ctx);
+	if (ret >= 0)
+		return ret > 0;
+
+	/* open the mail file and check the rest */
+	if (!search_arg_match_text(ctx->args, ctx))
+		return FALSE;
+
+	for (arg = ctx->args; arg != NULL; arg = arg->next) {
+		if (arg->result != 1)
+			return FALSE;
+	}
+
+	return TRUE;
+}
+
 struct mail *index_storage_search_next(struct mail_search_context *ctx)
 {
 	const struct messageset_mail *msgset_mail;
-        struct mail_search_arg *arg;
-	int found, ret;
+	int ret;
 
 	if (ctx->msgset_ctx == NULL) {
 		/* initialization failed or didn't found any messages */
@@ -998,47 +904,35 @@
 
 	do {
 		msgset_mail = index_messageset_next(ctx->msgset_ctx);
-		if (msgset_mail == NULL)
-			return NULL;
+		if (msgset_mail == NULL) {
+			ret = -1;
+			break;
+		}
 
 		ctx->mail->seq = msgset_mail->client_seq;
 		ctx->mail->uid = msgset_mail->rec->uid;
-		ret = index_mail_next(&ctx->imail, msgset_mail->rec,
-				      msgset_mail->idx_seq);
-
-		if (ret < 0)
-			return NULL;
-
-		if (ret == 0)
-			found = FALSE;
-		else {
-			mail_search_args_reset(ctx->args);
 
-			t_push();
-
-			mail_search_args_foreach(ctx->args, search_index_arg,
-						 ctx);
-			mail_search_args_foreach(ctx->args, search_cached_arg,
-						 ctx);
-			mail_search_args_foreach(ctx->args, search_envelope_arg,
-						 ctx);
-			found = search_arg_match_text(ctx->args, ctx);
+		ret = index_mail_next(&ctx->imail, msgset_mail->rec,
+				      msgset_mail->idx_seq, TRUE);
+		if (ret <= 0) {
+			if (ret < 0)
+				break;
+			continue;
+		}
 
-			t_pop();
+		t_push();
+		ret = search_match_next(ctx);
+		t_pop();
 
-			if (ctx->error != NULL)
-				return NULL;
-		}
+		if (ctx->error != NULL)
+			ret = -1;
+	} while (ret == 0);
 
-		if (found) {
-			for (arg = ctx->args; arg != NULL; arg = arg->next) {
-				if (arg->result != 1) {
-					found = FALSE;
-					break;
-				}
-			}
-		}
-	} while (!found);
+	if (ret < 0) {
+		/* error or last record */
+		index_mail_deinit(&ctx->imail);
+		return NULL;
+	}
 
 	return ctx->mail;
 }

Index: index-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- index-storage.c	26 Jul 2003 16:55:11 -0000	1.38
+++ index-storage.c	6 Aug 2003 20:15:33 -0000	1.39
@@ -149,20 +149,28 @@
 	destroy_unrefed(TRUE);
 }
 
-static enum mail_data_field get_data_fields(const char *fields)
+static enum mail_cache_field get_cache_fields(const char *fields)
 {
+	static enum mail_cache_field field_masks[] = {
+		MAIL_CACHE_SENT_DATE,
+		MAIL_CACHE_RECEIVED_DATE,
+		MAIL_CACHE_VIRTUAL_FULL_SIZE,
+		MAIL_CACHE_BODY,
+		MAIL_CACHE_BODYSTRUCTURE,
+		MAIL_CACHE_MESSAGEPART,
+	};
 	static const char *field_names[] = {
-		"Location",
-		"Envelope",
-		"Body",
-		"Bodystructure",
-		"MD5",
-		"MessagePart",
+		"sent_date",
+		"received_date",
+		"virtual_size",
+		"body",
+		"bodystructure",
+		"messagepart",
 		NULL
 	};
 
 	const char *const *arr;
-	enum mail_data_field ret;
+	enum mail_cache_field ret;
 	int i;
 
 	if (fields == NULL || *fields == '\0')
@@ -175,7 +183,7 @@
 
 		for (i = 0; field_names[i] != NULL; i++) {
 			if (strcasecmp(field_names[i], *arr) == 0) {
-				ret |= 1 << i;
+				ret |= field_masks[i];
 				break;
 			}
 		}
@@ -188,28 +196,28 @@
 	return ret;
 }
 
-static enum mail_data_field get_default_cache_fields(void)
+static enum mail_cache_field get_default_cache_fields(void)
 {
-	static enum mail_data_field ret = 0;
+	static enum mail_cache_field ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
 		return ret;
 
-	ret = get_data_fields(getenv("MAIL_CACHE_FIELDS"));
+	ret = get_cache_fields(getenv("MAIL_CACHE_FIELDS"));
 	ret_set = TRUE;
 	return ret;
 }
 
-static enum mail_data_field get_never_cache_fields(void)
+static enum mail_cache_field get_never_cache_fields(void)
 {
-	static enum mail_data_field ret = 0;
+	static enum mail_cache_field ret = 0;
 	static int ret_set = FALSE;
 
 	if (ret_set)
 		return ret;
 
-	ret = get_data_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
+	ret = get_cache_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
 	ret_set = TRUE;
 	return ret;
 }
@@ -282,9 +290,16 @@
 int index_storage_lock(struct index_mailbox *ibox,
 		       enum mail_lock_type lock_type)
 {
-	int ret;
+	int ret = TRUE;
 
 	if (lock_type == MAIL_LOCK_UNLOCK) {
+		if (ibox->trans_ctx != NULL) {
+			if (!mail_cache_transaction_commit(ibox->trans_ctx))
+				ret = FALSE;
+			if (!mail_cache_transaction_end(ibox->trans_ctx))
+				ret = FALSE;
+			ibox->trans_ctx = NULL;
+		}
 		if (ibox->lock_type != MAILBOX_LOCK_UNLOCK)
 			return TRUE;
 	} else {
@@ -295,7 +310,8 @@
 	/* we have to set/reset this every time, because the same index
 	   may be used by multiple IndexMailboxes. */
         index_storage_init_lock_notify(ibox);
-	ret = ibox->index->set_lock(ibox->index, lock_type);
+	if (!ibox->index->set_lock(ibox->index, lock_type))
+		ret = FALSE;
 	ibox->index->set_lock_notify_callback(ibox->index, NULL, NULL);
 
 	if (!ret)
@@ -337,13 +353,12 @@
 
 		if (!index->opened) {
 			/* open the index first */
-			index->default_cache_fields =
-				get_default_cache_fields();
-			index->never_cache_fields =
-				get_never_cache_fields();
-
 			if (!index->open(index, index_flags))
 				break;
+
+			mail_cache_set_defaults(index->cache,
+						get_default_cache_fields(),
+						get_never_cache_fields());
 
 			if (INDEX_IS_IN_MEMORY(index) &&
 			    storage->index_dir != NULL) {

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- index-storage.h	26 Jul 2003 16:55:11 -0000	1.46
+++ index-storage.h	6 Aug 2003 20:15:33 -0000	1.47
@@ -21,6 +21,7 @@
 
 	struct mail_index *index;
         enum mailbox_lock_type lock_type;
+	struct mail_cache_transaction_ctx *trans_ctx;
 
 	struct timeout *autosync_to;
         struct index_autosync_file *autosync_files;
@@ -90,6 +91,7 @@
 struct mail_fetch_context *
 index_storage_fetch_init(struct mailbox *box,
 			 enum mail_fetch_field wanted_fields,
+			 const char *const *wanted_headers,
 			 const char *messageset, int uidset);
 int index_storage_fetch_deinit(struct mail_fetch_context *ctx, int *all_found);
 struct mail *index_storage_fetch_next(struct mail_fetch_context *ctx);



More information about the dovecot-cvs mailing list