]> granicus.if.org Git - neomutt/commitdiff
Use AddressList in mutt_addr_append
authorPietro Cerutti <gahr@gahr.ch>
Mon, 13 May 2019 12:25:00 +0000 (12:25 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 23 May 2019 10:57:09 +0000 (11:57 +0100)
address/address.c

index 98c4cf247c02d17c04e3e0c64072a3e1b7cb99aa..3637a69d4f43978b4a0792a9701ee65de2b87985 100644 (file)
@@ -795,22 +795,33 @@ struct Address *mutt_addr_append(struct Address **a, struct Address *b, bool pru
   if (!a)
     return NULL;
 
-  struct Address *tmp = *a;
-
-  while (tmp && tmp->next)
-    tmp = tmp->next;
+  struct AddressList *ala = mutt_addr_to_addresslist(*a);
   if (!b)
-    return tmp;
-  if (tmp)
-    tmp->next = mutt_addr_copy_list(b, prune);
-  else
   {
-    *a = mutt_addr_copy_list(b, prune);
-    tmp = *a;
+    if (TAILQ_EMPTY(ala))
+      return NULL;
+    else
+      return TAILQ_LAST(ala, AddressList)->addr;
+  }
+
+  struct AddressList *alb = mutt_addr_to_addresslist(b);
+  struct AddressList *alb_pruned = mutt_addresslist_copy(alb, prune);
+  struct AddressNode *an = NULL;
+  TAILQ_FOREACH(an, alb_pruned, entries)
+  {
+    mutt_addresslist_append(ala, an->addr);
+  }
+  FREE(&alb);
+  FREE(&alb_pruned);
+
+  struct Address *last = NULL;
+  if (!TAILQ_EMPTY(ala))
+  {
+    last = TAILQ_LAST(ala, AddressList)->addr;
   }
-  while (tmp && tmp->next)
-    tmp = tmp->next;
-  return tmp;
+  *a = mutt_addresslist_to_addr(ala);
+
+  return last;
 }
 
 /**