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

STARTTLS Callback #23

Merged
merged 1 commit into from Mar 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/gen_smtp_server_session.erl
Expand Up @@ -567,7 +567,7 @@ handle_request({<<"VRFY">>, Address}, #state{module= Module, socket = Socket, ca
socket:send(Socket, "501 Syntax: VRFY username/address\r\n"),
{ok, State}
end;
handle_request({<<"STARTTLS">>, <<>>}, #state{socket = Socket, tls=false, extensions = Extensions, options = Options} = State) ->
handle_request({<<"STARTTLS">>, <<>>}, #state{socket = Socket, module = Module, tls=false, extensions = Extensions, callbackstate = OldCallbackState, options = Options} = State) ->
case has_extension(Extensions, "STARTTLS") of
{true, _} ->
socket:send(Socket, "220 OK\r\n"),
Expand All @@ -592,7 +592,7 @@ handle_request({<<"STARTTLS">>, <<>>}, #state{socket = Socket, tls=false, extens
%io:format("SSL negotiation sucessful~n"),
{ok, State#state{socket = NewSocket, envelope=undefined,
authdata=undefined, waitingauth=false, readmessage=false,
tls=true}};
tls=true, callbackstate = Module:handle_STARTTLS(OldCallbackState)}};
{error, Reason} ->
io:format("SSL handshake failed : ~p~n", [Reason]),
socket:send(Socket, "454 TLS negotiation failed\r\n"),
Expand Down
9 changes: 8 additions & 1 deletion src/smtp_server_example.erl
Expand Up @@ -7,7 +7,7 @@

-export([init/4, handle_HELO/2, handle_EHLO/3, handle_MAIL/2, handle_MAIL_extension/2,
handle_RCPT/2, handle_RCPT_extension/2, handle_DATA/4, handle_RSET/1, handle_VRFY/2,
handle_other/3, handle_AUTH/4, code_change/3, terminate/2]).
handle_other/3, handle_AUTH/4, handle_STARTTLS/1, code_change/3, terminate/2]).

-define(RELAY, true).

Expand Down Expand Up @@ -195,6 +195,13 @@ handle_AUTH('cram-md5', <<"username">>, {Digest, Seed}, State) ->
handle_AUTH(_Type, _Username, _Password, _State) ->
error.

%% this callback is OPTIONAL
%% it only gets called if you add STARTTLS to your ESMTP extensions
-spec handle_STARTTLS(#state{}) -> #state{}.
handle_STARTTLS(State) ->
io:format("TLS Started~n"),
State.

-spec code_change(OldVsn :: any(), State :: #state{}, Extra :: any()) -> {ok, #state{}}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Expand Down