From 880012f92c76af24ebf074427789a2bfa39b2b90 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 7 Jun 2017 12:35:35 +0300 Subject: [PATCH] lib-mail: message_address_write() - Don't write empty <> --- src/lib-mail/message-address.c | 27 ++++++++++++++++----------- src/lib-mail/test-message-address.c | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/lib-mail/message-address.c b/src/lib-mail/message-address.c index 3e9af74ab3..9c9ab71b04 100644 --- a/src/lib-mail/message-address.c +++ b/src/lib-mail/message-address.c @@ -467,19 +467,24 @@ void message_address_write(string_t *str, const struct message_address *addr) str_append(str, addr->name); else str_append_maybe_escape(str, addr->name, TRUE); - str_append_c(str, ' '); } - str_append_c(str, '<'); - if (addr->route != NULL) { - str_append(str, addr->route); - str_append_c(str, ':'); - } - str_append_maybe_escape(str, addr->mailbox, FALSE); - if (addr->domain[0] != '\0') { - str_append_c(str, '@'); - str_append(str, addr->domain); + if (addr->route != NULL || + addr->mailbox[0] != '\0' || + addr->domain[0] != '\0') { + if (addr->name != NULL && addr->name[0] != '\0') + str_append_c(str, ' '); + str_append_c(str, '<'); + if (addr->route != NULL) { + str_append(str, addr->route); + str_append_c(str, ':'); + } + str_append_maybe_escape(str, addr->mailbox, FALSE); + if (addr->domain[0] != '\0') { + str_append_c(str, '@'); + str_append(str, addr->domain); + } + str_append_c(str, '>'); } - str_append_c(str, '>'); } addr = addr->next; diff --git a/src/lib-mail/test-message-address.c b/src/lib-mail/test-message-address.c index fb0ed44da1..c8d3edaa78 100644 --- a/src/lib-mail/test-message-address.c +++ b/src/lib-mail/test-message-address.c @@ -38,7 +38,7 @@ static void test_message_address(void) { NULL, NULL, "@route,@route2", "user", "domain", FALSE } }, { "hello <@route ,@route2:user@domain>", "hello <@route,@route2:user@domain>", { NULL, "hello", "@route,@route2", "user", "domain", FALSE } }, - { "hello", "hello <>", + { "hello", "hello", { NULL, "hello", NULL, "", "", TRUE } }, { "user (hello)", "hello ", { NULL, "hello", NULL, "user", "", TRUE } },