test-message-address.c revision 39025a2dabfcfaeee3790988b9ea00d19887a3d3
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainenstatic bool cmp_addr(const struct message_address *a1,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return null_strcmp(a1->name, a2->name) == 0 &&
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen static const char *input[] = {
42dbeeb3462895b03e7633dbc59e8e191199734bTimo Sirainen "user@domain",
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen "<user@domain>",
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen "foo bar <user@domain>",
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen "\"foo bar\" <user@domain>",
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen "<@route:user@domain>",
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen "<@route@route2:user@domain>",
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen "hello <@route ,@route2:user@domain>",
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen "user (hello)",
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen "hello <user>",
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen static struct message_address group_prefix = {
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen static struct message_address group_suffix = {
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen { NULL, NULL, NULL, "user", "domain", FALSE },
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen { NULL, NULL, NULL, "user", "domain", FALSE },
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen { NULL, "foo bar", NULL, "user", "domain", FALSE },
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen { NULL, "foo bar", NULL, "user", "domain", FALSE },
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen { NULL, NULL, "@route", "user", "domain", FALSE },
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen { NULL, NULL, "@route,@route2", "user", "domain", FALSE },
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen { NULL, "hello", "@route,@route2", "user", "domain", FALSE },
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen unsigned int i;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen addr = message_address_parse(pool_datastack_create(),
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen (const unsigned char *)input[i],
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen success = addr != NULL && addr->next == NULL &&
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen test_out(t_strdup_printf("message_address_parse(%d)", i),
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen if (i != 0) {
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen if ((i % 2) == 0)
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen addr = message_address_parse(pool_datastack_create(), str_data(group),
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen success = addr != NULL && cmp_addr(addr, &group_prefix);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen for (i = 0; i < N_ELEMENTS(input) && addr != NULL; i++) {
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen test_out("message_address_parse(group)", success);
d4fe93a9c242d745e0cf2e6cc58d5caf265de2a0Timo Sirainen static void (*test_functions[])(void) = {