# HG changeset patch # User Timo Sirainen # Date 1030986652 -10800 # Node ID d6105a8a6ca98e39dd18e57b46888eff29457eda # Parent 8a9c6b71761fc071576e15176119492432432c79 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. diff -r 8a9c6b71761f -r d6105a8a6ca9 src/lib-imap/imap-bodystructure.c --- 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" */ diff -r 8a9c6b71761f -r d6105a8a6ca9 src/lib-mail/message-parser.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); } } diff -r 8a9c6b71761f -r d6105a8a6ca9 src/lib-mail/rfc822-address.c --- 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; } diff -r 8a9c6b71761f -r d6105a8a6ca9 src/lib-mail/rfc822-tokenize.c --- 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++] = '"'; diff -r 8a9c6b71761f -r d6105a8a6ca9 src/lib-mail/rfc822-tokenize.h --- 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