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 SMTPUTF8 extension, RFC-6531 #280

Merged
merged 1 commit into from
Sep 21, 2021

Conversation

seriyps
Copy link
Collaborator

@seriyps seriyps commented Sep 16, 2021

https://datatracker.ietf.org/doc/html/rfc6531
It's relatively simple extension that allows SMTP clients send MAIL FROM: <utf-8 email> and RCPT TO: <utf-8 email>.
I never seen UTF-8 email addresses in a wild so far, but I saw many SMTP servers implementing this extension (including gmail and outlook).

@@ -546,7 +554,7 @@ handle_request({<<"MAIL">>, Args},
?log(debug, "error: ~s~n", [Message]),
send(State, Message),
{ok, State};
NewState ->
#state{envelope = Envelope} = NewState ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's actually a small bugfix, because we used to loose the value of #envelope.expectedsize we set on lines 522 and 528

@@ -756,62 +764,73 @@ handle_error(Kind, Details, #state{module=Module, callbackstate = OldCallbackSta
State
end.

-spec parse_encoded_address(Address :: binary()) -> {binary(), binary()} | 'error'.
parse_encoded_address(<<>>) ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

most of the diff in parse_encoded_address is just me replacing the tuple with the record (except one clause I added and changing list_to_binary to unicode:characters_to_binary)

parse_encoded_address(Tail, [H | Acc], {false, AB}); % dash, dot, underscore
parse_encoded_address(<<H/utf8, Tail/binary>>, Acc, #pa{utf8 = true} = F) when H > 127 ->
%% https://datatracker.ietf.org/doc/html/rfc6531#section-3.3
parse_encoded_address(Tail, [H | Acc], F); % UTF-8 above 7bit (when allowed)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the only new clause I added

?assertEqual({<<"God2@heaven.af.mil">>, <<>>}, parse_encoded_address(<<"<God2@heaven.af.mil>">>, false)),
?assertEqual({<<"God+extension@heaven.af.mil">>, <<>>}, parse_encoded_address(<<"<God+extension@heaven.af.mil>">>, false)),
?assertEqual({<<"God~*$@heaven.af.mil">>, <<>>}, parse_encoded_address(<<"<God~*$@heaven.af.mil>">>, false)),
?assertEqual({<<"God~!#$%^&*()_+123@heaven.af.mil">>, <<>>}, parse_encoded_address(<<"<\"God~!#$%^&*()_+123\"@heaven.af.mil>">>, false))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the only extra test in "Valid addresses should parse" section, and it is not related to the PR's topic. I just noticed that quoted address is not covered by tests

@seriyps seriyps requested review from arjan and mworrell September 16, 2021 01:27
@mworrell
Copy link
Collaborator

I agree, supporting this is good, even if we didn't see it in the wild yet.

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