dovecot: Avoid moving raw stream offset.

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 22 05:59:03 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/5b40343e96c7
changeset: 7033:5b40343e96c7
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 22 05:49:26 2007 +0200
description:
Avoid moving raw stream offset.

diffstat:

2 files changed, 8 insertions(+), 1 deletion(-)
src/lib-storage/index/mbox/istream-raw-mbox.c |    4 ++++
src/lib-storage/index/mbox/mbox-mail.c        |    5 ++++-

diffs (61 lines):

diff -r 85cf52f0bc64 -r 5b40343e96c7 src/lib-storage/index/mbox/istream-raw-mbox.c
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Dec 22 05:15:51 2007 +0200
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Dec 22 05:49:26 2007 +0200
@@ -475,6 +475,7 @@ uoff_t istream_raw_mbox_get_body_size(st
 		(struct raw_mbox_istream *)stream->real_stream;
 	const unsigned char *data;
 	size_t size;
+	uoff_t old_offset;
 
 	i_assert(rstream->hdr_offset != (uoff_t)-1);
 	i_assert(rstream->body_offset != (uoff_t)-1);
@@ -484,12 +485,14 @@ uoff_t istream_raw_mbox_get_body_size(st
 			(rstream->body_offset - rstream->hdr_offset);
 	}
 
+	old_offset = stream->v_offset;
 	if (body_size != (uoff_t)-1) {
 		i_stream_seek(rstream->istream.parent,
 			      rstream->body_offset + body_size);
 		if (istream_raw_mbox_is_valid_from(rstream) > 0) {
 			rstream->mail_size = body_size +
 				(rstream->body_offset - rstream->hdr_offset);
+			i_stream_seek(stream, old_offset);
 			return body_size;
 		}
 	}
@@ -497,6 +500,7 @@ uoff_t istream_raw_mbox_get_body_size(st
 	/* have to read through the message body */
 	while (i_stream_read_data(stream, &data, &size, 0) > 0)
 		i_stream_skip(stream, size);
+	i_stream_seek(stream, old_offset);
 
 	i_assert(rstream->mail_size != (uoff_t)-1);
 	return rstream->mail_size -
diff -r 85cf52f0bc64 -r 5b40343e96c7 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c	Sat Dec 22 05:15:51 2007 +0200
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Sat Dec 22 05:49:26 2007 +0200
@@ -174,12 +174,13 @@ static int mbox_mail_get_physical_size(s
 	const struct mail_index_header *hdr;
 	struct istream *input;
 	struct message_size hdr_size;
-	uoff_t body_offset, body_size, next_offset;
+	uoff_t old_offset, body_offset, body_size, next_offset;
 
 	if (index_mail_get_physical_size(_mail, size_r) == 0)
 		return 0;
 
 	/* we want to return the header size as seen by mail_get_stream(). */
+	old_offset = data->stream == NULL ? 0 : data->stream->v_offset;
 	if (mail_get_stream(_mail, &hdr_size, NULL, &input) < 0)
 		return -1;
 
@@ -215,6 +216,8 @@ static int mbox_mail_get_physical_size(s
 
 	data->physical_size = hdr_size.physical_size + body_size;
 	*size_r = data->physical_size;
+
+	i_stream_seek(input, old_offset);
 	return 0;
 }
 


More information about the dovecot-cvs mailing list