changeset 4518:ed489df90232 HEAD

index_mail_cache_add() was used with lib-storage's internal indexes for most of the received date, physical size and virtual size cache additions. This may have caused all kinds of trouble, but since it went unnoticed this long perhaps not..
author Timo Sirainen <tss@iki.fi>
date Mon, 31 Jul 2006 02:02:16 +0300
parents e661182eab75
children 4be4c887deb7
files src/lib-storage/index/index-mail-headers.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-mail.h
diffstat 3 files changed, 30 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail-headers.c	Sun Jul 30 22:27:24 2006 +0300
+++ b/src/lib-storage/index/index-mail-headers.c	Mon Jul 31 02:02:16 2006 +0300
@@ -72,7 +72,8 @@
 						    mail->data.seq,
 						    match_idx) == 0) {
 				/* this header doesn't exist. remember that. */
-				index_mail_cache_add(mail, match_idx, NULL, 0);
+				index_mail_cache_add_idx(mail, match_idx,
+							 NULL, 0);
 			}
 			match_idx++;
 		}
@@ -121,7 +122,8 @@
 		}
 
 		data = buffer_get_data(buf, &data_size);
-		index_mail_cache_add(mail, lines[i].field_idx, data, data_size);
+		index_mail_cache_add_idx(mail, lines[i].field_idx,
+					 data, data_size);
 	}
 
 	for (; match_idx < match_count; match_idx++) {
@@ -129,7 +131,7 @@
 		    mail_cache_field_exists(mail->trans->cache_view,
 					    mail->data.seq, match_idx) == 0) {
 			/* this header doesn't exist. remember that. */
-			index_mail_cache_add(mail, match_idx, NULL, 0);
+			index_mail_cache_add_idx(mail, match_idx, NULL, 0);
 		}
 	}
 
@@ -149,7 +151,7 @@
 		/* check that it hadn't been added in some older session */
 		if (mail_cache_field_exists(mail->trans->cache_view,
 					    mail->data.seq, cache_field) == 0)
-			index_mail_cache_add(mail, cache_field, NULL, 0);
+			index_mail_cache_add_idx(mail, cache_field, NULL, 0);
 	}
 	t_pop();
 }
--- a/src/lib-storage/index/index-mail.c	Sun Jul 30 22:27:24 2006 +0300
+++ b/src/lib-storage/index/index-mail.c	Mon Jul 31 02:02:16 2006 +0300
@@ -235,7 +235,6 @@
 {
 	struct index_mail *mail = (struct index_mail *) _mail;
 	struct index_mail_data *data = &mail->data;
-	struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
 	const char *str;
 	int tz;
 
@@ -260,8 +259,7 @@
 			tz = 0;
 		}
 		data->sent_date.timezone = tz;
-		index_mail_cache_add(mail,
-				     cache_fields[MAIL_CACHE_SENT_DATE].idx,
+		index_mail_cache_add(mail, MAIL_CACHE_SENT_DATE,
 				     &data->sent_date, sizeof(data->sent_date));
 	}
 
@@ -295,7 +293,6 @@
 {
 	struct index_mail *mail = (struct index_mail *) _mail;
 	struct index_mail_data *data = &mail->data;
-	struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
 	struct message_size hdr_size, body_size;
 	uoff_t old_offset;
 
@@ -315,8 +312,7 @@
 	}
 
 	i_assert(data->virtual_size != (uoff_t)-1);
-	index_mail_cache_add(mail,
-			     cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx,
+	index_mail_cache_add(mail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
 			     &data->virtual_size, sizeof(data->virtual_size));
 	return data->virtual_size;
 }
@@ -339,9 +335,16 @@
 	return (uoff_t)-1;
 }
 
-void index_mail_cache_add(struct index_mail *mail, unsigned int field,
+void index_mail_cache_add(struct index_mail *mail, enum index_cache_field field,
 			  const void *data, size_t data_size)
 {
+	index_mail_cache_add_idx(mail, mail->ibox->cache_fields[field].idx,
+				 data, data_size);
+}
+
+void index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx,
+			      const void *data, size_t data_size)
+{
 	const struct mail_index_header *hdr;
 
 	/* First check if we've configured caching not to be used with
@@ -351,7 +354,7 @@
 		return;
 
 	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-		       field, data, data_size);
+		       field_idx, data, data_size);
 }
 
 static void parse_bodystructure_part_header(struct message_part *part,
@@ -398,11 +401,8 @@
 		cache_flags |= MAIL_CACHE_FLAG_BINARY_BODY;
 
 	if (cache_flags != data->cache_flags) {
-		unsigned int cache_field =
-			mail->ibox->cache_fields[MAIL_CACHE_FLAGS].idx;
-
 		data->cache_flags = cache_flags;
-		index_mail_cache_add(mail, cache_field,
+		index_mail_cache_add(mail, MAIL_CACHE_FLAGS,
 				     &cache_flags, sizeof(cache_flags));
 	}
 }
@@ -439,7 +439,8 @@
 	t_push();
 	buffer = buffer_create_dynamic(pool_datastack_create(), 1024);
 	message_part_serialize(mail->data.parts, buffer);
-	index_mail_cache_add(mail, cache_field, buffer->data, buffer->used);
+	index_mail_cache_add(mail, MAIL_CACHE_MESSAGE_PARTS,
+			     buffer->data, buffer->used);
 	t_pop();
 
 	data->messageparts_saved_to_cache = TRUE;
@@ -492,7 +493,8 @@
 		data->bodystructure = str_c(str);
 
 		if (cache_bodystructure) {
-			index_mail_cache_add(mail, cache_field_bodystructure,
+			index_mail_cache_add(mail,
+					     MAIL_CACHE_IMAP_BODYSTRUCTURE,
 					     str_c(str), str_len(str)+1);
 			bodystructure_cached = TRUE;
 		}
@@ -526,7 +528,7 @@
 		data->body = str_c(str);
 
 		if (cache_body) {
-			index_mail_cache_add(mail, cache_field_body,
+			index_mail_cache_add(mail, MAIL_CACHE_IMAP_BODY,
 					     str_c(str), str_len(str)+1);
 		}
 	}
@@ -540,7 +542,7 @@
 
 	if (mail_cache_field_want_add(mail->trans->cache_trans,
 				      mail->data.seq, cache_field)) {
-		index_mail_cache_add(mail, cache_field,
+		index_mail_cache_add(mail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
 				     &mail->data.virtual_size,
 				     sizeof(mail->data.virtual_size));
 	}
@@ -911,7 +913,9 @@
 	data->seq = seq;
 	data->virtual_size = (uoff_t)-1;
 	data->physical_size = (uoff_t)-1;
-	data->received_date = data->sent_date.time = (time_t)-1;
+	data->save_date = (time_t)-1;
+	data->received_date = (time_t)-1;
+	data->sent_date.time = (time_t)-1;
 
 	if (!index_mail_get_fixed_field(mail, MAIL_CACHE_FLAGS,
 					&data->cache_flags,
--- a/src/lib-storage/index/index-mail.h	Sun Jul 30 22:27:24 2006 +0300
+++ b/src/lib-storage/index/index-mail.h	Mon Jul 31 02:02:16 2006 +0300
@@ -174,8 +174,10 @@
 				    enum index_cache_field field);
 uoff_t index_mail_get_cached_virtual_size(struct index_mail *mail);
 
-void index_mail_cache_add(struct index_mail *mail, unsigned int field,
+void index_mail_cache_add(struct index_mail *mail, enum index_cache_field field,
 			  const void *data, size_t data_size);
+void index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx,
+			      const void *data, size_t data_size);
 
 void index_mail_cache_parse_init(struct mail *mail, struct istream *input);
 void index_mail_cache_parse_continue(struct mail *mail);