[dovecot-cvs] dovecot/src/lib-storage/index index-fetch.c, 1.55, 1.56 index-mail-headers.c, 1.41, 1.42 index-mail.c, 1.71, 1.72 index-mail.h, 1.28, 1.29 index-search.c, 1.99, 1.100 index-storage.c, 1.69, 1.70 index-storage.h, 1.88, 1.89 index-transaction.c, 1.11, 1.12

cras at dovecot.org cras at dovecot.org
Tue Mar 15 21:01:54 EET 2005


Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv16056/lib-storage/index

Modified Files:
	index-fetch.c index-mail-headers.c index-mail.c index-mail.h 
	index-search.c index-storage.c index-storage.h 
	index-transaction.c 
Log Message:
Major mail-storage API changes. It's now a bit cleaner and much more plugin
friendly. Removed proxy_mailbox* stuff, they were difficult to use and
there's now much easier way to replace them.



Index: index-fetch.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- index-fetch.c	8 Jul 2004 20:26:16 -0000	1.55
+++ index-fetch.c	15 Mar 2005 19:01:52 -0000	1.56
@@ -4,22 +4,6 @@
 #include "index-storage.h"
 #include "index-mail.h"
 
-struct mail *
-index_storage_fetch(struct mailbox_transaction_context *_t, uint32_t seq,
-		    enum mail_fetch_field wanted_fields)
-{
-	struct index_transaction_context *t =
-		(struct index_transaction_context *)_t;
-
-	if (t->fetch_mail.pool != NULL)
-		index_mail_deinit(&t->fetch_mail);
-
-	index_mail_init(t, &t->fetch_mail, wanted_fields, NULL);
-	if (index_mail_next(&t->fetch_mail, seq) < 0)
-		return NULL;
-	return &t->fetch_mail.mail;
-}
-
 int index_storage_get_uids(struct mailbox *box,
 			   uint32_t uid1, uint32_t uid2,
 			   uint32_t *seq1_r, uint32_t *seq2_r)

Index: index-mail-headers.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail-headers.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- index-mail-headers.c	6 Jan 2005 21:12:19 -0000	1.41
+++ index-mail-headers.c	15 Mar 2005 19:01:52 -0000	1.42
@@ -163,7 +163,7 @@
 {
 	string_t *str;
 
-	str = str_new(mail->pool, 256);
+	str = str_new(mail->data_pool, 256);
 	imap_envelope_write_part_data(mail->data.envelope_data, str);
 	mail->data.envelope = str_c(str);
 
@@ -187,11 +187,11 @@
 
 	if (data->save_bodystructure_header) {
 		i_assert(part != NULL);
-		imap_bodystructure_parse_header(mail->pool, part, hdr);
+		imap_bodystructure_parse_header(mail->data_pool, part, hdr);
 	}
 
 	if (data->save_envelope) {
-		imap_envelope_parse_header(mail->pool,
+		imap_envelope_parse_header(mail->data_pool,
 					   &data->envelope_data, hdr);
 
 		if (hdr == NULL)
@@ -313,7 +313,7 @@
 {
 	struct index_mail_data *data = &mail->data;
 
-	if (mail->mail.get_stream(&mail->mail, NULL, NULL) == NULL)
+	if (mail_get_stream(&mail->mail.mail, NULL, NULL) == NULL)
 		return -1;
 
 	index_mail_parse_header_init(mail, headers);
@@ -322,7 +322,7 @@
 		/* initialize bodystructure parsing in case we read the whole
 		   message. */
 		data->parser_ctx =
-			message_parser_init(mail->pool, data->stream);
+			message_parser_init(mail->data_pool, data->stream);
 		message_parser_parse_header(data->parser_ctx, &data->hdr_size,
 					    index_mail_parse_header_cb, mail);
 	} else {
@@ -342,7 +342,8 @@
 {
 	struct index_mail *mail = context;
 
-	imap_envelope_parse_header(mail->pool, &mail->data.envelope_data, hdr);
+	imap_envelope_parse_header(mail->data_pool,
+				   &mail->data.envelope_data, hdr);
 
 	if (hdr == NULL)
 		index_mail_parse_finish_imap_envelope(mail);
@@ -356,7 +357,7 @@
 	mail->data.save_envelope = TRUE;
 	header_ctx = mailbox_header_lookup_init(&mail->ibox->box,
 						imap_envelope_headers);
-	stream = mail->mail.get_headers(&mail->mail, header_ctx);
+	stream = mail_get_headers(&mail->mail.mail, header_ctx);
 	if (mail->data.envelope == NULL && stream != NULL) {
 		/* we got the headers from cache - parse them to get the
 		   envelope */
@@ -437,7 +438,7 @@
 
 	data = buffer_get_data(mail->header_data, &size);
         size = get_header_size(mail->header_data, offsets[field_idx]);
-	return p_strndup(mail->pool, data + offsets[field_idx], size);
+	return p_strndup(mail->data_pool, data + offsets[field_idx], size);
 }
 
 const char *index_mail_get_header(struct mail *_mail, const char *field)
@@ -453,11 +454,11 @@
 
 	field_idx = get_header_field_idx(mail->ibox, field);
 
-	dest = str_new(mail->pool, 128);
+	dest = str_new(mail->data_pool, 128);
 	if (mail_cache_lookup_headers(mail->trans->cache_view, dest,
 				      mail->data.seq, &field_idx, 1) <= 0) {
 		/* not in cache / error - first see if it's already parsed */
-		p_free(mail->pool, dest);
+		p_free(mail->data_pool, dest);
 		if (mail->header_seq == mail->data.seq) {
 			ret = index_mail_header_is_parsed(mail, field_idx);
 			if (ret != -1) {
@@ -529,17 +530,17 @@
 			return NULL;
 	}
 
-	dest = str_new(mail->pool, 256);
+	dest = str_new(mail->data_pool, 256);
 	if (mail_cache_lookup_headers(mail->trans->cache_view, dest,
 				      mail->data.seq, headers->idx,
 				      headers->count) > 0) {
-		return i_stream_create_from_data(mail->pool,
+		return i_stream_create_from_data(mail->data_pool,
 						 str_data(dest), str_len(dest));
 	}
 	/* not in cache / error */
-	p_free(mail->pool, dest);
+	p_free(mail->data_pool, dest);
 
-	if (mail->mail.get_stream(&mail->mail, NULL, NULL) == NULL)
+	if (mail_get_stream(&mail->mail.mail, NULL, NULL) == NULL)
 		return NULL;
 
 	if (mail->data.filter_stream != NULL)

Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- index-mail.c	15 Mar 2005 11:30:12 -0000	1.71
+++ index-mail.c	15 Mar 2005 19:01:52 -0000	1.72
@@ -48,7 +48,7 @@
 		return NULL;
 	}
 
-	part = message_part_deserialize(mail->pool,
+	part = message_part_deserialize(mail->data_pool,
 					buffer_get_data(part_buf, NULL),
 					buffer_get_used_size(part_buf),
 					&error);
@@ -62,11 +62,11 @@
 
 	/* we know the NULs now, update them */
 	if ((part->flags & MESSAGE_PART_FLAG_HAS_NULS) != 0) {
-		mail->mail.has_nuls = TRUE;
-		mail->mail.has_no_nuls = FALSE;
+		mail->mail.mail.has_nuls = TRUE;
+		mail->mail.mail.has_no_nuls = FALSE;
 	} else {
-		mail->mail.has_nuls = FALSE;
-		mail->mail.has_no_nuls = TRUE;
+		mail->mail.mail.has_nuls = FALSE;
+		mail->mail.mail.has_no_nuls = TRUE;
 	}
 
 	return part;
@@ -77,11 +77,11 @@
 {
 	string_t *str;
 
-	str = str_new(mail->pool, 32);
+	str = str_new(mail->data_pool, 32);
 	if (mail_cache_lookup_field(mail->trans->cache_view, str,
 				    mail->data.seq,
 				    mail->ibox->cache_fields[field].idx) <= 0) {
-		p_free(mail->pool, str);
+		p_free(mail->data_pool, str);
 		return NULL;
 	}
 
@@ -172,8 +172,10 @@
 	struct index_mail_data *data = &mail->data;
 	const char *const *keywords;
 
-	if (data->keywords_buf == NULL)
-		data->keywords_buf = buffer_create_dynamic(mail->pool, 128);
+	if (data->keywords_buf == NULL) {
+		data->keywords_buf =
+			buffer_create_dynamic(mail->data_pool, 128);
+	}
 
 	if (mail_index_lookup_keywords(mail->ibox->view, mail->data.seq,
 				       data->keywords_buf, &keywords) < 0) {
@@ -238,7 +240,7 @@
 
 	if (data->sent_date.time == (time_t)-1) {
 		data->save_sent_date = TRUE;
-		str = _mail->get_header(_mail, "Date");
+		str = mail_get_header(_mail, "Date");
 		if (data->sent_date.time == (time_t)-1) {
 			if (!message_date_parse((const unsigned char *)str,
 						(size_t)-1,
@@ -298,7 +300,7 @@
 	if (get_cached_msgpart_sizes(mail))
 		return data->virtual_size;
 
-	if (_mail->get_stream(_mail, &hdr_size, &body_size) == NULL)
+	if (mail_get_stream(_mail, &hdr_size, &body_size) == NULL)
 		return (uoff_t)-1;
 
 	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
@@ -355,7 +357,7 @@
 		i_assert(!data->save_bodystructure_header);
 		message_parser_parse_body(data->parser_ctx,
 					  parse_bodystructure_part_header,
-					  NULL, mail->pool);
+					  NULL, mail->data_pool);
 		data->save_bodystructure_body = FALSE;
 		data->parsed_bodystructure = TRUE;
 	} else {
@@ -368,17 +370,17 @@
 	data->body_size_set = TRUE;
 
 	cache_flags = 0;
-	if (!mail->mail.has_nuls && !mail->mail.has_no_nuls) {
+	if (!mail->mail.mail.has_nuls && !mail->mail.mail.has_no_nuls) {
 		/* we know the NULs now, update them */
 		if ((data->parts->flags & MESSAGE_PART_FLAG_HAS_NULS) != 0) {
-			mail->mail.has_nuls = TRUE;
-			mail->mail.has_no_nuls = FALSE;
+			mail->mail.mail.has_nuls = TRUE;
+			mail->mail.mail.has_no_nuls = FALSE;
 		} else {
-			mail->mail.has_nuls = FALSE;
-			mail->mail.has_no_nuls = TRUE;
+			mail->mail.mail.has_nuls = FALSE;
+			mail->mail.mail.has_no_nuls = TRUE;
 		}
 
-		if (mail->mail.has_nuls)
+		if (mail->mail.mail.has_nuls)
 			cache_flags |= MAIL_CACHE_FLAG_HAS_NULS;
 		else
 			cache_flags |= MAIL_CACHE_FLAG_HAS_NO_NULS;
@@ -480,7 +482,7 @@
 			message_parse_from_parts(data->parts->children,
 						data->stream,
 						parse_bodystructure_part_header,
-						mail->pool);
+						mail->data_pool);
 			data->parsed_bodystructure = TRUE;
 		} else {
 			index_mail_parse_body(mail, FALSE);
@@ -493,7 +495,7 @@
 	    ((dec & ~MAIL_CACHE_DECISION_FORCED) != MAIL_CACHE_DECISION_NO &&
 	     mail_cache_field_exists(mail->trans->cache_view, data->seq,
 			cache_fields[MAIL_CACHE_BODYSTRUCTURE].idx) == 0)) {
-		str = str_new(mail->pool, 128);
+		str = str_new(mail->data_pool, 128);
 		imap_bodystructure_write(data->parts, str, TRUE);
 		data->bodystructure = str_c(str);
 
@@ -512,7 +514,7 @@
 	    ((dec & ~MAIL_CACHE_DECISION_FORCED) != MAIL_CACHE_DECISION_NO &&
 	     mail_cache_field_exists(mail->trans->cache_view, data->seq,
 				     cache_fields[MAIL_CACHE_BODY].idx) == 0)) {
-		str = str_new(mail->pool, 128);
+		str = str_new(mail->data_pool, 128);
 		imap_bodystructure_write(data->parts, str, FALSE);
 		data->body = str_c(str);
 
@@ -544,7 +546,7 @@
 		   3) parse body structure, and save BODY/BODYSTRUCTURE
 		      depending on what we want cached */
 
-		str = str_new(mail->pool, 128);
+		str = str_new(mail->data_pool, 128);
 		if (mail_cache_lookup_field(mail->trans->cache_view, str,
 				mail->data.seq,
 				cache_fields[MAIL_CACHE_BODY].idx) > 0) {
@@ -554,7 +556,8 @@
 		if (mail_cache_lookup_field(mail->trans->cache_view, str,
 			      mail->data.seq,
 			      cache_fields[MAIL_CACHE_BODYSTRUCTURE].idx) > 0) {
-			data->bodystructure = p_strdup(mail->pool, str_c(str));
+			data->bodystructure =
+				p_strdup(mail->data_pool, str_c(str));
 			str_truncate(str, 0);
 
 			if (imap_body_parse_from_bodystructure(
@@ -566,10 +569,10 @@
 			/* broken, continue.. */
 			mail_cache_set_corrupted(mail->ibox->cache,
 				"Corrupted BODYSTRUCTURE for mail %u",
-				mail->mail.uid);
+				mail->mail.mail.uid);
 			data->bodystructure = NULL;
 		}
-		p_free(mail->pool, str);
+		p_free(mail->data_pool, str);
 
 		index_mail_parse_bodystructure(mail, MAIL_CACHE_BODY);
 		return data->body;
@@ -577,14 +580,14 @@
 		if (data->bodystructure != NULL)
 			return data->bodystructure;
 
-		str = str_new(mail->pool, 128);
+		str = str_new(mail->data_pool, 128);
 		if (mail_cache_lookup_field(mail->trans->cache_view, str,
 			      mail->data.seq,
 			      cache_fields[MAIL_CACHE_BODYSTRUCTURE].idx) > 0) {
 			data->bodystructure = str_c(str);
 			return data->bodystructure;
 		}
-		p_free(mail->pool, str);
+		p_free(mail->data_pool, str);
 
 		index_mail_parse_bodystructure(mail, MAIL_CACHE_BODYSTRUCTURE);
 		return data->bodystructure;
@@ -611,28 +614,39 @@
 	}
 }
 
-void index_mail_init(struct index_transaction_context *t,
-		     struct index_mail *mail,
-		     enum mail_fetch_field wanted_fields,
-		     struct mailbox_header_lookup_ctx *_wanted_headers)
+struct mail *
+index_mail_alloc(struct mailbox_transaction_context *_t,
+		 enum mail_fetch_field wanted_fields,
+		 struct mailbox_header_lookup_ctx *_wanted_headers)
 {
+	struct index_transaction_context *t =
+		(struct index_transaction_context *)_t;
 	struct index_header_lookup_ctx *wanted_headers =
 		(struct index_header_lookup_ctx *)_wanted_headers;
+	struct index_mail *mail;
 	const struct mail_index_header *hdr;
+	pool_t pool;
 
-	mail->mail = *t->ibox->mail_interface;
-	mail->mail.box = &t->ibox->box;
-	mail->mail.transaction = &t->mailbox_ctx;
+	pool = pool_alloconly_create("mail", 256);
+	mail = p_new(pool, struct index_mail, 1);
+	mail->mail.pool = pool;
+	ARRAY_CREATE(&mail->mail.module_contexts, pool, void *, 5);
+
+	mail->mail.v = *t->ibox->mail_vfuncs;
+	mail->mail.mail.box = &t->ibox->box;
+	mail->mail.mail.transaction = &t->mailbox_ctx;
 
 	/* only reason we couldn't get header is if view is invalidated */
 	hdr = mail_index_get_header(t->ibox->view);
 	mail->uid_validity = hdr->uid_validity;
 
-	mail->pool = pool_alloconly_create("index_mail", 16384);
+	mail->data_pool = pool_alloconly_create("index_mail", 16384);
 	mail->ibox = t->ibox;
 	mail->trans = t;
 	mail->wanted_fields = wanted_fields;
 	mail->wanted_headers = wanted_headers;
+
+	return &mail->mail.mail;
 }
 
 static void index_mail_close(struct index_mail *mail)
@@ -643,8 +657,9 @@
 		i_stream_unref(mail->data.filter_stream);
 }
 
-int index_mail_next(struct index_mail *mail, uint32_t seq)
+int index_mail_set_seq(struct mail *_mail, uint32_t seq)
 {
+	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
         const struct mail_index_record *rec;
 
@@ -656,7 +671,7 @@
 	index_mail_close(mail);
 
 	memset(data, 0, sizeof(*data));
-	p_clear(mail->pool);
+	p_clear(mail->data_pool);
 
 	data->rec = rec;
 	data->seq = seq;
@@ -669,11 +684,11 @@
 					sizeof(data->cache_flags)))
 		data->cache_flags = 0;
 
-	mail->mail.seq = seq;
-	mail->mail.uid = rec->uid;
-	mail->mail.has_nuls =
+	mail->mail.mail.seq = seq;
+	mail->mail.mail.uid = rec->uid;
+	mail->mail.mail.has_nuls =
 		(data->cache_flags & MAIL_CACHE_FLAG_HAS_NULS) != 0;
-	mail->mail.has_no_nuls =
+	mail->mail.mail.has_no_nuls =
 		(data->cache_flags & MAIL_CACHE_FLAG_HAS_NO_NULS) != 0;
 
 	t_push();
@@ -722,7 +737,7 @@
 					  MAIL_FETCH_STREAM_BODY)) {
 		data->open_mail = TRUE;
 		/* open stream to set expunged flag */
-		(void)mail->mail.get_stream(&mail->mail, NULL, NULL);
+		(void)mail_get_stream(_mail, NULL, NULL);
 	}
 
 	if ((mail->wanted_fields & MAIL_FETCH_DATE) &&
@@ -736,8 +751,10 @@
 	return 0;
 }
 
-void index_mail_deinit(struct index_mail *mail)
+void index_mail_free(struct mail *_mail)
 {
+	struct index_mail *mail = (struct index_mail *)_mail;
+
 	index_mail_close(mail);
 
 	if (mail->header_data != NULL)
@@ -749,8 +766,8 @@
 	if (mail->header_offsets != NULL)
 		buffer_free(mail->header_offsets);
 
-	pool_unref(mail->pool);
-	memset(mail, 0, sizeof(*mail));
+	pool_unref(mail->data_pool);
+	pool_unref(mail->mail.pool);
 }
 
 int index_mail_update_flags(struct mail *mail, enum modify_type modify_type,

Index: index-mail.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- index-mail.h	10 Jan 2005 17:37:23 -0000	1.28
+++ index-mail.h	15 Mar 2005 19:01:52 -0000	1.29
@@ -87,10 +87,10 @@
 };
 
 struct index_mail {
-	struct mail mail;
+        struct mail_private mail;
 	struct index_mail_data data;
 
-	pool_t pool;
+	pool_t data_pool;
 	struct index_mailbox *ibox;
 	struct index_transaction_context *trans;
 	uint32_t uid_validity;
@@ -107,12 +107,12 @@
 	uint8_t header_match_value;
 };
 
-void index_mail_init(struct index_transaction_context *t,
-		     struct index_mail *mail,
-		     enum mail_fetch_field wanted_fields,
-		     struct mailbox_header_lookup_ctx *wanted_headers);
-int index_mail_next(struct index_mail *mail, uint32_t seq);
-void index_mail_deinit(struct index_mail *mail);
+struct mail *
+index_mail_alloc(struct mailbox_transaction_context *t,
+		 enum mail_fetch_field wanted_fields,
+		 struct mailbox_header_lookup_ctx *wanted_headers);
+int index_mail_set_seq(struct mail *mail, uint32_t seq);
+void index_mail_free(struct mail *mail);
 
 void index_mail_parse_header_init(struct index_mail *mail,
 				  struct mailbox_header_lookup_ctx *headers);

Index: index-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- index-search.c	6 Jan 2005 18:14:29 -0000	1.99
+++ index-search.c	15 Mar 2005 19:01:52 -0000	1.100
@@ -27,8 +27,8 @@
 	struct mail_search_arg *args;
 
 	uint32_t seq1, seq2;
-	struct index_mail imail;
 	struct mail *mail;
+	struct index_mail *imail;
 
 	pool_t hdr_pool;
 	const char *error;
@@ -103,9 +103,9 @@
 	case SEARCH_SEEN:
 		return rec->flags & MAIL_SEEN;
 	case SEARCH_RECENT:
-		return imail->mail.get_flags(&imail->mail) & MAIL_RECENT;
+		return mail_get_flags(&imail->mail.mail) & MAIL_RECENT;
 	case SEARCH_KEYWORD:
-		keywords = imail->mail.get_keywords(&imail->mail);
+		keywords = mail_get_keywords(&imail->mail.mail);
 		if (keywords != NULL) {
 			while (*keywords != NULL) {
 				if (strcasecmp(*keywords, value) == 0)
@@ -131,13 +131,13 @@
 		return;
 	}
 
-	if (ctx->imail.data.rec == NULL) {
+	if (ctx->imail->data.rec == NULL) {
 		/* expunged message */
 		ARG_SET_RESULT(arg, 0);
 		return;
 	}
 
-	switch (search_arg_match_index(&ctx->imail, arg->type,
+	switch (search_arg_match_index(ctx->imail, arg->type,
 				       arg->value.str)) {
 	case -1:
 		/* unknown */
@@ -165,7 +165,7 @@
 	case SEARCH_BEFORE:
 	case SEARCH_ON:
 	case SEARCH_SINCE:
-		date = ctx->mail->get_received_date(ctx->mail);
+		date = mail_get_received_date(ctx->mail);
 		if (date == (time_t)-1)
 			return -1;
 
@@ -191,7 +191,7 @@
 	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);
+		date = mail_get_date(ctx->mail, &timezone_offset);
 		if (date == (time_t)-1)
 			return -1;
 		date += timezone_offset * 60;
@@ -215,7 +215,7 @@
 	/* sizes */
 	case SEARCH_SMALLER:
 	case SEARCH_LARGER:
-		virtual_size = ctx->mail->get_virtual_size(ctx->mail);
+		virtual_size = mail_get_virtual_size(ctx->mail);
 		if (virtual_size == (uoff_t)-1)
 			return -1;
 
@@ -423,7 +423,7 @@
 	if (hdr->eoh)
 		return;
 
-	index_mail_parse_header(NULL, hdr, &ctx->index_context->imail);
+	index_mail_parse_header(NULL, hdr, ctx->index_context->imail);
 
 	if (ctx->custom_header || strcasecmp(hdr->name, "Date") == 0) {
 		ctx->hdr = hdr;
@@ -478,7 +478,7 @@
 
 		if (headers == NULL) {
 			headers_ctx = NULL;
-			input = ctx->mail->get_stream(ctx->mail, NULL, NULL);
+			input = mail_get_stream(ctx->mail, NULL, NULL);
 			if (input == NULL)
 				return FALSE;
 		} else {
@@ -486,7 +486,7 @@
 			headers_ctx =
 				mailbox_header_lookup_init(&ctx->ibox->box,
 							   headers);
-			input = ctx->mail->get_headers(ctx->mail, headers_ctx);
+			input = mail_get_headers(ctx->mail, headers_ctx);
 			if (input == NULL) {
 				mailbox_header_lookup_deinit(headers_ctx);
 				return FALSE;
@@ -498,7 +498,7 @@
 		hdr_ctx.custom_header = TRUE;
 		hdr_ctx.args = args;
 
-		index_mail_parse_header_init(&ctx->imail, headers_ctx);
+		index_mail_parse_header_init(ctx->imail, headers_ctx);
 		message_parse_header(NULL, input, NULL,
 				     search_header, &hdr_ctx);
 		if (headers_ctx != NULL)
@@ -506,7 +506,7 @@
 	} else {
 		struct message_size hdr_size;
 
-		input = ctx->mail->get_stream(ctx->mail, &hdr_size, NULL);
+		input = mail_get_stream(ctx->mail, &hdr_size, NULL);
 		if (input == NULL)
 			return FALSE;
 
@@ -519,7 +519,7 @@
 		memset(&body_ctx, 0, sizeof(body_ctx));
 		body_ctx.index_ctx = ctx;
 		body_ctx.input = input;
-		body_ctx.part = ctx->mail->get_parts(ctx->mail);
+		body_ctx.part = mail_get_parts(ctx->mail);
 
 		mail_search_args_foreach(args, search_body, &body_ctx);
 	}
@@ -710,9 +710,7 @@
 struct mail_search_context *
 index_storage_search_init(struct mailbox_transaction_context *_t,
 			  const char *charset, struct mail_search_arg *args,
-			  const enum mail_sort_type *sort_program,
-			  enum mail_fetch_field wanted_fields,
-			  struct mailbox_header_lookup_ctx *wanted_headers)
+			  const enum mail_sort_type *sort_program)
 {
 	struct index_transaction_context *t =
 		(struct index_transaction_context *)_t;
@@ -724,15 +722,12 @@
 	}
 
 	ctx = i_new(struct index_search_context, 1);
-	ctx->mail_ctx.box = &t->ibox->box;
+	ctx->mail_ctx.transaction = _t;
 	ctx->ibox = t->ibox;
 	ctx->view = t->trans_view;
 	ctx->charset = i_strdup(charset);
 	ctx->args = args;
 
-	ctx->mail = &ctx->imail.mail;
-	index_mail_init(t, &ctx->imail, wanted_fields, wanted_headers);
-
 	mail_search_args_reset(ctx->args, TRUE);
 
 	if (search_get_seqset(ctx, args) < 0) {
@@ -750,9 +745,6 @@
 
 	ret = ctx->failed || ctx->error != NULL ? -1 : 0;
 
-	if (ctx->imail.pool != NULL)
-		index_mail_deinit(&ctx->imail);
-
 	if (ctx->error != NULL) {
 		mail_storage_set_error(ctx->ibox->box.storage,
 				       "%s", ctx->error);
@@ -777,7 +769,7 @@
 	if (ret >= 0)
 		return ret > 0;
 
-	if (ctx->imail.data.rec == NULL) {
+	if (ctx->imail->data.rec == NULL) {
 		/* expunged message, no way to check if the rest would have
 		   matched */
 		return FALSE;
@@ -800,16 +792,20 @@
 	return TRUE;
 }
 
-struct mail *index_storage_search_next(struct mail_search_context *_ctx)
+int index_storage_search_next(struct mail_search_context *_ctx,
+			      struct mail *mail)
 {
         struct index_search_context *ctx = (struct index_search_context *)_ctx;
 	int ret;
 
+	ctx->mail = mail;
+	ctx->imail = (struct index_mail *)mail;
+
 	ret = 0;
 	while (ctx->seq1 <= ctx->seq2) {
-		if (index_mail_next(&ctx->imail, ctx->seq1++) < 0) {
+		if (mail_set_seq(mail, ctx->seq1++) < 0) {
 			ctx->failed = TRUE;
-			return NULL;
+			break;
 		}
 
 		t_push();
@@ -821,11 +817,8 @@
 		if (ret != 0)
 			break;
 	}
+	ctx->mail = NULL;
+	ctx->imail = NULL;
 
-	if (ret <= 0) {
-		/* error or last record */
-		return NULL;
-	}
-
-	return ctx->mail;
+	return ret;
 }

Index: index-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- index-storage.c	7 Mar 2005 09:42:54 -0000	1.69
+++ index-storage.c	15 Mar 2005 19:01:52 -0000	1.70
@@ -5,6 +5,7 @@
 #include "ioloop.h"
 #include "mail-index.h"
 #include "index-storage.h"
+#include "index-mail.h"
 
 #include <stdlib.h>
 #include <time.h>
@@ -42,6 +43,8 @@
 			enum mail_storage_flags flags)
 {
 	storage->storage.flags = flags;
+	ARRAY_CREATE(&storage->storage.module_contexts,
+		     storage->storage.pool, void *, 5);
 	index_storage_refcount++;
 }
 
@@ -279,12 +282,10 @@
 	ibox->last_notify_type = MAILBOX_LOCK_NOTIFY_NONE;
 }
 
-struct index_mailbox *
-index_storage_mailbox_init(struct index_storage *storage, struct mailbox *box,
-			   struct mail_index *index, const char *name,
-			   enum mailbox_open_flags flags)
+int index_storage_mailbox_init(struct index_mailbox *ibox,
+			       struct mail_index *index, const char *name,
+			       enum mailbox_open_flags flags)
 {
-	struct index_mailbox *ibox;
 	enum mail_index_open_flags index_flags;
 	enum mail_index_lock_method lock_method = 0;
 	const char *str;
@@ -312,15 +313,13 @@
 		i_fatal("Unknown lock_method: %s", str);
 
 	do {
-		ibox = i_new(struct index_mailbox, 1);
-		ibox->box = *box;
-		ibox->storage = storage;
+		ibox->box.storage = &ibox->storage->storage;
+		ibox->box.name = p_strdup(ibox->box.pool, name);
+		ARRAY_CREATE(&ibox->box.module_contexts,
+			     ibox->box.pool, void *, 5);
 
-		ibox->box.storage = &storage->storage;
-		ibox->box.name = i_strdup(name);
 		ibox->readonly = (flags & MAILBOX_OPEN_READONLY) != 0;
 		ibox->keep_recent = (flags & MAILBOX_OPEN_KEEP_RECENT) != 0;
-
 		ibox->index = index;
 
 		ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
@@ -333,12 +332,12 @@
 		ibox->cache = mail_index_get_cache(index);
 		index_cache_register_defaults(ibox);
 		ibox->view = mail_index_view_open(index);
-		return ibox;
+		return 0;
 	} while (0);
 
 	mail_storage_set_index_error(ibox);
 	index_storage_mailbox_free(&ibox->box);
-	return NULL;
+	return -1;
 }
 
 void index_storage_mailbox_free(struct mailbox *box)
@@ -352,11 +351,7 @@
 	if (ibox->index != NULL)
 		index_storage_unref(ibox->index);
         i_free(ibox->cache_fields);
-	i_free(ibox->path);
-	i_free(ibox->control_dir);
-
-	i_free(box->name);
-	i_free(box);
+	pool_unref(box->pool);
 }
 
 int index_storage_is_readonly(struct mailbox *box)

Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- index-storage.h	5 Feb 2005 12:01:50 -0000	1.88
+++ index-storage.h	15 Mar 2005 19:01:52 -0000	1.89
@@ -4,7 +4,6 @@
 #include "file-dotlock.h"
 #include "mail-storage-private.h"
 #include "mail-index.h"
-#include "index-mail.h"
 
 /* Max. mmap()ed size for a message */
 #define MAIL_MMAP_BLOCK_SIZE (1024*256)
@@ -25,13 +24,13 @@
 struct index_storage {
 	struct mail_storage storage;
 
-	char *dir; /* root directory */
-	char *index_dir;
-	char *control_dir;
-	char *inbox_path; /* INBOX location */
-        char *temp_prefix; /* prefix for temporary files */
+	const char *dir; /* root directory */
+	const char *index_dir;
+	const char *control_dir;
+	const char *inbox_path; /* INBOX location */
+        const char *temp_prefix; /* prefix for temporary files */
 
-	char *user; /* name of user accessing the storage */
+	const char *user; /* name of user accessing the storage */
 
 	struct mail_storage_callbacks *callbacks;
 	void *callback_context;
@@ -40,12 +39,12 @@
 struct index_mailbox {
 	struct mailbox box;
 	struct index_storage *storage;
-	char *path, *control_dir;
+	const char *path, *control_dir;
 
 	struct mail_index *index;
 	struct mail_index_view *view;
 	struct mail_cache *cache;
-	struct mail *mail_interface;
+	struct mail_vfuncs *mail_vfuncs;
 
 	int (*is_recent)(struct index_mailbox *ibox, uint32_t uid);
 
@@ -110,13 +109,13 @@
 struct index_transaction_context {
 	struct mailbox_transaction_context mailbox_ctx;
 	struct index_mailbox *ibox;
+        enum mailbox_transaction_flags flags;
 
 	struct mail_index_transaction *trans;
 	struct mail_index_view *trans_view;
 	struct mail_cache_view *cache_view;
 	struct mail_cache_transaction_ctx *cache_trans;
 
-	struct index_mail fetch_mail; /* for index_storage_fetch() */
 	unsigned int cache_trans_failed:1;
 };
 
@@ -137,10 +136,9 @@
 			enum mail_storage_flags flags);
 void index_storage_deinit(struct index_storage *storage);
 
-struct index_mailbox *
-index_storage_mailbox_init(struct index_storage *storage, struct mailbox *box,
-			   struct mail_index *index, const char *name,
-			   enum mailbox_open_flags flags);
+int index_storage_mailbox_init(struct index_mailbox *ibox,
+			       struct mail_index *index, const char *name,
+			       enum mailbox_open_flags flags);
 void index_storage_mailbox_free(struct mailbox *box);
 
 int index_storage_is_readonly(struct mailbox *box);
@@ -184,9 +182,6 @@
 				    enum mailbox_status_items items,
 				    struct mailbox_status *status_r);
 
-struct mail *
-index_storage_fetch(struct mailbox_transaction_context *t, uint32_t seq,
-		    enum mail_fetch_field wanted_fields);
 int index_storage_get_uids(struct mailbox *box, uint32_t uid1, uint32_t uid2,
 			   uint32_t *seq1_r, uint32_t *seq2_r);
 
@@ -199,14 +194,14 @@
 struct mail_search_context *
 index_storage_search_init(struct mailbox_transaction_context *t,
 			  const char *charset, struct mail_search_arg *args,
-			  const enum mail_sort_type *sort_program,
-			  enum mail_fetch_field wanted_fields,
-			  struct mailbox_header_lookup_ctx *wanted_headers);
+			  const enum mail_sort_type *sort_program);
 int index_storage_search_deinit(struct mail_search_context *ctx);
-struct mail *index_storage_search_next(struct mail_search_context *ctx);
+int index_storage_search_next(struct mail_search_context *ctx,
+			      struct mail *mail);
 
 void index_transaction_init(struct index_transaction_context *t,
-			    struct index_mailbox *ibox, int hide);
+			    struct index_mailbox *ibox,
+			    enum mailbox_transaction_flags flags);
 int index_transaction_commit(struct mailbox_transaction_context *t);
 void index_transaction_rollback(struct mailbox_transaction_context *t);
 

Index: index-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-transaction.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- index-transaction.c	11 Nov 2004 22:01:44 -0000	1.11
+++ index-transaction.c	15 Mar 2005 19:01:52 -0000	1.12
@@ -2,13 +2,19 @@
 
 #include "lib.h"
 #include "index-storage.h"
+#include "index-mail.h"
 
 void index_transaction_init(struct index_transaction_context *t,
-			    struct index_mailbox *ibox, int hide)
+			    struct index_mailbox *ibox,
+			    enum mailbox_transaction_flags flags)
 {
 	t->mailbox_ctx.box = &ibox->box;
 	t->ibox = ibox;
-	t->trans = mail_index_transaction_begin(ibox->view, hide, FALSE);
+	t->flags = flags;
+
+	t->trans = mail_index_transaction_begin(ibox->view,
+		(flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0,
+		(flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 	t->trans_view = mail_index_transaction_open_updated_view(t->trans);
 	t->cache_view = mail_cache_view_open(ibox->cache, t->trans_view);
 	t->cache_trans = mail_cache_get_transaction(t->cache_view, t->trans);
@@ -30,9 +36,6 @@
 	uoff_t offset;
 	int ret;
 
-	if (t->fetch_mail.pool != NULL)
-		index_mail_deinit(&t->fetch_mail);
-
 	ret = mail_index_transaction_commit(t->trans, &seq, &offset);
 	if (ret < 0)
 		mail_storage_set_index_error(t->ibox);
@@ -52,9 +55,6 @@
 	struct index_transaction_context *t =
 		(struct index_transaction_context *)_t;
 
-	if (t->fetch_mail.pool != NULL)
-		index_mail_deinit(&t->fetch_mail);
-
 	mail_index_transaction_rollback(t->trans);
 	index_transaction_free(t);
 }



More information about the dovecot-cvs mailing list