Skip to content
Browse files

Split send_page/3 function from action to z_email, so it can be easil…

…y reused.
  • Loading branch information...
1 parent 305fcfd commit 8babe0bd0af54a1d0b588164447bea342ed00c36 @mworrell mworrell committed
Showing with 32 additions and 16 deletions.
  1. +1 −15 modules/mod_mailinglist/actions/action_mailinglist_dialog_mail_page.erl
  2. +31 −1 src/smtp/z_email.erl
View
16 modules/mod_mailinglist/actions/action_mailinglist_dialog_mail_page.erl
@@ -47,20 +47,6 @@ event(#submit{message={mail_page, Args}}, Context) ->
Id = proplists:get_value(id, Args),
OnSuccess = proplists:get_all_values(on_success, Args),
Email = z_context:get_q_validated("email", Context),
- Vars = [
- {id, Id},
- {recipient, Email}
- ],
- case m_rsc:is_a(Id, document, Context) of
- false -> z_email:send_render(Email, {cat, "mailing_page.tpl"}, Vars, Context);
- true ->
- E = #email{
- to=Email,
- html_tpl={cat, "mailing_page.tpl"},
- vars=Vars,
- attachments=[Id]
- },
- z_email:send(E, Context)
- end,
+ z_email:send_page(Email, Id, Context),
Context1 = z_render:growl(?__("Sending the e-mail...", Context), Context),
z_render:wire(OnSuccess, Context1).
View
32 src/smtp/z_email.erl
@@ -26,6 +26,8 @@
get_admin_email/1,
send_admin/3,
+ send_page/3,
+
send/2,
send/3,
@@ -66,7 +68,7 @@ get_admin_email(Context) ->
send_admin(Subject, Message, Context) ->
case get_admin_email(Context) of
undefined ->
- error;
+ {error, no_admin_email};
Email ->
Subject1 = [
$[,
@@ -82,6 +84,34 @@ send_admin(Subject, Message, Context) ->
z_email_server:send(#email{queue=false, to=Email, subject=Subject1, text=Message1}, Context)
end.
+
+%% @doc Send a page to an e-mail address, assumes the correct template "mailing_page.tpl" is available.
+%% Defaults for these pages are supplied by mod_mailinglist.
+send_page(undefined, _Id, _Context) ->
+ {error, not_email};
+send_page(_Email, undefined, _Context) ->
+ {error, not_found};
+send_page(Email, Id, Context) when is_integer(Id) ->
+ Vars = [
+ {id, Id},
+ {recipient, Email}
+ ],
+ case m_rsc:is_a(Id, document, Context) of
+ false ->
+ send_render(Email, {cat, "mailing_page.tpl"}, Vars, Context);
+ true ->
+ E = #email{
+ to=Email,
+ html_tpl={cat, "mailing_page.tpl"},
+ vars=Vars,
+ attachments=[Id]
+ },
+ send(E, Context)
+ end;
+send_page(Email, Id, Context) ->
+ send_page(Email, m_rsc:rid(Id, Context), Context).
+
+
%% @doc Send an email message defined by the email record.
send(#email{} = Email, Context) ->
z_email_server:send(Email, Context).

0 comments on commit 8babe0b

Please sign in to comment.
Something went wrong with that request. Please try again.