Skip to content

Commit

Permalink
Merge pull request #36 from agau4779/master
Browse files Browse the repository at this point in the history
Add check in split utility method to prevent panic
  • Loading branch information
badoux authored May 31, 2021
2 parents 06ca3b2 + 46c1079 commit a155f10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions checkmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func DialTimeout(addr string, timeout time.Duration) (*smtp.Client, error) {

func split(email string) (account, host string) {
i := strings.LastIndexByte(email, '@')
// If no @ present, not a valid email.
if i < 0 {
return
}
account = email[:i]
host = email[i+1:]
return
Expand Down
6 changes: 4 additions & 2 deletions checkmail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ var (
{mail: " [email protected]", format: false, account: false},
{mail: "test@wrong domain.com", format: false, account: false},
{mail: "é&ààà@gmail.com", format: false, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "", format: false, account: false},
{mail: "not-a-valid-email", format: false, account: false},
}
)

Expand Down

0 comments on commit a155f10

Please sign in to comment.