]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_address_write() - Don't write empty <>
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 7 Jun 2017 09:35:35 +0000 (12:35 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 7 Jun 2017 15:33:55 +0000 (18:33 +0300)
src/lib-mail/message-address.c
src/lib-mail/test-message-address.c

index 7fc99d054a28baefbeecdc65654d7498def55241..a1e0977b363f1dee2de923f54086657c41c611df 100644 (file)
@@ -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;
index 05db36e3fa66556848fd33cece6dd1ecfba661b6..1604104f5ff32c6657eb3ee5893de48a70d34794 100644 (file)
@@ -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 <user>",
                  { NULL, "hello", NULL, "user", "", TRUE } },