UPDATED: improving email address splitting for common comma case

This commit is contained in:
TheAvgJojo 2022-08-05 15:13:21 -04:00
parent 9524963da6
commit 1e37e91eda
3 changed files with 17 additions and 1 deletions

View file

@ -58,7 +58,7 @@ function extract_first_email_addr(str: string): string
function split_mime_email_addresses(line: string): set[string] function split_mime_email_addresses(line: string): set[string]
{ {
local output = string_set(); local output = string_set();
local addrs = find_all(line, /(\"[^"]*\")?[^,]+/); local addrs = find_all(line, /(\"[^"]*\")?[^,]+@[^,]+/);
for ( part in addrs ) for ( part in addrs )
{ {
add output[strip(part)]; add output[strip(part)];

View file

@ -13,6 +13,11 @@ three@example.com,
two@example.com, two@example.com,
one@example.com one@example.com
} }
{
three@example.com,
two@example.com,
one@example.com
}
one@example.com one@example.com
[one@example.com, two@example.com, three@example.com, one@example.com] [one@example.com, two@example.com, three@example.com, one@example.com]
{ {
@ -26,9 +31,17 @@ john.smith@email.com
john.smith@email.com, john.smith@email.com,
jane.doe@email.com jane.doe@email.com
} }
{
"Smith, John" <john.smith@email.com>,
"Doe, Jane" <jane.doe@email.com>
}
john.smith@email.com john.smith@email.com
[john.smith@email.com, jane.doe@email.com] [john.smith@email.com, jane.doe@email.com]
{ {
john.smith@email.com, john.smith@email.com,
jane.doe@email.com jane.doe@email.com
} }
{
"Smith, John" <john.smith@email.com>,
"Doe, Jane" <jane.doe@email.com>
}

View file

@ -11,6 +11,7 @@ s = "one@example.com,two@example.com,three@example.com,one@example.com";
print extract_first_email_addr(s); print extract_first_email_addr(s);
print extract_email_addrs_vec(s); print extract_email_addrs_vec(s);
print extract_email_addrs_set(s); print extract_email_addrs_set(s);
print split_mime_email_addresses(s);
s = "ieje one@example.com, eifj two@example.com, asdf three@example.com, one@example.com"; s = "ieje one@example.com, eifj two@example.com, asdf three@example.com, one@example.com";
print extract_first_email_addr(s); print extract_first_email_addr(s);
print extract_email_addrs_vec(s); print extract_email_addrs_vec(s);
@ -19,7 +20,9 @@ s = "\"Smith, John\" <john.smith@email.com>, \"Doe, Jane\" <jane.doe@email.com>"
print extract_first_email_addr(s); print extract_first_email_addr(s);
print extract_email_addrs_vec(s); print extract_email_addrs_vec(s);
print extract_email_addrs_set(s); print extract_email_addrs_set(s);
print split_mime_email_addresses(s);
s = "\"Smith, John\" <john.smith@email.com>,\"Doe, Jane\" <jane.doe@email.com>"; s = "\"Smith, John\" <john.smith@email.com>,\"Doe, Jane\" <jane.doe@email.com>";
print extract_first_email_addr(s); print extract_first_email_addr(s);
print extract_email_addrs_vec(s); print extract_email_addrs_vec(s);
print extract_email_addrs_set(s); print extract_email_addrs_set(s);
print split_mime_email_addresses(s);