Skip to content

Commit

Permalink
Split send_page/3 function from action to z_email, so it can be easil…
Browse files Browse the repository at this point in the history
…y reused.
  • Loading branch information
mworrell committed Aug 22, 2012
1 parent 305fcfd commit 8babe0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
32 changes: 31 additions & 1 deletion src/smtp/z_email.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
get_admin_email/1,
send_admin/3,

send_page/3,

send/2,
send/3,

Expand Down Expand Up @@ -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 = [
$[,
Expand All @@ -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).
Expand Down

0 comments on commit 8babe0b

Please sign in to comment.