changeset 112:d6105a8a6ca9 HEAD

Fixed rfc822_tokens_get_value(). It doesn't have "put spaces around all tokens" option anymore, but instead spaces are always put between atoms. This should fix address fields with non-7bit charset.
author Timo Sirainen <tss@iki.fi>
date Mon, 02 Sep 2002 20:10:52 +0300
parents 8a9c6b71761f
children 76a3a6c0c452
files src/lib-imap/imap-bodystructure.c src/lib-mail/message-parser.c src/lib-mail/rfc822-address.c src/lib-mail/rfc822-tokenize.c src/lib-mail/rfc822-tokenize.h
diffstat 5 files changed, 36 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap/imap-bodystructure.c	Mon Sep 02 14:39:00 2002 +0300
+++ b/src/lib-imap/imap-bodystructure.c	Mon Sep 02 20:10:52 2002 +0300
@@ -44,10 +44,10 @@
 			break;
 	}
 
-	value = rfc822_tokens_get_value_quoted(tokens, i, FALSE);
+	value = rfc822_tokens_get_value_quoted(tokens, i);
 	data->content_type = p_strdup(data->pool, value);
 
-	value = rfc822_tokens_get_value_quoted(tokens+i+1, count-i-1, FALSE);
+	value = rfc822_tokens_get_value_quoted(tokens+i+1, count-i-1);
 	data->content_subtype = p_strdup(data->pool, value);
 }
 
@@ -65,7 +65,7 @@
 	t_string_append_n(data->str, name->ptr, name->len);
 	t_string_append(data->str, "\" ");
 
-        str = rfc822_tokens_get_value_quoted(value, value_count, FALSE);
+        str = rfc822_tokens_get_value_quoted(value, value_count);
 	t_string_append(data->str, str);
 }
 
@@ -75,7 +75,7 @@
         MessagePartBodyData *data = context;
 	const char *value;
 
-	value = rfc822_tokens_get_value_quoted(tokens, count, FALSE);
+	value = rfc822_tokens_get_value_quoted(tokens, count);
 	data->content_transfer_encoding = p_strdup(data->pool, value);
 }
 
@@ -85,7 +85,7 @@
         MessagePartBodyData *data = context;
 	const char *value;
 
-	value = rfc822_tokens_get_value_quoted(tokens, count, FALSE);
+	value = rfc822_tokens_get_value_quoted(tokens, count);
 	data->content_disposition = p_strdup(data->pool, value);
 }
 
@@ -98,7 +98,7 @@
 	if (count <= 0)
 		return;
 
-	value = rfc822_tokens_get_value_quoted(tokens, count, FALSE);
+	value = rfc822_tokens_get_value_quoted(tokens, count);
 	data->content_language = p_strdup(data->pool, value);
 
 	/* FIXME: a,b,c -> "a" "b" "c" */
--- a/src/lib-mail/message-parser.c	Mon Sep 02 14:39:00 2002 +0300
+++ b/src/lib-mail/message-parser.c	Mon Sep 02 20:10:52 2002 +0300
@@ -74,7 +74,7 @@
 	if (parse_ctx->last_content_type != NULL)
 		return;
 
-	str = rfc822_tokens_get_value(tokens, count, FALSE);
+	str = rfc822_tokens_get_value(tokens, count);
 	parse_ctx->last_content_type = p_strdup(parse_ctx->pool, str);
 
 	if (strcasecmp(str, "message/rfc822") == 0)
@@ -103,7 +103,7 @@
 		return;
 
 	if (parse_ctx->last_boundary == NULL) {
-		str = rfc822_tokens_get_value(value, value_count, FALSE);
+		str = rfc822_tokens_get_value(value, value_count);
 		parse_ctx->last_boundary = p_strdup(parse_ctx->pool, str);
 	}
 }
--- a/src/lib-mail/rfc822-address.c	Mon Sep 02 14:39:00 2002 +0300
+++ b/src/lib-mail/rfc822-address.c	Mon Sep 02 20:10:52 2002 +0300
@@ -52,7 +52,7 @@
 
 	count = read_until(*tokens, stop_tokens, comment);
 	if (count > 0) {
-		value = rfc822_tokens_get_value(*tokens, count, FALSE);
+		value = rfc822_tokens_get_value(*tokens, count);
 		t_string_append(phrase, value);
 
 		*tokens += count;
@@ -65,7 +65,7 @@
 	TempString *mailbox, *domain, *route, *name, *comment, *next_phrase;
 	const Rfc822Token *tokens;
 	const char *list, *value;
-	int ingroup, stop, count, spaces;
+	int ingroup, stop, count;
 
 	if (str == NULL || *str == '\0')
 		return NULL;
@@ -96,13 +96,14 @@
 	while (!stop) {
 		count = read_until(tokens, list, comment);
 		if (count > 0) {
-			/* put spaces around tokens if we're parsing name */
-			spaces = tokens[count].token == '<' ||
-				next_phrase == name;
-			if (spaces && next_phrase->len > 0)
+			if ((tokens[count].token == '<' ||
+			     next_phrase == name) && next_phrase->len > 0) {
+				/* continuing previously started name,
+				   separate it from us with space */
 				t_string_append_c(next_phrase, ' ');
+			}
 
-			value = rfc822_tokens_get_value(tokens, count, spaces);
+			value = rfc822_tokens_get_value(tokens, count);
 			t_string_append(next_phrase, value);
 			tokens += count;
 		}
--- a/src/lib-mail/rfc822-tokenize.c	Mon Sep 02 14:39:00 2002 +0300
+++ b/src/lib-mail/rfc822-tokenize.c	Mon Sep 02 20:10:52 2002 +0300
@@ -185,11 +185,11 @@
 	return first_token;
 }
 
-const char *rfc822_tokens_get_value(const Rfc822Token *tokens, int count,
-				    int space_separators)
+const char *rfc822_tokens_get_value(const Rfc822Token *tokens, int count)
 {
 	char *buf;
 	unsigned int i, len, buf_size;
+	int last_atom;
 
 	if (count <= 0)
 		return "";
@@ -197,7 +197,7 @@
 	buf_size = 256;
 	buf = t_buffer_get(buf_size);
 
-	len = 0;
+	len = 0; last_atom = FALSE;
 	for (; count > 0; count--, tokens++) {
 		if (tokens->token == '(')
 			continue; /* skip comments */
@@ -208,9 +208,6 @@
 			buf = t_buffer_reget(buf, buf_size);
 		}
 
-		if (space_separators && len > 0)
-			buf[len++] = ' ';
-
 		switch (tokens->token) {
 		case '"':
 		case '[':
@@ -229,6 +226,9 @@
 				buf[len++] = ']';
 			break;
 		case 'A':
+			if (last_atom)
+				buf[len++] = ' ';
+
 			memcpy(buf+len, tokens->ptr, tokens->len);
 			len += tokens->len;
 			break;
@@ -237,6 +237,8 @@
 			buf[len++] = (char) tokens->token;
 			break;
 		}
+
+		last_atom = tokens->token == 'A';
 	}
 
 	buf[len++] = '\0';
@@ -245,17 +247,18 @@
 }
 
 const char *rfc822_tokens_get_value_quoted(const Rfc822Token *tokens,
-					   int count, int space_separators)
+					   int count)
 {
 	char *buf;
 	unsigned int len, buf_size;
+	int last_atom;
 
 	if (count <= 0)
 		return "\"\"";
 
 	buf_size = 256;
 	buf = t_buffer_get(buf_size);
-	buf[0] = '"'; len = 1;
+	buf[0] = '"'; len = 1; last_atom = FALSE;
 
 	for (; count > 0; count--, tokens++) {
 		if (tokens->token == '(')
@@ -267,9 +270,6 @@
 			buf = t_buffer_reget(buf, buf_size);
 		}
 
-		if (space_separators && len > 0)
-			buf[len++] = ' ';
-
 		switch (tokens->token) {
 		case '"':
 		case '[':
@@ -283,6 +283,9 @@
 				buf[len++] = ']';
 			break;
 		case 'A':
+			if (last_atom)
+				buf[len++] = ' ';
+
 			memcpy(buf+len, tokens->ptr, tokens->len);
 			len += tokens->len;
 			break;
@@ -291,6 +294,8 @@
 			buf[len++] = (char) tokens->token;
 			break;
 		}
+
+		last_atom = tokens->token == 'A';
 	}
 
 	buf[len++] = '"';
--- a/src/lib-mail/rfc822-tokenize.h	Mon Sep 02 14:39:00 2002 +0300
+++ b/src/lib-mail/rfc822-tokenize.h	Mon Sep 02 20:10:52 2002 +0300
@@ -48,11 +48,11 @@
 				   Rfc822TokenizeErrorFunc error_func,
 				   void *context);
 
-/* Returns the tokens as a string. */
-const char *rfc822_tokens_get_value(const Rfc822Token *tokens, int count,
-				    int space_separators);
+/* Returns the tokens as a string. Tokens are merged together, except
+   spaces are added between atoms. */
+const char *rfc822_tokens_get_value(const Rfc822Token *tokens, int count);
 /* Returns the tokens as a "string". */
 const char *rfc822_tokens_get_value_quoted(const Rfc822Token *tokens,
-					   int count, int space_separators);
+					   int count);
 
 #endif