[dovecot-cvs] dovecot/src/lib-storage/index index-mail-headers.c, 1.59.2.1, 1.59.2.2 index-mail.c, 1.93.2.2, 1.93.2.3

cras at dovecot.org cras at dovecot.org
Mon Jul 24 03:26:47 EEST 2006


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

Modified Files:
      Tag: branch_1_0
	index-mail-headers.c index-mail.c 
Log Message:
Restore data stream's offset after it has been internally changed, so that
it doesn't have much visible effect on the stream returned by
mail_get_stream(). The buffered data will still be lost, but this should
help with the most common use cases.



Index: index-mail-headers.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail-headers.c,v
retrieving revision 1.59.2.1
retrieving revision 1.59.2.2
diff -u -d -r1.59.2.1 -r1.59.2.2
--- index-mail-headers.c	17 Jun 2006 20:15:09 -0000	1.59.2.1
+++ index-mail-headers.c	24 Jul 2006 00:26:45 -0000	1.59.2.2
@@ -347,6 +347,9 @@
 			     struct mailbox_header_lookup_ctx *headers)
 {
 	struct index_mail_data *data = &mail->data;
+	uoff_t old_offset;
+
+	old_offset = data->stream == NULL ? 0 : data->stream->v_offset;
 
 	if (mail_get_stream(&mail->mail.mail, NULL, NULL) == NULL)
 		return -1;
@@ -371,6 +374,7 @@
 	data->hdr_size_set = TRUE;
 	data->access_part &= ~PARSE_HDR;
 
+	i_stream_seek(data->stream, old_offset);
 	return 0;
 }
 
@@ -391,6 +395,10 @@
 {
 	struct mailbox_header_lookup_ctx *header_ctx;
 	struct istream *stream;
+	uoff_t old_offset;
+
+	old_offset = mail->data.stream == NULL ? 0 :
+		mail->data.stream->v_offset;
 
 	mail->data.save_envelope = TRUE;
 	header_ctx = mailbox_header_lookup_init(&mail->ibox->box,
@@ -404,6 +412,9 @@
 		mail->data.save_envelope = FALSE;
 	}
 	mailbox_header_lookup_deinit(&header_ctx);
+
+	if (mail->data.stream != NULL)
+		i_stream_seek(mail->data.stream, old_offset);
 }
 
 static size_t get_header_size(buffer_t *buffer, size_t pos)

Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.93.2.2
retrieving revision 1.93.2.3
diff -u -d -r1.93.2.2 -r1.93.2.3
--- index-mail.c	8 May 2006 11:42:53 -0000	1.93.2.2
+++ index-mail.c	24 Jul 2006 00:26:45 -0000	1.93.2.3
@@ -297,6 +297,7 @@
 	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;
 
 	if (data->virtual_size != (uoff_t)-1)
 		return data->virtual_size;
@@ -306,8 +307,11 @@
 		return data->virtual_size;
 
 	if (!get_cached_msgpart_sizes(mail)) {
+		old_offset = data->stream == NULL ? 0 : data->stream->v_offset;
+
 		if (mail_get_stream(_mail, &hdr_size, &body_size) == NULL)
 			return (uoff_t)-1;
+		i_stream_seek(data->stream, old_offset);
 	}
 
 	i_assert(data->virtual_size != (uoff_t)-1);
@@ -367,11 +371,13 @@
 	buffer_t *buffer;
 	const void *buf_data;
 	size_t buf_size;
+	uoff_t old_offset;
 	uint32_t cache_flags = data->cache_flags;
 
 	i_assert(data->parts == NULL);
 	i_assert(data->parser_ctx != NULL);
 
+	old_offset = data->stream->v_offset;
 	i_stream_seek(data->stream, data->hdr_size.physical_size);
 
 	if (data->save_bodystructure_body) {
@@ -387,6 +393,7 @@
 		message_parser_parse_body(data->parser_ctx, NULL, NULL, NULL);
 	}
 	data->parts = message_parser_deinit(&data->parser_ctx);
+	i_stream_seek(data->stream, old_offset);
 
 	if (data->parsed_bodystructure &&
 	    imap_bodystructure_is_plain_7bit(data->parts)) {
@@ -512,6 +519,7 @@
 	struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
 	enum mail_cache_decision_type dec;
 	string_t *str;
+	uoff_t old_offset;
 	bool bodystructure_cached = FALSE;
 	bool plain_bodystructure = FALSE;
 
@@ -527,6 +535,8 @@
 
 		if (data->parts != NULL) {
 			i_assert(data->parts->next == NULL);
+
+			old_offset = data->stream->v_offset;
 			i_stream_seek(data->stream,
 				      data->hdr_size.physical_size);
 			message_parse_from_parts(data->parts->children,
@@ -534,6 +544,7 @@
 						parse_bodystructure_part_header,
 						mail->data_pool);
 			data->parsed_bodystructure = TRUE;
+			i_stream_seek(data->stream, old_offset);
 		} else {
 			index_mail_parse_body(mail, FALSE);
 		}
@@ -760,6 +771,7 @@
 	struct index_mail_data *data = &mail->data;
 	struct mail_cache_field *cache_fields = mail->ibox->cache_fields;
         struct mail_cache_view *cache_view = mail->trans->cache_view;
+	const struct mail_index_header *hdr;
 	const struct mail_index_record *rec;
 
 	if (mail_index_lookup(mail->trans->trans_view, seq, &rec) < 0) {
@@ -767,6 +779,10 @@
 		return -1;
 	}
 
+	hdr = mail_index_get_header(mail->trans->trans_view);
+	if (rec->uid >= hdr->next_uid)
+		i_unreached();
+
 	index_mail_close(mail);
 
 	memset(data, 0, sizeof(*data));



More information about the dovecot-cvs mailing list