[dovecot-cvs] dovecot/src/lib-mail message-address.c,1.2,1.3 message-parser.c,1.35,1.36

cras at procontrol.fi cras at procontrol.fi
Tue Feb 25 21:10:05 EET 2003


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

Modified Files:
	message-address.c message-parser.c 
Log Message:
A few small fixes to MIME and mail address parsers.



Index: message-address.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-address.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- message-address.c	20 Jan 2003 14:52:51 -0000	1.2
+++ message-address.c	25 Feb 2003 19:10:03 -0000	1.3
@@ -64,6 +64,7 @@
 	*/
 	tok = message_tokenize_init(data, size, NULL, NULL);
 	message_tokenize_skip_comments(tok, FALSE);
+        message_tokenize_dot_token(tok, FALSE);
 
 	t_push();
 	mailbox = t_str_new(128);
@@ -112,8 +113,8 @@
 				addr->route = str_len(route) == 0 ? NULL :
 					p_strdup(pool, str_c(route));
 				addr->name = next_phrase == name ?
-					p_strdup(pool, str_c(name)) :
-					p_strdup(pool, str_c(comment));
+					p_strdup_empty(pool, str_c(name)) :
+					p_strdup_empty(pool, str_c(comment));
 			}
 
 			if (ingroup && token == ';') {

Index: message-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-parser.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- message-parser.c	31 Jan 2003 06:11:25 -0000	1.35
+++ message-parser.c	25 Feb 2003 19:10:03 -0000	1.36
@@ -269,9 +269,8 @@
 	return part;
 }
 
-/* skip over to next line increasing message size */
 static void message_skip_line(struct istream *input,
-			      struct message_size *msg_size)
+			      struct message_size *msg_size, int skip_lf)
 {
 	const unsigned char *msg;
 	size_t i, size, startpos;
@@ -281,20 +280,23 @@
 	while (i_stream_read_data(input, &msg, &size, startpos) > 0) {
 		for (i = startpos; i < size; i++) {
 			if (msg[i] == '\n') {
+				if (!skip_lf) {
+					if (i > 0 && msg[i-1] == '\r')
+						i--;
+					startpos = i;
+					goto __break;
+				}
+
 				if (msg_size != NULL) {
 					if (i == 0 || msg[i-1] != '\r')
 						msg_size->virtual_size++;
 					msg_size->lines++;
 				}
-				break;
+				startpos = i+1;
+				goto __break;
 			}
 		}
 
-		if (i < size) {
-			startpos = i+1;
-			break;
-		}
-
 		/* leave the last character, it may be \r */
 		i_stream_skip(input, i - 1);
 		startpos = 1;
@@ -304,7 +306,7 @@
 			msg_size->virtual_size += i - 1;
 		}
 	}
-
+__break:
 	i_stream_skip(input, startpos);
 
 	if (msg_size != NULL) {
@@ -333,7 +335,7 @@
 			/* overflow, line is too long. just skip it. */
 			i_assert(size > 2);
 
-                        message_skip_line(input, hdr_size);
+                        message_skip_line(input, hdr_size, TRUE);
 			startpos = line_start = 0;
 			colon_pos = UINT_MAX;
 			continue;
@@ -389,13 +391,11 @@
 						end_pos--;
 					name_len = end_pos - line_start + 1;
 
-					/* get length of value field. skip
-					   only the initial LWSP after ':'.
-					   some fields may want to keep
-					   the extra spaces.. */
+					/* get length of value field.
+					   skip all LWSP after ':'. */
 					colon_pos++;
-					if (colon_pos < i &&
-					    IS_LWSP(msg[colon_pos]))
+					while (colon_pos < i &&
+					       IS_LWSP(msg[colon_pos]))
 						colon_pos++;
 					value_len = i - colon_pos;
 					if (msg[i-1] == '\r') value_len--;
@@ -520,7 +520,8 @@
 			/* leave the last line to buffer, it may be
 			   boundary */
 			i = line_start;
-			if (i > 2) i -= 2; /* leave the \r\n too */
+			if (i > 0) i--; /* leave the \r\n too */
+			if (i > 0) i--;
 			line_start -= i;
 		}
 
@@ -531,6 +532,14 @@
 		startpos = size - i;
 	}
 
+	if (boundary == NULL && line_start+2 <= size &&
+	    msg[line_start] == '-' && msg[line_start+1] == '-') {
+		/* possible boundary without line feed at end */
+		boundary = boundary_find(boundaries,
+					 msg + line_start + 2,
+					 size - line_start - 2);
+	}
+
 	if (boundary != NULL) {
 		if (skip_over) {
 			/* leave the pointer right after the boundary */
@@ -559,16 +568,18 @@
 
 static struct message_part *
 message_parse_body(struct istream *input, struct message_boundary *boundaries,
-		   struct message_size *body_size)
+		   struct message_size *msg_size)
 {
 	struct message_boundary *boundary;
+	struct message_size body_size;
 
 	if (boundaries == NULL) {
-		message_get_body_size(input, body_size, (uoff_t)-1, NULL);
+		message_get_body_size(input, &body_size, (uoff_t)-1, NULL);
+		message_size_add(msg_size, &body_size);
 		return NULL;
 	} else {
 		boundary = message_find_boundary(input, boundaries,
-						 body_size, FALSE);
+						 msg_size, FALSE);
 		return boundary == NULL ? NULL : boundary->part;
 	}
 }
@@ -596,11 +607,11 @@
 		end_boundary = msg[0] == '-' && msg[1] == '-';
 
 	/* skip the rest of the line */
-	message_skip_line(input, boundary_size);
+	message_skip_line(input, boundary_size, !end_boundary);
 
 	if (end_boundary) {
 		/* skip the footer */
-		return message_parse_body(input, boundaries, boundary_size);
+		return message_parse_body(input, boundary->next, boundary_size);
 	}
 
 	return boundary == NULL ? NULL : boundary->part;




More information about the dovecot-cvs mailing list