Permalink
Browse files

Merge pull request #23 from drdo/master

STARTTLS Callback
  • Loading branch information...
2 parents d727914 + 7b69beb commit 1b76471625530c61cd55d2d5fd83d290f4b5fdb9 @lordnull lordnull committed Mar 19, 2012
Showing with 10 additions and 3 deletions.
  1. +2 −2 src/gen_smtp_server_session.erl
  2. +8 −1 src/smtp_server_example.erl
@@ -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"),
@@ -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"),
@@ -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).
@@ -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}.

0 comments on commit 1b76471

Please sign in to comment.