Skip to content

Commit

Permalink
Allow sender to immediately hangup after QUIT message (#344)
Browse files Browse the repository at this point in the history
* Allow sender to immediately hangup after QUIT message

* Use OTP 25 for docs
  • Loading branch information
mworrell authored Dec 16, 2024
1 parent da7893d commit bd7fae3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
otp: ["24"] # https://www.erlang.org/downloads
otp: ["25"] # https://www.erlang.org/downloads
rebar3: ["3.18.0"] # https://www.rebar3.org

steps:
Expand Down
5 changes: 4 additions & 1 deletion src/gen_smtp_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,10 @@ read_possible_multiline_reply(Socket) ->
Code = binstr:substr(Packet, 1, 3),
read_multiline_reply(Socket, Code, [Packet]);
<<" ">> ->
{ok, Packet}
{ok, Packet};
_ ->
quit(Socket),
throw({unexpected_response, Packet})
end;
Error ->
throw({network_failure, Error})
Expand Down
10 changes: 9 additions & 1 deletion src/gen_smtp_server_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ handle_request({<<"NOOP">>, _Any}, State) ->
send(State, "250 Ok\r\n"),
{ok, State};
handle_request({<<"QUIT">>, _Any}, State) ->
send(State, "221 Bye\r\n"),
try_send(State, "221 Bye\r\n"),
{stop, normal, State};
handle_request(
{<<"VRFY">>, Address},
Expand Down Expand Up @@ -1358,6 +1358,14 @@ check_bare_crlf(Binary, _Prev, Op, Offset) ->
end
end.

try_send(#state{transport = Transport, socket = Sock} = St, Data) ->
case Transport:send(Sock, Data) of
ok ->
ok;
{error, _Err} ->
ok
end.

This comment has been minimized.

Copy link
@Zabrane

Zabrane Jan 6, 2025

@mworrell Unless you'd like to log some error messages, how about this?

try_send(#state{transport = Transport, socket = Sock} = St, Data) ->
    Transport:send(Sock, Data),
    ok.

This comment has been minimized.

Copy link
@mworrell

mworrell Jan 7, 2025

Author Collaborator

Good one. I have made a pull request.
#345


send(#state{transport = Transport, socket = Sock} = St, Data) ->
case Transport:send(Sock, Data) of
ok ->
Expand Down

0 comments on commit bd7fae3

Please sign in to comment.