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 a LenientSMTP option. #12

Merged
merged 6 commits into from
May 3, 2018
Merged

Add a LenientSMTP option. #12

merged 6 commits into from
May 3, 2018

Conversation

lyda
Copy link
Contributor

@lyda lyda commented May 2, 2018

There's probably more to do here. Allow out of order MAIL/RCPTs and so
forth.

Fixes #11

There's probably more to do here. Allow out of order MAIL/RCPTs and so
forth.
conn.go Outdated
// Match FROM, while accepting '>' as quoted pair and in double quoted strings
// (?i) makes the regex case insensitive, (?:) is non-grouping sub-match
re := regexp.MustCompile("(?i)^FROM:\\s*<((?:\\\\>|[^>])+|\"[^\"]+\"@[^>]+)>( [\\w= ]+)?$")
re := regexp.MustCompile(mailFromRE)
Copy link
Owner

Choose a reason for hiding this comment

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

Hmmm, this regexp is a leftover from the past I really want to get rid of. Possible to parse this with strings instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly don't know a huge amount about the ESMTP extensions to MAIL FROM but I can go look.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I'll just create a follow-up issue for this one if you don't feel like fixing it right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. That removes the need for regexp everywhere.

server.go Outdated
@@ -25,6 +25,7 @@ type Server struct {
MaxIdleSeconds int
MaxMessageBytes int
AllowInsecureAuth bool
LenientSMTP bool
Copy link
Owner

Choose a reason for hiding this comment

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

The default behaviour should probably to be lenient (since RCPT TO is lenient right now). So maybe we can change this to be a "Strict" flag instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to check existing behaviour, but yes, my first pass had StrictSMTP - I had to raid the antonyms page to get the most neutral opposite I could find. But happy to switch to StrictSMTP, sure.

@emersion
Copy link
Owner

emersion commented May 2, 2018

Can you add a test for the new behaviour?

This makes the default behavious lenient. And it now removes the need
for regexp.
@codecov
Copy link

codecov bot commented May 2, 2018

Codecov Report

Merging #12 into master will increase coverage by 4.47%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   61.09%   65.56%   +4.47%     
==========================================
  Files           5        5              
  Lines         568      575       +7     
==========================================
+ Hits          347      377      +30     
+ Misses        166      145      -21     
+ Partials       55       53       -2
Impacted Files Coverage Δ
server.go 56.96% <ø> (ø) ⬆️
conn.go 65.36% <100%> (+7.2%) ⬆️
parse.go 52.94% <80%> (+22.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7437cd...2e44694. Read the comment docs.

Copy link
Contributor Author

@lyda lyda left a comment

Choose a reason for hiding this comment

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

Added tests in the next commit.

conn.go Outdated
// Match FROM, while accepting '>' as quoted pair and in double quoted strings
// (?i) makes the regex case insensitive, (?:) is non-grouping sub-match
re := regexp.MustCompile("(?i)^FROM:\\s*<((?:\\\\>|[^>])+|\"[^\"]+\"@[^>]+)>( [\\w= ]+)?$")
re := regexp.MustCompile(mailFromRE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. That removes the need for regexp everywhere.

@lyda
Copy link
Contributor Author

lyda commented May 2, 2018

OK, I think that's it. Increased coverage till I found a bug! Good?

conn.go Outdated
re := regexp.MustCompile("(?i)^FROM:\\s*<((?:\\\\>|[^>])+|\"[^\"]+\"@[^>]+)>( [\\w= ]+)?$")
m := re.FindStringSubmatch(arg)
if m == nil {
if (len(arg) < 6) || (strings.ToUpper(arg[0:5]) != "FROM:") {
Copy link
Owner

Choose a reason for hiding this comment

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

No need for these parentheses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

conn.go Outdated
c.WriteResponse(501, "Was expecting MAIL arg syntax of FROM:<address>")
return
}
fromArgs := strings.Split(strings.Trim(arg[5:], " "), " ")
Copy link
Owner

Choose a reason for hiding this comment

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

What's the purpose of this strings.Split?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, my bad, I see.

server.go Outdated
@@ -25,6 +25,7 @@ type Server struct {
MaxIdleSeconds int
MaxMessageBytes int
AllowInsecureAuth bool
StrictSMTP bool
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is the smtp package, is it possible to rename this to simply Strict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Looks pretty good!

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@emersion emersion merged commit 592cbda into emersion:master May 3, 2018
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.

2 participants