Skip to content

Commit

Permalink
Allow sender to immediately hangup after QUIT message
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Nov 7, 2024
1 parent da7893d commit 4a80cbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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.

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

0 comments on commit 4a80cbd

Please sign in to comment.