Exemple #1
0
static void test_noname(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("*****@*****.**", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_PTR_NULL(a->name);
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);

    a = NULL;
    parseaddr_list("<*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_PTR_NULL(a->name);
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);

    a = NULL;
    parseaddr_list(" <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_PTR_NULL(a->name);
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);

}
Exemple #2
0
static void test_single_append(void)
{
    struct address *a;
    struct address *origa;

    a = NULL;
    parseaddr_list("Fred Bloggs <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_STRING_EQUAL(a->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);
    origa = a;

    parseaddr_list("Sarah Jane Smith <*****@*****.**>", &a);
    CU_ASSERT_PTR_EQUAL_FATAL(a, origa);
    CU_ASSERT_STRING_EQUAL(a->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NOT_NULL_FATAL(a->next);
    CU_ASSERT_STRING_EQUAL(a->next->name, "Sarah Jane Smith");
    CU_ASSERT_STRING_EQUAL(a->next->mailbox, "sjsmith");
    CU_ASSERT_STRING_EQUAL(a->next->domain, "gmail.com");
    CU_ASSERT_PTR_NULL(a->next->next);

    parseaddr_free(a);
}
Exemple #3
0
static void test_group(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("Buddies: Fred Bloggs <*****@*****.**>, Sarah Jane Smith <*****@*****.**>;", &a);

    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_PTR_NULL(a->name);
    CU_ASSERT_STRING_EQUAL(a->mailbox, "Buddies");
    CU_ASSERT_PTR_NULL(a->domain);

    CU_ASSERT_PTR_NOT_NULL_FATAL(a->next);
    CU_ASSERT_STRING_EQUAL(a->next->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->next->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->next->domain, "fastmail.fm");

    CU_ASSERT_PTR_NOT_NULL_FATAL(a->next->next);
    CU_ASSERT_STRING_EQUAL(a->next->next->name, "Sarah Jane Smith");
    CU_ASSERT_STRING_EQUAL(a->next->next->mailbox, "sjsmith");
    CU_ASSERT_STRING_EQUAL(a->next->next->domain, "gmail.com");

    CU_ASSERT_PTR_NOT_NULL_FATAL(a->next->next->next);
    CU_ASSERT_PTR_NULL(a->next->next->next->name);
    CU_ASSERT_PTR_NULL(a->next->next->next->mailbox);
    CU_ASSERT_PTR_NULL(a->next->next->next->domain);

    CU_ASSERT_PTR_NULL(a->next->next->next->next);

    parseaddr_free(a);
}
Exemple #4
0
static void test_multi_group(void)
{
    struct address *a;
    struct address *cur;

    a = NULL;
    parseaddr_list("group: [email protected], [email protected];, group2: [email protected];", &a);

    cur = a;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "group");
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "g1");
    CU_ASSERT_STRING_EQUAL(cur->domain, "d1.org");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "g2");
    CU_ASSERT_STRING_EQUAL(cur->domain, "d2.org");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_PTR_NULL(cur->mailbox);
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "group2");
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "g3");
    CU_ASSERT_STRING_EQUAL(cur->domain, "d3.org");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_PTR_NULL(cur->mailbox);
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NULL(cur);

    parseaddr_free(a);
}
Exemple #5
0
/*
 * Convenience function to return a single canonicalised address.
 */
char *address_canonicalise(const char *str)
{
    struct address *addrlist = NULL;
    char *s = NULL;

    parseaddr_list(str, &addrlist);
    if (addrlist)
	s = address_get_all(addrlist, 1);
    parseaddr_free(addrlist);

    return s;
}
Exemple #6
0
static void test_long_domain(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("Fred Bloggs <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_STRING_EQUAL(a->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "a.really.quite.surprisingly.long.domain.name.com");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);
}
Exemple #7
0
static void test_dotted_mailbox(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("Fred Bloggs <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_STRING_EQUAL(a->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "Fred.Bloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);
}
Exemple #8
0
static void test_domain_literal(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("Fred Bloggs <fbloggs@[192.168.0.1]>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_STRING_EQUAL(a->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "[192.168.0.1]");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);
}
Exemple #9
0
static void test_quoted_name_comma(void)
{
    struct address *a;

    a = NULL;
    parseaddr_list("\"Bloggs, Fred\" <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_STRING_EQUAL(a->name, "Bloggs, Fred");
    CU_ASSERT_STRING_EQUAL(a->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(a->domain, "fastmail.fm");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);
}
Exemple #10
0
static void test_mailbox_comment(void)
{
    struct address *a;

    /* This example is from the RFC822 text */
    a = NULL;
    parseaddr_list("Wilt . (the Stilt) [email protected]", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);
    CU_ASSERT_PTR_NULL(a->name);
//     CU_ASSERT_STRING_EQUAL(a->mailbox, "Wilt.Chamberlain");
    CU_ASSERT_STRING_EQUAL(a->domain, "NBA.US");
    CU_ASSERT_PTR_NULL(a->next);

    parseaddr_free(a);
}
Exemple #11
0
/*
 * Test getting parts of a fully featured address
 */
static void test_getparts(void)
{
    struct address *a;
    char *s;

    a = NULL;
    parseaddr_list("Fred Bloggs <*****@*****.**>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);

    s = address_get_all(a, 0);
    CU_ASSERT_STRING_EQUAL(s, "*****@*****.**");
    free(s);

    s = address_get_all(a, 1);
    CU_ASSERT_STRING_EQUAL(s, "*****@*****.**");
    free(s);

    s = address_get_localpart(a);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs+foo");
    free(s);

    s = address_get_domain(a, 0);
    CU_ASSERT_STRING_EQUAL(s, "FastMAIL.fm");
    free(s);

    s = address_get_domain(a, 1);
    CU_ASSERT_STRING_EQUAL(s, "fastmail.fm");
    free(s);

    s = address_get_user(a);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs");
    free(s);

    s = address_get_detail(a);
    CU_ASSERT_STRING_EQUAL(s, "foo");
    free(s);

    parseaddr_free(a);
}
Exemple #12
0
/*
 * Test getting parts of an address with no domain part
 */
static void test_getparts_nodomain(void)
{
    struct address *a;
    char *s;

    a = NULL;
    parseaddr_list("Fred Bloggs <fbloggs>", &a);
    CU_ASSERT_PTR_NOT_NULL_FATAL(a);

    s = address_get_all(a, 0);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs@unspecified-domain");
    free(s);

    s = address_get_all(a, 1);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs@unspecified-domain");
    free(s);

    s = address_get_localpart(a);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs");
    free(s);

    s = address_get_domain(a, 0);
    CU_ASSERT_STRING_EQUAL(s, "unspecified-domain");
    free(s);

    s = address_get_domain(a, 1);
    CU_ASSERT_STRING_EQUAL(s, "unspecified-domain");
    free(s);

    s = address_get_user(a);
    CU_ASSERT_STRING_EQUAL(s, "fbloggs");
    free(s);

    s = address_get_detail(a);
    CU_ASSERT_PTR_NULL(s);

    parseaddr_free(a);
}
Exemple #13
0
static void test_multi_group_mixed(void)
{
    struct address *a;
    struct address *cur;

    a = NULL;
    parseaddr_list("Buddies: Fred Bloggs <*****@*****.**>, "
		   "Sarah Jane Smith <*****@*****.**>;, "
		   "[email protected], "
		   "group2: Fred Bloggs Junior <*****@*****.**>;",
		   &a);

    cur = a;

    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "Buddies");
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_STRING_EQUAL(cur->name, "Fred Bloggs");
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "fbloggs");
    CU_ASSERT_STRING_EQUAL(cur->domain, "fastmail.fm");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_STRING_EQUAL(cur->name, "Sarah Jane Smith");
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "sjsmith");
    CU_ASSERT_STRING_EQUAL(cur->domain, "gmail.com");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_PTR_NULL(cur->mailbox);
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "foobar");
    CU_ASSERT_STRING_EQUAL(cur->domain, "fastmail.fm");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "group2");
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_STRING_EQUAL(cur->name, "Fred Bloggs Junior");
    CU_ASSERT_STRING_EQUAL(cur->mailbox, "fbloggs_jr");
    CU_ASSERT_STRING_EQUAL(cur->domain, "fastmail.fm");

    cur = cur->next;
    CU_ASSERT_PTR_NOT_NULL_FATAL(cur);
    CU_ASSERT_PTR_NULL(cur->name);
    CU_ASSERT_PTR_NULL(cur->mailbox);
    CU_ASSERT_PTR_NULL(cur->domain);

    cur = cur->next;
    CU_ASSERT_PTR_NULL(cur);

    parseaddr_free(a);
}
Exemple #14
0
void address_itr_fini(struct address_itr *ai)
{
    parseaddr_free(ai->addrlist);
    memset(ai, 0, sizeof(*ai));
}