diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c6822362e..c6becfdd4 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -368,7 +368,7 @@ class Mailer < ActionMailer::Base ActionMailer::Base.delivery_method = saved_method end - def mail(headers={}) + def mail(headers={}, &block) headers.merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, 'X-Redmine-Site' => Setting.app_title, @@ -403,12 +403,17 @@ class Mailer < ActionMailer::Base headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') end - super headers do |format| - format.text - format.html unless Setting.plain_text_mail? + m = if block_given? + super headers, &block + else + super headers do |format| + format.text + format.html unless Setting.plain_text_mail? + end end - set_language_if_valid @initial_language + + m end def initialize(*args) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index a2f371632..138611bc1 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -725,6 +725,10 @@ class MailerTest < ActiveSupport::TestCase end end + def test_mail_should_return_a_mail_message + assert_kind_of ::Mail::Message, Mailer.test_email(User.find(1)) + end + private def last_email