Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space is an address delimiter #12

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (a Address) WithoutTag() string {
// It is also useful if the address wasn't created with ParseList() but directly
// (e.g. addr := Address{...}).
func (a *Address) Valid() bool {
fmt.Printf("===Valid %#v %t\n", a, reValidEmail.MatchString(a.Address))
if a.Address == "" || !reValidEmail.MatchString(a.Address) {
a.err = ErrNoEmail
return false
Expand Down
20 changes: 14 additions & 6 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,30 @@ func TestAddressEncoded(t *testing.T) {
func TestStringEncoded(t *testing.T) {
cases := []struct {
in, expected string
count int
}{
{`[email protected]`, `[email protected]`},
{`Martin Tournoij <[email protected]>`, `Martin Tournoij <[email protected]>`},
{`"Martin Tournoij" <[email protected]>`, `Martin Tournoij <[email protected]>`},
{`Martin Tour<noij> <[email protected]>`, `Martin Tour noij <[email protected]>`},
{`[email protected]`, `[email protected]`, 1},
{`Martin Tournoij <[email protected]>`, `Martin Tournoij <[email protected]>`, 1},
{`"Martin Tournoij" <[email protected]>`, `Martin Tournoij <[email protected]>`, 1},
{`Martin Tour<noij> <[email protected]>`, `Martin Tour noij <[email protected]>`, 1},
{
`Martin, Nichole <[email protected] <mailto:[email protected]>>r`,
"Nichole <[email protected]>",
1,
},
{
`a العَرَبِي b <[email protected]>`,
`=?utf-8?q?a_=D8=A7=D9=84=D8=B9=D9=8E=D8=B1=D9=8E=D8=A8=D9=90=D9=8A_b?= <[email protected]>`,
1,
},
}

for _, tc := range cases {
t.Run(tc.in, func(t *testing.T) {
out, outErr := ParseList(tc.in)
if outErr {
t.Error(out.Errors())
out = out.ValidAddresses()
if outErr && len(out) != tc.count {
t.Error(out.Errors(), " count:", len(out))
}

if out.StringEncoded() != tc.expected {
Expand Down
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func parse(str string) (list List, haveError bool) {
inAddress = false

// Next <address>
case !inQuote && (chr == "," || chr == ";"): // ';' introduced by outlook
case !inQuote && (chr == "," || chr == ";" || inAddress && unicode.IsSpace(code)): // ';' introduced by outlook
haveError = end(&addr) || haveError
if addr.Name != "" || addr.Address != "" || addr.err != nil {
list = append(list, addr)
Expand Down
Loading