]> granicus.if.org Git - neomutt/commitdiff
Cleanup Address API: mutt_addr_cmp_strict -> mutt_addresslist_equal
authorPietro Cerutti <gahr@gahr.ch>
Thu, 16 May 2019 11:30:10 +0000 (11:30 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 23 May 2019 10:57:10 +0000 (11:57 +0100)
address/address.c
address/address.h
email/envelope.c
test/Makefile.autosetup
test/address/mutt_addresslist_equal.c [moved from test/address/mutt_addr_cmp_strict.c with 69% similarity]
test/main.c

index 7c2597722a38e9e01501e08d2f69153f42934237..8a1a03445f67913d295ae7e6789fa53dc08baeb1 100644 (file)
@@ -827,13 +827,18 @@ bool mutt_addr_valid_msgid(const char *msgid)
 }
 
 /**
- * mutt_addr_cmp_strict - Strictly compare two Address lists
+ * mutt_addresslist_equal - Compare two Address lists for equality
  * @param a First Address
  * @param b Second Address
  * @retval true Address lists are strictly identical
  */
-bool mutt_addresslist_cmp_strict(const struct AddressList *ala, const struct AddressList *alb)
+bool mutt_addresslist_equal(const struct AddressList *ala, const struct AddressList *alb)
 {
+  if (!ala || !alb)
+  {
+    return !(ala || alb);
+  }
+
   struct AddressNode *ana = TAILQ_FIRST(ala);
   struct AddressNode *anb = TAILQ_FIRST(alb);
 
@@ -851,15 +856,6 @@ bool mutt_addresslist_cmp_strict(const struct AddressList *ala, const struct Add
 
   return !(ana || anb);
 }
-bool mutt_addr_cmp_strict(const struct Address *a, const struct Address *b)
-{
-  struct AddressList *ala = mutt_addr_to_addresslist((struct Address *) a);
-  struct AddressList *alb = mutt_addr_to_addresslist((struct Address *) b);
-  bool res = mutt_addresslist_cmp_strict(ala, alb);
-  FREE(&ala);
-  FREE(&alb);
-  return res;
-}
 
 /**
  * mutt_addresslist_has_recips - Count the number of Addresses with valid recipients
index ba1dd2ea703500c1e97324a18aca229bc8fad07d..e8d39482de93e78f350dc151c5789e817b94b343 100644 (file)
@@ -68,7 +68,9 @@ extern const char AddressSpecials[];
 
 void            mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials);
 bool            mutt_addr_cmp(const struct Address *a, const struct Address *b);
-bool            mutt_addr_cmp_strict(const struct Address *a, const struct Address *b);
+
+
+
 struct Address *mutt_addr_copy(const struct Address *addr);
 const char *    mutt_addr_for_display(const struct Address *a);
 void            mutt_addr_free(struct Address **p);
@@ -109,6 +111,6 @@ void                mutt_addresslist_qualify(struct AddressList *al, const char
 struct Address*     mutt_addresslist_first(const struct AddressList *al);
 bool                mutt_addresslist_search(const struct Address *needle, const struct AddressList *haystack);
 int                 mutt_addresslist_has_recips(const struct AddressList *al);
-bool                mutt_addresslist_cmp_strict(const struct AddressList *ala, const struct AddressList *alb);
+bool                mutt_addresslist_equal(const struct AddressList *ala, const struct AddressList *alb);
 
 #endif /* MUTT_EMAIL_ADDRESS_H */
index 99f36fd152b576f701ce4e05eb520ac3304461a7..7994a3f80e25fcaf375fc1794eb2361308a70e31 100644 (file)
@@ -192,12 +192,12 @@ bool mutt_env_cmp_strict(const struct Envelope *e1, const struct Envelope *e2)
     if ((mutt_str_strcmp(e1->message_id, e2->message_id) != 0) ||
         (mutt_str_strcmp(e1->subject, e2->subject) != 0) ||
         !mutt_list_compare(&e1->references, &e2->references) ||
-        !mutt_addresslist_cmp_strict(&e1->from, &e2->from) ||
-        !mutt_addresslist_cmp_strict(&e1->sender, &e2->sender) ||
-        !mutt_addresslist_cmp_strict(&e1->reply_to, &e2->reply_to) ||
-        !mutt_addresslist_cmp_strict(&e1->to, &e2->to) ||
-        !mutt_addresslist_cmp_strict(&e1->cc, &e2->cc) ||
-        !mutt_addresslist_cmp_strict(&e1->return_path, &e2->return_path))
+        !mutt_addresslist_equal(&e1->from, &e2->from) ||
+        !mutt_addresslist_equal(&e1->sender, &e2->sender) ||
+        !mutt_addresslist_equal(&e1->reply_to, &e2->reply_to) ||
+        !mutt_addresslist_equal(&e1->to, &e2->to) ||
+        !mutt_addresslist_equal(&e1->cc, &e2->cc) ||
+        !mutt_addresslist_equal(&e1->return_path, &e2->return_path))
     {
       return false;
     }
index 90d96837f97fc71bf663c3c3a0ce0f73cfb30d70..ebfe34989e6c17ff201617baf94ea6218b9ce5c7 100644 (file)
@@ -1,7 +1,6 @@
 ADDRESS_OBJS   = test/address/mutt_addr_append.o \
                  test/address/mutt_addr_cat.o \
                  test/address/mutt_addr_cmp.o \
-                 test/address/mutt_addr_cmp_strict.o \
                  test/address/mutt_addr_copy.o \
                  test/address/mutt_addr_copy_list.o \
                  test/address/mutt_addr_for_display.o \
@@ -9,6 +8,7 @@ ADDRESS_OBJS    = test/address/mutt_addr_append.o \
                  test/address/mutt_addr_has_recips.o \
                  test/address/mutt_addr_is_intl.o \
                  test/address/mutt_addr_is_local.o \
+                 test/address/mutt_addresslist_equal.o \
                  test/address/mutt_addrlist_dedupe.o \
                  test/address/mutt_addrlist_to_intl.o \
                  test/address/mutt_addrlist_to_local.o \
similarity index 69%
rename from test/address/mutt_addr_cmp_strict.c
rename to test/address/mutt_addresslist_equal.c
index 651939489bfd3a9b25c72a01274afa13d19c2041..d2d6d346916f02a125b520c0f5ab16a9d5bd2dac 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * @file
- * Test code for mutt_addr_cmp_strict()
+ * Test code for mutt_addresslist_equal()
  *
  * @authors
  * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
 #include "mutt/mutt.h"
 #include "address/lib.h"
 
-void test_mutt_addr_cmp_strict(void)
+void test_mutt_addresslist_equal(void)
 {
-  // bool mutt_addr_cmp_strict(const struct Address *a, const struct Address *b);
+  // bool mutt_addresslist_equal(const struct AddressList *a, const struct AddressList *b);
 
   {
-    struct Address addr = { 0 };
-    TEST_CHECK(!mutt_addr_cmp_strict(NULL, &addr));
+    struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
+    TEST_CHECK(!mutt_addresslist_equal(NULL, &al));
   }
 
   {
-    struct Address addr = { 0 };
-    TEST_CHECK(!mutt_addr_cmp_strict(&addr, NULL));
+    struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
+    TEST_CHECK(!mutt_addresslist_equal(&al, NULL));
   }
 }
index 13f53373e06b2301fca075eeffc086450cbc0901..a7a567c9c218c3a6b40b9f3694844b199be31e25 100644 (file)
@@ -29,7 +29,6 @@
   NEOMUTT_TEST_ITEM(test_mutt_addr_append)                                     \
   NEOMUTT_TEST_ITEM(test_mutt_addr_cat)                                        \
   NEOMUTT_TEST_ITEM(test_mutt_addr_cmp)                                        \
-  NEOMUTT_TEST_ITEM(test_mutt_addr_cmp_strict)                                 \
   NEOMUTT_TEST_ITEM(test_mutt_addr_copy)                                       \
   NEOMUTT_TEST_ITEM(test_mutt_addr_copy_list)                                  \
   NEOMUTT_TEST_ITEM(test_mutt_addr_for_display)                                \
@@ -50,6 +49,7 @@
   NEOMUTT_TEST_ITEM(test_mutt_addr_valid_msgid)                                \
   NEOMUTT_TEST_ITEM(test_mutt_addr_write)                                      \
   NEOMUTT_TEST_ITEM(test_mutt_addr_write_single)                               \
+  NEOMUTT_TEST_ITEM(test_mutt_addresslist_equal)                               \
   NEOMUTT_TEST_ITEM(test_mutt_addrlist_to_intl)                                \
   NEOMUTT_TEST_ITEM(test_mutt_addrlist_to_local)                               \
   NEOMUTT_TEST_ITEM(test_mutt_actx_add_attach)                                 \