changeset 9015:05a98aaf0aaf HEAD

Try to skip over errors in Content-Type parameters.
author Timo Sirainen <tss@iki.fi>
date Mon, 04 May 2009 12:32:59 -0400
parents e569d73e9056
children 6770f46971af
files src/lib-mail/rfc2231-parser.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-mail/rfc2231-parser.c	Sun May 03 22:04:39 2009 -0400
+++ b/src/lib-mail/rfc2231-parser.c	Mon May 04 12:32:59 2009 -0400
@@ -46,7 +46,7 @@
 	const char *key, *value, *p, *p2;
 	string_t *str;
 	unsigned int i, j, count, next, next_idx;
-	bool ok, have_extended;
+	bool ok, have_extended, broken = FALSE;
 	int ret;
 
 	/* Get a list of all parameters. RFC 2231 uses key*<n>[*]=value pairs,
@@ -55,7 +55,15 @@
 	memset(&rfc2231_param, 0, sizeof(rfc2231_param));
 	t_array_init(&result, 8);
 	t_array_init(&rfc2231_params_arr, 8);
-	while ((ret = rfc822_parse_content_param(ctx, &key, &value)) > 0) {
+	while ((ret = rfc822_parse_content_param(ctx, &key, &value)) != 0) {
+		if (ret < 0) {
+			/* try to continue anyway.. */
+			broken = TRUE;
+			if (ctx->data == ctx->end)
+				break;
+			ctx->data++;
+			continue;
+		}
 		p = strchr(key, '*');
 		if (p != NULL) {
 			p2 = p++;
@@ -89,7 +97,7 @@
 		/* No RFC 2231 parameters */
 		(void)array_append_space(&result); /* NULL-terminate */
 		*result_r = array_idx(&result, 0);
-		return ret;
+		return broken ? -1 : 0;
 	}
 
 	/* Merge the RFC 2231 parameters. Since their order isn't guaranteed to
@@ -157,5 +165,5 @@
 	}
 	(void)array_append_space(&result); /* NULL-terminate */
 	*result_r = array_idx(&result, 0);
-	return ret;
+	return broken ? -1 : 0;
 }