From d90b4f00d83b0eb1693fa64cde03e5aab79a43a6 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Mon, 13 May 2019 12:21:09 +0000 Subject: [PATCH] Use AddressList in mutt_addr_copy_list --- address/address.c | 28 +++++++++++++++++----------- address/address.h | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/address/address.c b/address/address.c index 6b789e862..4b9f9df83 100644 --- a/address/address.c +++ b/address/address.c @@ -758,26 +758,32 @@ struct Address *mutt_addr_copy(const struct Address *addr) */ struct Address *mutt_addr_copy_list(struct Address *addr, bool prune) { - struct Address *top = NULL, *last = NULL; + struct AddressList *al = mutt_addr_to_addresslist(addr); + struct AddressList *al_out = mutt_addresslist_copy(al, prune); + struct Address *out = mutt_addresslist_to_addr(al_out); + FREE(&al); + FREE(&al_out); + return out; +} - for (; addr; addr = addr->next) +struct AddressList *mutt_addresslist_copy(const struct AddressList *al, bool prune) +{ + struct AddressList *al_out = mutt_addresslist_new(); + struct AddressNode *an = NULL; + TAILQ_FOREACH(an, al, entries) { - if (prune && addr->group && (!addr->next || !addr->next->mailbox)) + struct Address *addr = an->addr; + struct AddressNode *next = TAILQ_NEXT(an, entries); + if (prune && addr->group && (!next || !next->addr->mailbox)) { /* ignore this element of the list */ } - else if (last) - { - last->next = mutt_addr_copy(addr); - last = last->next; - } else { - last = mutt_addr_copy(addr); - top = last; + mutt_addresslist_append(al_out, mutt_addr_copy(addr)); } } - return top; + return al_out; } /** diff --git a/address/address.h b/address/address.h index f036c1adc..d133a731e 100644 --- a/address/address.h +++ b/address/address.h @@ -98,6 +98,7 @@ struct AddressList *mutt_addr_to_addresslist(struct Address *a); struct AddressList *mutt_addresslist_new(void); struct Address *mutt_addresslist_to_addr(struct AddressList *alist); void mutt_addresslist_append(struct AddressList *al, struct Address *a); +struct AddressList *mutt_addresslist_copy(const struct AddressList *al, bool prune); void mutt_addresslist_free(struct AddressList **alist); #endif /* MUTT_EMAIL_ADDRESS_H */ -- 2.40.0