changeset 3596:71472bab2cbb HEAD

Parse obs-phrase correctly. Patch by Chris Wakelin
author Timo Sirainen <tss@iki.fi>
date Fri, 23 Sep 2005 15:03:48 +0300
parents 4d2ee2274c70
children aeb53e34d1f4
files src/lib-mail/rfc822-parser.c
diffstat 1 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-mail/rfc822-parser.c	Sun Sep 18 21:18:50 2005 +0300
+++ b/src/lib-mail/rfc822-parser.c	Fri Sep 23 15:03:48 2005 +0300
@@ -230,19 +230,55 @@
 	return -1;
 }
 
+static int
+rfc822_parse_atom_or_dot(struct rfc822_parser_context *ctx, string_t *str)
+{
+	const unsigned char *start;
+
+	/*
+	   atom            = [CFWS] 1*atext [CFWS]
+	   atext           =
+	     ; Any character except controls, SP, and specials.
+
+	   The difference between this function and rfc822_parse_dot_atom()
+	   is that this doesn't just silently skip over all the whitespace.
+	*/
+	for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
+		if (IS_ATEXT(*ctx->data) || *ctx->data == '.')
+			continue;
+
+		str_append_n(str, start, ctx->data - start);
+		return rfc822_skip_lwsp(ctx);
+	}
+
+	str_append_n(str, start, ctx->data - start);
+	return 0;
+}
+
 int rfc822_parse_phrase(struct rfc822_parser_context *ctx, string_t *str)
 {
 	int ret;
 
+	/*
+	   phrase     = 1*word / obs-phrase
+	   word       = atom / quoted-string
+	   obs-phrase = word *(word / "." / CFWS)
+	*/
+
+	if (*ctx->data == '.')
+		return -1;
+
 	for (;;) {
 		if (*ctx->data == '"')
 			ret = rfc822_parse_quoted_string(ctx, str);
 		else
-			ret = rfc822_parse_atom(ctx, str);
+			ret = rfc822_parse_atom_or_dot(ctx, str);
+
 		if (ret <= 0)
 			return ret;
 
-		if (!IS_ATEXT(*ctx->data) && *ctx->data != '"')
+		if (!IS_ATEXT(*ctx->data) && *ctx->data != '"'
+		    && *ctx->data != '.')
 			break;
 		str_append_c(str, ' ');
 	}