changeset 2167:9f318b950ea7 HEAD

fix
author Timo Sirainen <tss@iki.fi>
date Sat, 19 Jun 2004 04:00:41 +0300
parents ed6b3d59ce93
children d6687626c6a1
files src/lib-storage/index/mbox/istream-raw-mbox.c
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Jun 19 04:00:09 2004 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Jun 19 04:00:41 2004 +0300
@@ -197,7 +197,7 @@
 	   because all characters are different in mbox_from. */
         fromp = mbox_from; from_start_pos = 0;
 	eoh_char = rstream->body_offset == (uoff_t)-1 ? '\n' : '\0';
-	for (i = 0; i < pos; i++) {
+	for (i = stream->pos; i < pos; i++) {
 		if (buf[i] == eoh_char && i > 0 && buf[i-1] == '\n') {
 			rstream->body_offset = stream->istream.v_offset + i + 1;
 			eoh_char = '\0';
@@ -209,13 +209,13 @@
 				   FIXME: if From-line is longer than input
 				   buffer, we break. probably irrelevant.. */
 				i++;
-				from_start_pos = i;
+				from_start_pos = i - 6;
 				fromp = mbox_from;
 			} else if (from_start_pos != 0) {
 				/* we have the whole From-line here now.
 				   See if it's a valid one. */
-				if (mbox_from_parse(buf + from_start_pos,
-						    pos - from_start_pos,
+				if (mbox_from_parse(buf + from_start_pos + 6,
+						    pos - from_start_pos - 6,
 						    &received_time,
 						    &sender) == 0) {
 					/* yep, we stop here. */
@@ -225,9 +225,6 @@
 					rstream->next_sender = sender;
 					rstream->eom = TRUE;
 
-                                        /* rewind "\nFrom " */
-					from_start_pos -= 6;
-
 					handle_end_of_mail(rstream,
 							   from_start_pos);
 					break;
@@ -251,11 +248,16 @@
 		/* leave out the beginnings of potential From-line */
 		new_pos = i - (fromp - mbox_from);
 	}
-	i_assert(new_pos > stream->pos);
-	ret = new_pos - stream->pos;
+
+	if (new_pos == stream->pos)
+		ret = -2;
+	else {
+		i_assert(new_pos > stream->pos);
+		ret = new_pos - stream->pos;
+		stream->pos = new_pos;
+	}
 
 	stream->buffer = buf;
-	stream->pos = new_pos;
 	return ret;
 }