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

Add support for email links #66

Merged
merged 2 commits into from
Jul 31, 2021
Merged

Conversation

saswatamcode
Copy link
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 self-assigned this Jul 29, 2021
Copy link
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
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
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
}

@@ -304,6 +315,26 @@ func (v *validator) visit(filepath string, dest string, lineNumbers string) {
}
}

// checkEmail checks email structure and domain.
func checkEmail(email string) bool {
Copy link
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>
Copy link
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