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

index 793a550c2361fbee5c198227aaaf83411b485736..d59044d1ecb018b019c17455d8ed50045639a025 100644 (file)
@@ -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 = &top;
-  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;
 }
 
 /**