Skip to content

Commit

Permalink
lib-mail: message-address: Dropped message_detail_address_parse(), si…
Browse files Browse the repository at this point in the history
…nce it is no longer used.
  • Loading branch information
stephanbosch authored and sirainen committed Nov 26, 2017
1 parent 52f6112 commit ca3aed4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 82 deletions.
30 changes: 0 additions & 30 deletions src/lib-mail/message-address.c
Expand Up @@ -563,33 +563,3 @@ bool message_header_is_address(const char *hdr_name)
}
return FALSE;
}

void message_detail_address_parse(const char *delimiters, const char *address,
const char **username_r, char *delim_r,
const char **detail_r)
{
const char *p, *domain;
size_t idx;

*username_r = address;
*detail_r = "";
*delim_r = '\0';

domain = strchr(address, '@');
/* first character that matches the recipient_delimiter */
idx = strcspn(address, delimiters);
p = address[idx] != '\0' ? address + idx : NULL;

if (p != NULL && (domain == NULL || p < domain)) {
*delim_r = *p;
/* user+detail@domain */
*username_r = t_strdup_until(*username_r, p);
if (domain == NULL)
*detail_r = p+1;
else {
*detail_r = t_strdup_until(p+1, domain);
*username_r = t_strconcat(*username_r, domain, NULL);
}
}
}

6 changes: 0 additions & 6 deletions src/lib-mail/message-address.h
Expand Up @@ -44,10 +44,4 @@ const char *message_address_first_to_string(const struct message_address *addr);
/* Returns TRUE if header is known to be an address */
bool message_header_is_address(const char *hdr_name);

/* Parse address+detail@domain into address@domain and detail
using given delimiters. Returns used delimiter. */
void message_detail_address_parse(const char *delimiters, const char *address,
const char **username_r, char *delim_r,
const char **detail_r);

#endif
46 changes: 0 additions & 46 deletions src/lib-mail/test-message-address.c
Expand Up @@ -295,56 +295,10 @@ static void test_message_address(void)
test_end();
}

static void test_message_delim(void) {
test_begin("message address detail parsing");

struct {
const char *delimiters;
const char *address;
const char *username;
const char *detail;
char delim;
} tests[] = {
{ "", "", "", "", '\0' },
{ "", "test", "test", "", '\0' },
{ "", "test+address", "test+address", "", '\0' },
{ "", "test:address", "test:address", "", '\0' },
{ "", "test-address:another+delim", "test-address:another+delim", "", '\0' },
{ "", "test@domain", "test@domain", "", '\0' },
{ "", "test+address@domain", "test+address@domain", "", '\0' },
{ "", "test:address@domain", "test:address@domain", "", '\0' },
{ "", "test-address:another+delim@domain", "test-address:another+delim@domain", "", '\0' },

{ "+-:", "", "", "", '\0' },
{ "+-:", "test", "test", "", '\0' },
{ "+-:", "test+address", "test", "address", '+' },
{ "+-:", "test:address", "test", "address", ':' },
{ "+-:", "test-address:another+delim", "test", "address:another+delim", '-' },
{ "+-:", "test@domain", "test@domain", "", '\0' },
{ "+-:", "test+address@domain", "test@domain", "address", '+' },
{ "+-:", "test:address@domain", "test@domain", "address", ':' },
{ "+-:", "test-address:another+delim@domain", "test@domain", "address:another+delim", '-' }
};

for(size_t i = 0; i < N_ELEMENTS(tests); i++) {
const char *username, *detail;
char delim;

message_detail_address_parse(tests[i].delimiters, tests[i].address,
&username, &delim, &detail);
test_assert_idx(strcmp(username, tests[i].username) == 0, i);
test_assert_idx(strcmp(detail, tests[i].detail) == 0, i);
test_assert_idx(delim == tests[i].delim, i);
}

test_end();
}

int main(void)
{
static void (*const test_functions[])(void) = {
test_message_address,
test_message_delim,
NULL
};
return test_run(test_functions);
Expand Down

0 comments on commit ca3aed4

Please sign in to comment.