Skip to content

Add support for email links#66

Merged
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:support-mailto
Jul 31, 2021
Merged

Add support for email links#66
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:support-mailto

Conversation

@saswatamcode
Copy link
Copy Markdown
Collaborator

@saswatamcode saswatamcode commented Jul 29, 2021

This PR adds checks for mailto: email links like here. It validates email using regex as specified here and also checks if email has valid domain using net.LookupMX. Fixes #65.

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode saswatamcode requested a review from bwplotka July 29, 2021 05:27
@saswatamcode saswatamcode self-assigned this Jul 29, 2021
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits, only otherwise LGTM! Thanks

if checkEmail(strings.TrimSpace(email[1])) {
return
}
v.destFutures[k].resultFn = func() error { return errors.New("email not valid " + dest) }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
v.destFutures[k].resultFn = func() error { return errors.New("email not valid " + dest) }
v.destFutures[k].resultFn = func() error { return errors.Errors("provided mailto link is not a valid email, got %v", dest) }

Comment on lines +291 to +295
if strings.HasPrefix(dest, "mailto:") {
email := strings.Split(dest, "mailto:")
if checkEmail(strings.TrimSpace(email[1])) {
return
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if strings.HasPrefix(dest, "mailto:") {
email := strings.Split(dest, "mailto:")
if checkEmail(strings.TrimSpace(email[1])) {
return
}
if email := strings.TrimPrefix(dest, "mailto:"); email != dest {
if checkEmail(email) {
return
}

}

// checkEmail checks email structure and domain.
func checkEmail(email string) bool {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func checkEmail(email string) bool {
func isValidEmail(email string) bool {

Check is not very verbose what exactly we are checking for

Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
@saswatamcode saswatamcode requested a review from bwplotka July 30, 2021 15:24
Copy link
Copy Markdown
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! and tests!! Amazing 💪🏽

@bwplotka bwplotka merged commit 946757e into bwplotka:main Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for mailto links

2 participants