Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mod_mailinglist - Add support for external attachments using 'documen…

…t' edges.
  • Loading branch information...
commit 9b00a589d520e4020ec5b3e30d6a2a3e1ead7080 1 parent f734c98
@arjan arjan authored
View
8 modules/mod_mailinglist/actions/action_mailinglist_dialog_email_page.erl
@@ -46,5 +46,11 @@ event({submit, {email_page, Args}, _TriggerId, _TargetId}, Context) ->
Id = proplists:get_value(id, Args),
OnSuccess = proplists:get_all_values(on_success, Args),
Email = z_context:get_q_validated("email", Context),
- z_email:send_render(Email, {cat, "email_page.tpl"}, [{id,Id}, {email,Email}], Context),
+
+ Vars = [{id,Id}, {email,Email}],
+ Attachments = mod_mailinglist:page_attachments(Id, Context),
+
+ z_email_server:send(#email{queue=false, to=Email,
+ html_tpl={cat, "email_page.tpl"}, vars=Vars, attachments=Attachments}, Context),
+
z_render:wire(OnSuccess, Context).
View
27 modules/mod_mailinglist/mod_mailinglist.erl
@@ -35,7 +35,8 @@
observe_mailinglist_message/2,
event/2,
update_scheduled_list/2,
- datamodel/1
+ datamodel/1,
+ page_attachments/2
]).
-include_lib("zotonic.hrl").
@@ -331,10 +332,12 @@ send_mailing_process(ListId, PageId, Context) ->
[] -> skip;
Email1 ->
Options1 = [{email,Email1}|Options],
- case IsDirect of
- true -> z_email:send_render(Email, {cat, "mailing_page.tpl"}, Options1, Context);
- false -> z_email:sendq_render(Email, {cat, "mailing_page.tpl"}, Options1, Context)
- end
+
+ Id = proplists:get_value(id, Options),
+ Attachments = mod_mailinglist:page_attachments(Id, Context),
+
+ z_email_server:send(#email{queue=not(IsDirect), to=Email1,
+ html_tpl={cat, "mailing_page.tpl"}, vars=Options1, attachments=Attachments}, Context)
end.
@@ -348,3 +351,17 @@ send_mailing_process(ListId, PageId, Context) ->
split_list(N, [H|T], Acc) ->
split_list(N-1, T, [H|Acc]).
+
+%% @doc Return list of attachments for this page as a list of files. Attachments are outgoing 'document' edges.
+page_attachments(Id, Context) ->
+ AttIds = m_edge:objects(Id, document, Context),
+ [as_upload(AId, Context) || AId <- AttIds].
+
+
+as_upload(Id, Context) ->
+ M = m_media:get(Id, Context),
+ #upload{
+ tmpfile=z_media_archive:abspath(proplists:get_value(filename, M), Context),
+ mime=proplists:get_value(mime, M),
+ filename=proplists:get_value(original_filename, M)
+ }.
Please sign in to comment.
Something went wrong with that request. Please try again.