Skip to content

Commit

Permalink
Support max message parts limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ten0s committed Jun 29, 2015
1 parent af92e80 commit 2e478a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
4 changes: 2 additions & 2 deletions rel/files/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{smtp_recipient_fields, [<<"to">>, <<"cc">>, <<"bcc">>]},

{auth_schemes, [subject]}, % [from_address, subject, to_address]
{invalid_recipient_policy, ignore_invalid} % ignore_invalid | reject_message
{invalid_recipient_policy, ignore_invalid}, % ignore_invalid | reject_message
{max_msg_parts, 10}

%% {throttling_hourly_limit, 5}
%% {max_msg_parts, 10}

%% https://tools.ietf.org/html/rfc3461
%% delayed when real delivery receipt is available
Expand Down
18 changes: 10 additions & 8 deletions src/email2sms_errors.hrl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
-ifndef(email2sms_errors_hrl).
-define(email2sms_errors_hrl, defined).

-define(E_AUTHENTICATION, "550 Invalid user account").
-define(E_INTERNAL, "554 Internal server error").
-define(E_NOT_IMPLEMENTED, "502 Not implemented").
-define(E_TIMEOUT, "554 Request timeout").
-define(E_NO_RECIPIENTS, "550 No valid recipients found").
-define(E_TOO_MANY_RECIPIENTS, "550 Too many recipients specified").
-define(E_SERVER_BUSY, "554 Server is busy").
-define(E_NOT_RECOGNIZED, "500 Not recognized").
-define(E_AUTHENTICATION, "550 Invalid user account").
-define(E_INTERNAL, "554 Internal server error").
-define(E_NOT_IMPLEMENTED, "502 Not implemented").
-define(E_TIMEOUT, "554 Request timeout").
-define(E_NO_RECIPIENTS, "550 No valid recipients found").
-define(E_TOO_MANY_RECIPIENTS, "550 Too many recipients specified").
-define(E_SERVER_BUSY, "554 Server is busy").
-define(E_NOT_RECOGNIZED, "500 Not recognized").
-define(E_TOO_MANY_PARTS, "550 Too many SMS parts").
-define(E_UNKNOWN_CONTENT_TYPE, "550 Unknown content type").

-endif.
33 changes: 27 additions & 6 deletions src/email2sms_smtp_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
recipients :: [email()],
auth_schema :: auth_schema(),
customer :: #auth_customer_v1{},
message :: binary()
message :: binary(),
encoding :: default | ucs2,
size :: pos_integer()
}).

%% ===================================================================
Expand Down Expand Up @@ -244,9 +246,28 @@ handle_data(decode_message, St) ->
case decode_message(Type, Subtype, Headers, Params, Content) of
{ok, Message} ->
Message2 = cleanup_message(Message),
handle_data(send, St#st{message = Message2});
{error, Error} ->
{error, Error, St}
{ok, Encoding} = alley_services_utils:guess_encoding(Message),
handle_data(check_parts_count, St#st{
message = Message2,
encoding = Encoding
});
{error, unknown_content_type} ->
{error, ?E_UNKNOWN_CONTENT_TYPE, St}
end;

handle_data(check_parts_count, St) ->
{ok, MaxMsgParts} =
application:get_env(?APP, max_msg_parts),

Message = St#st.message,
Encoding = St#st.encoding,
Size = alley_services_utils:chars_size(Encoding, Message),
MsgParts = alley_services_utils:calc_parts_number(Size, Encoding),
case MsgParts =< MaxMsgParts of
true ->
handle_data(send, St#st{size = Size});
false ->
{error, ?E_TOO_MANY_PARTS, St}
end;

handle_data(send, St) ->
Expand All @@ -259,9 +280,9 @@ handle_data(send, St) ->
Originator = Customer#auth_customer_v1.default_source,
Recipients = St#st.recipients,
Message = St#st.message,
Encoding = St#st.encoding,
Size = St#st.size,

{ok, Encoding} = alley_services_utils:guess_encoding(Message),
Size = alley_services_utils:chars_size(Encoding, Message),
Params = common_smpp_params(Customer) ++ [
{esm_class, 3},
{protocol_id, 0}
Expand Down

0 comments on commit 2e478a9

Please sign in to comment.