]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_address_write: Fix generating empty group list
authorPali Rohár <pali.rohar@gmail.com>
Sun, 5 Jun 2016 13:48:14 +0000 (15:48 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 6 Jun 2016 10:49:13 +0000 (13:49 +0300)
Empty group list ends with ": " not with ", ".

Test case:

  { { name = NULL, mailbox = "group", domain = NULL }, { name = NULL, mailbox = NULL, domain = NULL } }

converts to:

  group:;

src/lib-mail/message-address.c

index 36cb4832667c013479c656d548ca4c3e134e2a03..efa91fd2895f51ed73cff137ba54d592e78b2224 100644 (file)
@@ -340,6 +340,7 @@ message_address_parse(pool_t pool, const unsigned char *data, size_t size,
 
 void message_address_write(string_t *str, const struct message_address *addr)
 {
+       const char *tmp;
        bool first = TRUE, in_group = FALSE;
 
        /* a) mailbox@domain
@@ -365,7 +366,12 @@ void message_address_write(string_t *str, const struct message_address *addr)
                                i_assert(addr->mailbox == NULL);
 
                                /* cut out the ", " */
-                               str_truncate(str, str_len(str)-2);
+                               tmp = str_c(str)+str_len(str)-2;
+                               i_assert((tmp[0] == ',' || tmp[0] == ':') && tmp[1] == ' ');
+                               if (tmp[0] == ',' && tmp[1] == ' ')
+                                       str_truncate(str, str_len(str)-2);
+                               else if (tmp[0] == ':' && tmp[1] == ' ')
+                                       str_truncate(str, str_len(str)-1);
                                str_append_c(str, ';');
                        }