return mutt_mem_calloc(1, sizeof(struct Address));
}
+/**
+ * mutt_addr_create - Create and populate a new Address
+ * @param[in] personal The personal name for the Address (can be NULL)
+ * @param[in] mailbox The mailbox for the Address (can be NULL)
+ * @retval ptr Newly allocated Address
+ * @note The personal and mailbox values, if not NULL, are going to be copied
+ * into the newly allocated Address.
+ */
+struct Address *mutt_addr_create(const char *personal, const char *mailbox)
+{
+ struct Address *a = mutt_addr_new();
+ a->personal = mutt_str_strdup(personal);
+ a->mailbox = mutt_str_strdup(mailbox);
+ return a;
+}
+
+
/**
* mutt_addrlist_remove - Remove an Address from a list
* @param[in, out] al AddressList
/* Functions that work on a single struct Address */
bool mutt_addr_cmp(const struct Address *a, const struct Address *b);
struct Address *mutt_addr_copy(const struct Address *addr);
+struct Address *mutt_addr_create(const char *personal, const char *mailbox);
const char * mutt_addr_for_display(const struct Address *a);
void mutt_addr_free(struct Address **a);
struct Address *mutt_addr_new(void);
TEST_CHECK(a1.group == a2->group);
TEST_CHECK(a1.is_intl == a2->is_intl);
TEST_CHECK(a1.intl_checked == a2->intl_checked);
- FREE(&a2);
+ mutt_addr_free(&a2);
}
{
TEST_CHECK(a1.group == a2->group);
TEST_CHECK(a1.is_intl == a2->is_intl);
TEST_CHECK(a1.intl_checked == a2->intl_checked);
- FREE(&a2);
+ mutt_addr_free(&a2);
}
}
}
{
- struct Address a1 = { .mailbox = "test@example.com" };
- struct Address a2 = { .mailbox = "john@doe.org" };
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
- mutt_addrlist_append(&al, &a1);
- mutt_addrlist_append(&al, &a2);
+ mutt_addrlist_append(&al, mutt_addr_create(NULL, "test@example.com"));
+ mutt_addrlist_append(&al, mutt_addr_create(NULL, "john@doe.org"));
struct Address *a = TAILQ_FIRST(&al);
TEST_CHECK_STR_EQ("test@example.com", a->mailbox);
a = TAILQ_NEXT(a, entries);
TEST_CHECK_STR_EQ("john@doe.org", a->mailbox);
+ mutt_addrlist_clear(&al);
}
}
{
struct AddressList src = TAILQ_HEAD_INITIALIZER(src);
struct AddressList dst = TAILQ_HEAD_INITIALIZER(dst);
- struct Address a1 = { .mailbox = "test@example.com" };
- struct Address a2 = { .mailbox = "john@doe.org" };
- struct Address a3 = { .mailbox = "the-who@stage.co.uk" };
- mutt_addrlist_append(&src, &a1);
- mutt_addrlist_append(&src, &a2);
- mutt_addrlist_append(&src, &a3);
+ mutt_addrlist_append(&src, mutt_addr_create(NULL, "test@example.com"));
+ mutt_addrlist_append(&src, mutt_addr_create(NULL, "john@doe.org"));
+ mutt_addrlist_append(&src, mutt_addr_create(NULL, "the-who@stage.co.uk"));
mutt_addrlist_copy(&dst, &src, false);
TEST_CHECK(!TAILQ_EMPTY(&src));
TEST_CHECK(!TAILQ_EMPTY(&dst));
struct Address *adst = TAILQ_FIRST(&dst);
- TEST_CHECK_STR_EQ(a1.mailbox, adst->mailbox);
+ TEST_CHECK_STR_EQ("test@example.com", adst->mailbox);
adst = TAILQ_NEXT(adst, entries);
- TEST_CHECK_STR_EQ(a2.mailbox, adst->mailbox);
+ TEST_CHECK_STR_EQ("john@doe.org", adst->mailbox);
adst = TAILQ_NEXT(adst, entries);
- TEST_CHECK_STR_EQ(a3.mailbox, adst->mailbox);
+ TEST_CHECK_STR_EQ("the-who@stage.co.uk", adst->mailbox);
+ mutt_addrlist_clear(&src);
mutt_addrlist_clear(&dst);
}
}
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
mutt_addrlist_parse(&al, "test@example.com, john@doe.org");
TEST_CHECK(mutt_addrlist_count_recips(&al) == 2);
+ mutt_addrlist_clear(&al);
}
{
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
mutt_addrlist_parse(&al, "test@example.com, john@doe.org");
mutt_addrlist_append(&al, mutt_addr_new());
- struct Address *a = mutt_addr_new();
- a->mailbox = mutt_str_strdup("foo@bar.baz");
- mutt_addrlist_append(&al, a);
+ mutt_addrlist_append(&al, mutt_addr_create(NULL, "foo@bar.baz"));
TEST_CHECK(mutt_addrlist_count_recips(&al) == 3);
+ mutt_addrlist_clear(&al);
}
{
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
mutt_addrlist_parse(&al, "test@example.com, john@doe.org");
mutt_addrlist_append(&al, mutt_addr_new());
- struct Address *a = mutt_addr_new();
- a->mailbox = mutt_str_strdup("foo@bar.baz");
+ struct Address *a = mutt_addr_create(NULL, "foo@bar.baz");
a->group = 1;
mutt_addrlist_append(&al, a);
TEST_CHECK(mutt_addrlist_count_recips(&al) == 2);
+ mutt_addrlist_clear(&al);
}
}
}
{
- struct Address a1 = { .mailbox = "test@example.com" };
- struct Address a2 = { .mailbox = "john@doe.org" };
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
- mutt_addrlist_prepend(&al, &a1);
- mutt_addrlist_prepend(&al, &a2);
+ mutt_addrlist_prepend(&al, mutt_addr_create(NULL, "test@example.com"));
+ mutt_addrlist_prepend(&al, mutt_addr_create(NULL, "john@doe.org"));
struct Address *a = TAILQ_FIRST(&al);
TEST_CHECK_STR_EQ("john@doe.org", a->mailbox);
a = TAILQ_NEXT(a, entries);
TEST_CHECK_STR_EQ("test@example.com", a->mailbox);
+ mutt_addrlist_clear(&al);
}
}