changeset 4435:ccd102aef7ad HEAD

Fixes to handling CR+LF linefeeds.
author Timo Sirainen <tss@iki.fi>
date Sat, 24 Jun 2006 23:53:37 +0300
parents 7fd600d3f719
children 2b7254c5809c
files src/lib-storage/index/mbox/istream-raw-mbox.c src/lib-storage/index/mbox/mbox-sync-rewrite.c src/lib-storage/index/mbox/mbox-sync-update.c
diffstat 3 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Jun 24 22:02:40 2006 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Jun 24 23:53:37 2006 +0300
@@ -107,12 +107,15 @@
 	if (rstream->hdr_offset + rstream->mail_size < rstream->body_offset) {
 		/* a) Header didn't have ending \n
 		   b) "headers\n\nFrom ..", the second \n belongs to next
-		   message which we didn't know at the time yet. */
+		   message which we didn't know at the time yet.
+
+		   The +2 check is for CR+LF linefeeds */
+		uoff_t new_body_offset =
+			rstream->hdr_offset + rstream->mail_size;
 		i_assert(rstream->body_offset == (uoff_t)-1 ||
-			 rstream->body_offset ==
-			 rstream->hdr_offset + rstream->mail_size + 1);
-		rstream->body_offset =
-			rstream->hdr_offset + rstream->mail_size;
+			 rstream->body_offset == new_body_offset + 1 ||
+			 rstream->body_offset == new_body_offset + 2);
+		rstream->body_offset = new_body_offset;
 	}
 }
 
@@ -190,6 +193,13 @@
 
 	if (stream->istream.v_offset == rstream->from_offset) {
 		/* beginning of message, we haven't yet read our From-line */
+		if (pos == 2) {
+			/* we're at the end of file with CR+LF linefeeds?
+			   need more data to verify it. */
+			rstream->input_peak_offset =
+				stream->istream.v_offset + pos;
+			return _read(stream);
+		}
 		if (mbox_read_from_line(rstream) < 0) {
 			stream->pos = 0;
 			rstream->eof = TRUE;
--- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Sat Jun 24 22:02:40 2006 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Sat Jun 24 23:53:37 2006 +0300
@@ -111,7 +111,7 @@
 			if (pos+1 == data_size || !IS_LWSP(data[pos+1]))
 				break;
 			start_pos = pos+1;
-		} else if (!IS_LWSP(data[pos])) {
+		} else if (!IS_LWSP(data[pos]) && data[pos] != '\r') {
 			start_pos = pos+1;
 		}
 	}
@@ -152,7 +152,7 @@
 				break;
 			}
                         last_line_pos = pos+1;
-		} else if (!IS_LWSP(data[pos])) {
+		} else if (!IS_LWSP(data[pos]) && data[pos] != '\r') {
 			start_pos = last_line_pos = pos+1;
 		}
 	}
--- a/src/lib-storage/index/mbox/mbox-sync-update.c	Sat Jun 24 22:02:40 2006 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-update.c	Sat Jun 24 23:53:37 2006 +0300
@@ -90,7 +90,7 @@
 	/* how many bytes do we have now? */
 	data = buffer_get_modifyable_data(ctx->header, &size);
 	for (have = 0; pos < size; pos++) {
-		if (data[pos] == '\n')
+		if (data[pos] == '\n' || data[pos] == '\r')
 			break;
 
 		/* see if this is unknown flag for us */