Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

STARTTLS Callback #23

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +2 −2 src/gen_smtp_server_session.erl
  2. +8 −1 src/smtp_server_example.erl
View
4 src/gen_smtp_server_session.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"),
View
9 src/smtp_server_example.erl
@@ -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}.
Something went wrong with that request. Please try again.