[dovecot-cvs] dovecot/src/lib-mail message-parser.c,1.27,1.28 message-send.c,1.12,1.13 message-size.c,1.9,1.10 message-size.h,1.6,1.7

cras at procontrol.fi cras at procontrol.fi
Fri Dec 27 15:05:55 EET 2002


Update of /home/cvs/dovecot/src/lib-mail
In directory danu:/tmp/cvs-serv6080/lib-mail

Modified Files:
	message-parser.c message-send.c message-size.c message-size.h 
Log Message:
Some bugfixes and speedups for partial fetch handling.



Index: message-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-parser.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- message-parser.c	8 Dec 2002 05:23:08 -0000	1.27
+++ message-parser.c	27 Dec 2002 13:05:53 -0000	1.28
@@ -549,7 +549,7 @@
 	MessageBoundary *boundary;
 
 	if (boundaries == NULL) {
-		message_get_body_size(input, body_size, (uoff_t)-1);
+		message_get_body_size(input, body_size, (uoff_t)-1, NULL);
 		return NULL;
 	} else {
 		boundary = message_find_boundary(input, boundaries,

Index: message-send.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-send.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- message-send.c	6 Dec 2002 01:09:23 -0000	1.12
+++ message-send.c	27 Dec 2002 13:05:53 -0000	1.13
@@ -37,26 +37,19 @@
 	message_skip_virtual(input, virtual_skip, NULL, &cr_skipped);
 
 	/* go through the message data and insert CRs where needed.  */
-	while (i_stream_read_data(input, &msg, &size, 0) > 0) {
+	while (max_virtual_size > 0 &&
+	       i_stream_read_data(input, &msg, &size, 0) > 0) {
 		add_cr = FALSE;
-		for (i = 0; i < size; i++) {
+		for (i = 0; i < size && max_virtual_size > 0; i++) {
+			max_virtual_size--;
+
 			if (msg[i] == '\n') {
 				if ((i == 0 && !cr_skipped) ||
 				    (i > 0 && msg[i-1] != '\r')) {
 					/* missing CR */
-					if (max_virtual_size > 0)
-						max_virtual_size--;
 					add_cr = TRUE;
 					break;
 				}
-
-			}
-
-			if (max_virtual_size > 0) {
-				if (--max_virtual_size == 0) {
-					i++;
-					break;
-				}
 			}
 		}
 
@@ -70,10 +63,6 @@
 		} else {
 			cr_skipped = i > 0 && msg[i-1] == '\r';
 		}
-
-		/* see if we've reached the limit */
-		if (max_virtual_size == 0)
-			break;
 
 		i_stream_skip(input, i);
 	}

Index: message-size.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-size.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- message-size.c	18 Dec 2002 15:15:41 -0000	1.9
+++ message-size.c	27 Dec 2002 13:05:53 -0000	1.10
@@ -56,40 +56,44 @@
 }
 
 void message_get_body_size(IStream *input, MessageSize *body,
-			   uoff_t max_virtual_size)
+			   uoff_t max_virtual_size, int *last_cr)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos, missing_cr_count;
+	int cr;
 
 	memset(body, 0, sizeof(MessageSize));
 
+	cr = 0;
 	missing_cr_count = 0; startpos = 0;
 	while (max_virtual_size != 0 &&
 	       i_stream_read_data(input, &msg, &size, startpos) > 0) {
-		for (i = startpos; i < size && max_virtual_size != 0; i++) {
-			if (max_virtual_size > 0)
-				max_virtual_size--;
-
-			if (msg[i] != '\n')
-				continue;
+		cr = 0;
+		for (i = startpos; i < size && max_virtual_size > 0; i++) {
+			max_virtual_size--;
 
-			if (i == 0 || msg[i-1] != '\r') {
-				/* missing CR */
-				missing_cr_count++;
+			if (msg[i] == '\n') {
+				if (i == 0 || msg[i-1] != '\r') {
+					/* missing CR */
+					missing_cr_count++;
 
-				if (max_virtual_size > 0) {
-					if (max_virtual_size == 0)
+					if (max_virtual_size == 0) {
+						cr = 2;
 						break;
+					}
 
 					max_virtual_size--;
 				}
-			}
 
-			/* increase after making sure we didn't break
-			   at virtual \r */
-			body->lines++;
+				/* increase after making sure we didn't break
+				   at virtual \r */
+				body->lines++;
+			}
 		}
 
+		if (cr == 0 && i > 0 && msg[i-1] == '\r')
+			cr = 1;
+
 		/* leave the last character, it may be \r */
 		i_stream_skip(input, i - 1);
 		startpos = 1;
@@ -101,6 +105,9 @@
 
 	body->virtual_size = body->physical_size + missing_cr_count;
 	i_assert(body->virtual_size >= body->physical_size);
+
+	if (last_cr != NULL)
+		*last_cr = cr;
 }
 
 void message_skip_virtual(IStream *input, uoff_t virtual_skip,

Index: message-size.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-size.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- message-size.h	18 Dec 2002 15:15:41 -0000	1.6
+++ message-size.h	27 Dec 2002 13:05:53 -0000	1.7
@@ -7,9 +7,10 @@
    character in body. */
 void message_get_header_size(IStream *input, MessageSize *hdr);
 /* Calculate size of message body. Read only max_virtual_size virtual bytes,
-   if you want it unlimited, use (uoff_t)-1. */
+   if you want it unlimited, use (uoff_t)-1. If last_cr is not NULL, it's set
+   to 1 if last character is CR, 2 if it's virtual CR. */
 void message_get_body_size(IStream *input, MessageSize *body,
-			   uoff_t max_virtual_size);
+			   uoff_t max_virtual_size, int *last_cr);
 
 /* Skip number of virtual bytes from putfer. If first character is \n, and
    cr_skipped is FALSE, \r must be sent before it. msg_size is updated if




More information about the dovecot-cvs mailing list