Feature #11530
openSupport hooks in mailer
Added by Kouhei Sutou over 12 years ago. Updated over 2 years ago.
0%
Description
Could you support hooks in mailer?
Views can be extended by plugin. I want to extend mail content by plugin.
I want to add newly added Wiki content to Wiki added notification mails.
I also want to add changed Wiki content diff to Wiki updated notification mails.
If Redmine supports hooks in mailer, I can write a plugin to do them.
Files
0001-Support-hooks-in-mailer.patch (3 KB) 0001-Support-hooks-in-mailer.patch | Kouhei Sutou, 2012-07-29 10:52 | ||
support-hooks-in-mailer-for-r10463.patch (1.95 KB) support-hooks-in-mailer-for-r10463.patch | Kouhei Sutou, 2012-09-24 04:25 | ||
support-hooks-in-mailer-for-r14648.patch (1.94 KB) support-hooks-in-mailer-for-r14648.patch | Kouhei Sutou, 2015-10-08 14:26 | ||
support-hooks-in-mailer-for-r16963.patch (15.7 KB) support-hooks-in-mailer-for-r16963.patch | okkez _, 2017-09-12 09:37 | ||
support-hooks-in-mailer-for-r18899.patch (16.4 KB) support-hooks-in-mailer-for-r18899.patch | Kouhei Sutou, 2019-11-05 08:46 | ||
support-hooks-in-mailer-for-r18899-2.patch (17.8 KB) support-hooks-in-mailer-for-r18899-2.patch | Kouhei Sutou, 2019-11-05 10:48 | ||
support-hooks-in-mailer-for-r18899-3.patch (17.8 KB) support-hooks-in-mailer-for-r18899-3.patch | Kouhei Sutou, 2019-11-05 11:26 | ||
support-hooks-in-mailer-for-r21217.patch (18 KB) support-hooks-in-mailer-for-r21217.patch | Kouhei Sutou, 2021-09-07 23:46 |
Related issues
Updated by Kouhei Sutou over 12 years ago
I attach a patch to support hooks in mailer.
We need to do two things to support hooks in mailer.
- Add view path of plugins to ActionView::Base
- Call
call_hook
in template
Here is the change for view path:
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index c3f4150..dae51ee 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -82,6 +82,7 @@ module Redmine #:nodoc: view_path = File.join(p.directory, 'app', 'views') if File.directory?(view_path) ActionController::Base.prepend_view_path(view_path) + ActionMailer::Base.prepend_view_path(view_path) end # Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
In the patch, just two call_hook
are only added. We need more call_hook
to make mailer more extensible.
Updated by Kouhei Sutou over 12 years ago
Here is a plugin that uses hooks in mailer:
https://github.com/kou/redmine-plugin-wiki-change-notifier
If this feature request is accepted, the plugin works.
For now, the plugin works with the attached patch.
Updated by Kouhei Sutou about 12 years ago
I've updated the patch because #11776 adds the following change:
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index c3f4150..dae51ee 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -82,6 +82,7 @@ module Redmine #:nodoc: view_path = File.join(p.directory, 'app', 'views') if File.directory?(view_path) ActionController::Base.prepend_view_path(view_path) + ActionMailer::Base.prepend_view_path(view_path) end # Adds the app/{controllers,helpers,models} directories of the plugin to the autoload path
Updated by Toshi MARUYAMA over 10 years ago
- Related to Feature #12508: Add diff to wiki change notification added
Updated by Kouhei Sutou about 9 years ago
I've updated the patch for r14648.
Updated by Go MAEDA about 9 years ago
Thank you for submitting patches.
Although the patch updates app/views/mailer/wiki_content_*.erb, I think other app/views/mailer/*.erb files should also have hooks for consistency.
Updated by Kouhei Sutou about 9 years ago
Thanks for your response.
I'll also update other files when a developer accepts this request.
Updated by okkez _ about 7 years ago
I've updated the patch for r16963.
This patch also includes changes for adding hooks to app/views/mailer/*.erb same as app/views/mailer/wiki_content_*.erb.
I hope that next major release includes this patch.
Updated by Go MAEDA about 7 years ago
- Target version set to 4.1.0
okkez _ wrote:
I've updated the patch for r16963.
This patch also includes changes for adding hooks to app/views/mailer/*.erb same as app/views/mailer/wiki_content_*.erb.
It looks good to me. I am setting target version to 4.1.0.
Thank you for posting the patch.
Updated by Toshi MARUYAMA about 7 years ago
- Related to Feature #26839: Inline Email Diff For Issue 'Description' Changes added
Updated by Jean-Philippe Lang over 5 years ago
- Target version changed from 4.1.0 to Candidate for next major release
We need to provide a way for the hook to know if we're rendering a html or plain text email.
Updated by Kouhei Sutou over 5 years ago
It's already provided.
If we're rendering a HTML email, XXX.html.erb
is used.
If we're rendering a plain text email, XXX.text.erb
is used.
Updated by Jean-Philippe Lang over 5 years ago
Kouhei Sutou wrote:
It's already provided.
If we're rendering a HTML email,XXX.html.erb
is used.
If we're rendering a plain text email,XXX.text.erb
is used.
Sure, but how does the hook that is called know about this?
Updated by Kouhei Sutou over 5 years ago
We can get :text
in XXX.text.erb
and :html
in XXX.html.erb
by calling lookup_context.rendered_format
.
We can also get [:text]
in XXX.text.erb
and [:html]
in XXX.html.erb
by calling formats
.
Updated by Kouhei Sutou about 5 years ago
I've updated the patch for r18899.
Updated by Kouhei Sutou about 5 years ago
I added more hooks to `app/views/mailer/issue_edit*`:
--- support-hooks-in-mailer-for-r18899.patch 2019-11-05 16:44:11.906980336 +0900
+++ support-hooks-in-mailer-for-r18899-2.patch 2019-11-05 18:46:16.355343392 +0900
@@ -132,28 +132,68 @@
===================================================================
--- app/views/mailer/issue_edit.html.erb (revision 18899)
+++ app/views/mailer/issue_edit.html.erb (working copy)
-@@ -13,3 +13,8 @@
+@@ -10,6 +10,28 @@
+ <% end %>
+ </ul>
+
++<%= call_hook(:view_mailer_issue_edit_after_details,
++ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
++ :users => @users,
++ :issue_url => @issue_url) %>
++
<%= textilizable(@journal, :notes, :only_path => false) %>
++
++<%= call_hook(:view_mailer_issue_edit_after_notes,
++ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
++ :users => @users,
++ :issue_url => @issue_url) %>
++
<hr />
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
+
+<%= call_hook(:view_mailer_issue_edit_bottom,
+ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
+ :users => @users,
+ :issue_url => @issue_url) %>
Index: app/views/mailer/issue_edit.text.erb
===================================================================
--- app/views/mailer/issue_edit.text.erb (revision 18899)
+++ app/views/mailer/issue_edit.text.erb (working copy)
-@@ -10,3 +10,8 @@
+@@ -3,10 +3,27 @@
+ <% details_to_strings(@journal_details, true).each do |string| -%>
+ <%= string %>
+ <% end -%>
+-
++<%= call_hook(:view_mailer_issue_edit_after_details,
++ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
++ :users => @users,
++ :issue_url => @issue_url) -%>
+ <% if @journal.notes? -%>
+ <%= @journal.notes %>
+
<% end -%>
++<%= call_hook(:view_mailer_issue_edit_after_notes,
++ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
++ :users => @users,
++ :issue_url => @issue_url) -%>
----------------------------------------
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
-+
+<%= call_hook(:view_mailer_issue_edit_bottom,
+ :issue => @issue,
++ :journal => @journal,
++ :journal_details => @journal_details,
+ :users => @users,
-+ :issue_url => @issue_url) %>
++ :issue_url => @issue_url) -%>
Index: app/views/mailer/lost_password.html.erb
===================================================================
--- app/views/mailer/lost_password.html.erb (revision 18899)
Updated by Kouhei Sutou about 5 years ago
Sorry... I added one more cosmetic fix...
Updated by Kouhei Sutou about 3 years ago
I've updated the patch for r21217.
Updated by Kouhei Sutou over 2 years ago
Could someone take a look at this?
We use this maintained patch in almost 10 years. We use this patch with Redmine 5.0.0 now.