From: Pietro Cerutti Date: Thu, 16 May 2019 11:30:10 +0000 (+0000) Subject: Cleanup Address API: mutt_addr_cmp_strict -> mutt_addresslist_equal X-Git-Tag: 2019-10-25~200^2~55 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05604772b465ddb717cb29260207b0edda1ce6b0;p=neomutt Cleanup Address API: mutt_addr_cmp_strict -> mutt_addresslist_equal --- diff --git a/address/address.c b/address/address.c index 7c2597722..8a1a03445 100644 --- a/address/address.c +++ b/address/address.c @@ -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 diff --git a/address/address.h b/address/address.h index ba1dd2ea7..e8d39482d 100644 --- a/address/address.h +++ b/address/address.h @@ -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 */ diff --git a/email/envelope.c b/email/envelope.c index 99f36fd15..7994a3f80 100644 --- a/email/envelope.c +++ b/email/envelope.c @@ -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; } diff --git a/test/Makefile.autosetup b/test/Makefile.autosetup index 90d96837f..ebfe34989 100644 --- a/test/Makefile.autosetup +++ b/test/Makefile.autosetup @@ -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 \ diff --git a/test/address/mutt_addr_cmp_strict.c b/test/address/mutt_addresslist_equal.c similarity index 69% rename from test/address/mutt_addr_cmp_strict.c rename to test/address/mutt_addresslist_equal.c index 651939489..d2d6d3469 100644 --- a/test/address/mutt_addr_cmp_strict.c +++ b/test/address/mutt_addresslist_equal.c @@ -1,6 +1,6 @@ /** * @file - * Test code for mutt_addr_cmp_strict() + * Test code for mutt_addresslist_equal() * * @authors * Copyright (C) 2019 Richard Russon @@ -26,17 +26,17 @@ #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)); } } diff --git a/test/main.c b/test/main.c index 13f53373e..a7a567c9c 100644 --- a/test/main.c +++ b/test/main.c @@ -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) \