From 47820920c2100e63f253ae8085820875beff34de Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Mon, 13 May 2019 12:25:00 +0000 Subject: [PATCH] Use AddressList in mutt_addr_append --- address/address.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/address/address.c b/address/address.c index 98c4cf247..3637a69d4 100644 --- a/address/address.c +++ b/address/address.c @@ -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; } /** -- 2.40.0