dovecot-2.2: lib-imap: bodystructure parsing now uses imap_appen...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 24 11:22:52 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/cb143b430787
changeset: 15248:cb143b430787
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 24 11:22:28 2012 +0300
description:
lib-imap: bodystructure parsing now uses imap_append_string() instead of imap_quote*()
Some of the fields are parsed through rfc822_*() which guarantees that they
contain proper clean input. Other fields are also machine-readable and don't
benefit from having whitespace compressed or of any other things that
imap_quote*(fix_text=TRUE) did.

None of the fields in

diffstat:

 src/lib-imap/imap-bodystructure.c |  68 ++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 35 deletions(-)

diffs (152 lines):

diff -r 9a17faaed2eb -r cb143b430787 src/lib-imap/imap-bodystructure.c
--- a/src/lib-imap/imap-bodystructure.c	Wed Oct 24 10:14:17 2012 +0300
+++ b/src/lib-imap/imap-bodystructure.c	Wed Oct 24 11:22:28 2012 +0300
@@ -20,6 +20,14 @@
 
 #define NVL(str, nullstr) ((str) != NULL ? (str) : (nullstr))
 
+static char *imap_get_string(pool_t pool, const char *value)
+{
+	string_t *str = t_str_new(64);
+
+	imap_append_string(str, value);
+	return p_strdup(pool, str_c(str));
+}
+
 static void parse_content_type(struct message_part_body_data *data,
 			       struct message_header_line *hdr)
 {
@@ -41,12 +49,12 @@
 	for (i = 0; value[i] != '\0'; i++) {
 		if (value[i] == '/') {
 			data->content_subtype =
-				imap_quote(data->pool, str_data(str) + i + 1,
-					   str_len(str) - (i + 1), TRUE);
+				imap_get_string(data->pool, value + i+1);
 			break;
 		}
 	}
-	data->content_type = imap_quote(data->pool, str_data(str), i, TRUE);
+	str_truncate(str, i);
+	data->content_type = imap_get_string(data->pool, str_c(str));
 
 	/* parse parameters and save them */
 	str_truncate(str, 0);
@@ -56,9 +64,9 @@
 			charset_found = TRUE;
 
 		str_append_c(str, ' ');
-		imap_quote_append_string(str, results[0], TRUE);
+		imap_append_string(str, results[0]);
 		str_append_c(str, ' ');
-		imap_quote_append_string(str, results[1], TRUE);
+		imap_append_string(str, results[1]);
 	}
 
 	if (!charset_found &&
@@ -85,8 +93,7 @@
 	str = t_str_new(256);
 	if (rfc822_parse_mime_token(&parser, str) >= 0) {
 		data->content_transfer_encoding =
-			imap_quote(data->pool, str_data(str),
-				   str_len(str), TRUE);
+			imap_get_string(data->pool, str_c(str));
 	}
 }
 
@@ -103,17 +110,16 @@
 	str = t_str_new(256);
 	if (rfc822_parse_mime_token(&parser, str) < 0)
 		return;
-	data->content_disposition =
-		imap_quote(data->pool, str_data(str), str_len(str), TRUE);
+	data->content_disposition = imap_get_string(data->pool, str_c(str));
 
 	/* parse parameters and save them */
 	str_truncate(str, 0);
 	rfc2231_parse(&parser, &results);
 	for (; *results != NULL; results += 2) {
 		str_append_c(str, ' ');
-		imap_quote_append_string(str, results[0], TRUE);
+		imap_append_string(str, results[0]);
 		str_append_c(str, ' ');
-		imap_quote_append_string(str, results[1], TRUE);
+		imap_append_string(str, results[1]);
 	}
 	if (str_len(str) > 0) {
 		data->content_disposition_params =
@@ -158,32 +164,26 @@
 				 pool_t pool)
 {
 	const char *name = hdr->name + strlen("Content-");
-	const unsigned char *value;
-	size_t value_len;
+	const char *value;
 
 	if (hdr->continues) {
 		hdr->use_full_value = TRUE;
 		return;
 	}
 
-	value = hdr->full_value;
-	value_len = hdr->full_value_len;
+	value = t_strndup(hdr->full_value, hdr->full_value_len);
 
 	switch (*name) {
 	case 'i':
 	case 'I':
-		if (strcasecmp(name, "ID") == 0 && d->content_id == NULL) {
-			d->content_id =
-				imap_quote(pool, value, value_len, TRUE);
-		}
+		if (strcasecmp(name, "ID") == 0 && d->content_id == NULL)
+			d->content_id = imap_get_string(pool, value);
 		break;
 
 	case 'm':
 	case 'M':
-		if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL) {
-			d->content_md5 =
-				imap_quote(pool, value, value_len, TRUE);
-		}
+		if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL)
+			d->content_md5 = imap_get_string(pool, value);
 		break;
 
 	case 't':
@@ -198,25 +198,23 @@
 	case 'l':
 	case 'L':
 		if (strcasecmp(name, "Language") == 0 &&
-		    d->content_language == NULL)
-			parse_content_language(value, value_len, d);
-		else if (strcasecmp(name, "Location") == 0 &&
-			 d->content_location == NULL) {
-			d->content_location =
-				imap_quote(pool, value, value_len, TRUE);
+		    d->content_language == NULL) {
+			parse_content_language(hdr->full_value,
+					       hdr->full_value_len, d);
+		} else if (strcasecmp(name, "Location") == 0 &&
+			   d->content_location == NULL) {
+			d->content_location = imap_get_string(pool, value);
 		}
 		break;
 
 	case 'd':
 	case 'D':
 		if (strcasecmp(name, "Description") == 0 &&
-		    d->content_description == NULL) {
-			d->content_description =
-				imap_quote(pool, value, value_len, TRUE);
-		} else if (strcasecmp(name, "Disposition") == 0 &&
-			   d->content_disposition_params == NULL) {
+		    d->content_description == NULL)
+			d->content_description = imap_get_string(pool, value);
+		else if (strcasecmp(name, "Disposition") == 0 &&
+			 d->content_disposition_params == NULL)
 			parse_content_disposition(d, hdr);
-		}
 		break;
 	}
 }


More information about the dovecot-cvs mailing list