Skip to content

Commit

Permalink
Merge pull request #23 from drdo/master
Browse files Browse the repository at this point in the history
STARTTLS Callback
  • Loading branch information
lordnull committed Mar 19, 2012
2 parents d727914 + 7b69beb commit 1b76471
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit 1b76471

Please sign in to comment.