From: Pietro Cerutti Date: Mon, 13 May 2019 08:44:11 +0000 (+0000) Subject: Use AddressList in mutt_addrlist_dedupe X-Git-Tag: 2019-10-25~200^2~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4a341e7ca55447bf4ba1794c050543159560f0d;p=neomutt Use AddressList in mutt_addrlist_dedupe --- diff --git a/address/address.c b/address/address.c index 793a550c2..d59044d1e 100644 --- a/address/address.c +++ b/address/address.c @@ -1342,41 +1342,33 @@ int mutt_addrlist_to_local(struct Address *a) */ struct Address *mutt_addrlist_dedupe(struct Address *addr) { - struct Address *top = addr; - struct Address **last = ⊤ - struct Address *tmp = NULL; - bool dup; - - while (addr) + struct AddressList *al = mutt_addr_to_addresslist(addr); + struct AddressNode *an = NULL; + TAILQ_FOREACH(an, al, entries) { - for (tmp = top, dup = false; tmp && tmp != addr; tmp = tmp->next) + if (an->addr->mailbox) { - if (tmp->mailbox && addr->mailbox && - (mutt_str_strcasecmp(addr->mailbox, tmp->mailbox) == 0)) + struct AddressNode *an2 = TAILQ_NEXT(an, entries), *tmp; + if (an2) { - dup = true; - break; + TAILQ_FOREACH_FROM_SAFE(an2, al, entries, tmp) + { + if (an2->addr->mailbox && + (mutt_str_strcasecmp(an->addr->mailbox, an2->addr->mailbox) == 0)) + { + mutt_debug(LL_DEBUG2, "Removing %s\n", an2->addr->mailbox); + TAILQ_REMOVE(al, an2, entries); + free_address(&an2->addr); + FREE(&an2); + } + } } } - - if (dup) - { - mutt_debug(LL_DEBUG2, "Removing %s\n", addr->mailbox); - - *last = addr->next; - - addr->next = NULL; - mutt_addr_free(&addr); - - addr = *last; - } - else - { - last = &addr->next; - addr = addr->next; - } } - return top; + + addr = mutt_addresslist_to_addr(al); + FREE(&al); + return addr; } /**