-
Notifications
You must be signed in to change notification settings - Fork 55
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
authres: parser rework #53
Open
konimarti
wants to merge
1
commit into
emersion:master
Choose a base branch
from
konimarti:parser-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,22 @@ var parseTests = []msgauthTest{ | |
&SPFResult{Value: ResultPass, From: "example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
"dkim=pass reason=\"good signature\" [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultPass, Reason: "good signature", Identifier: "@mail-router.example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
"dkim=pass reason=\"good; signature\" [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultPass, Reason: "good; signature", Identifier: "@mail-router.example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5) [email protected];", | ||
|
@@ -32,6 +48,63 @@ var parseTests = []msgauthTest{ | |
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5) [email protected];" + | ||
" spf=pass smtp.mailfrom=example.net", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
&SPFResult{Value: ResultPass, From: "example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5 (comment inside comment)) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5; comment with semicolon) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5 \\( comment with escaped char) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "foo.example.net (foobar) 1 (baz);" + | ||
" dkim (Because I like it) / 1 (One yay) = (wait for it) fail" + | ||
" policy (A dot can go here) . (like that) expired" + | ||
" (this surprised me) = (as I wasn't expecting it) 1362471462", | ||
identifier: "foo.example.net", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultFail, Reason: "", Domain: "", Identifier: ""}, | ||
}, | ||
}, | ||
} | ||
|
||
var mustFailParseTests = []msgauthTest{ | ||
{ | ||
value: " ; ", | ||
identifier: "", | ||
results: nil, | ||
}, | ||
{ | ||
value: "example.com 2; none", | ||
identifier: "example.com", | ||
results: nil, | ||
}, | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
|
@@ -51,4 +124,10 @@ func TestParse(t *testing.T) { | |
} | ||
} | ||
} | ||
for _, test := range mustFailParseTests { | ||
_, _, err := Parse(test.value) | ||
if err == nil { | ||
t.Errorf("Expected an error when parsing header, but got none.") | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
CFWS
referenced by https://datatracker.ietf.org/doc/html/rfc8601#section-2.2 is defined in https://www.rfc-editor.org/rfc/rfc5322#section-3.2.2 (internet message / email):this code is not entirely future-proof, though right now, i welcome everything that helps me handle my emails..
even net/mail doesn't go the whole way:
how about including the parentheses in the output string (doing
comment += string(c)
for both(
and)
) and leaving parsing of comments up to other or future implementations?in that case, the backslashes should also be kept.
i can think of invalid comments that would be accepted by this parser. particularly, the restrictions for
ctext
.the implementation before this pr was more restrictive than the grammar. this replacement is more liberal, which could be understood as a changing interface.