Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@17870 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/4.1.0
end | end | ||||
def mail(headers={}, &block) | def mail(headers={}, &block) | ||||
# Add a display name to the From field if Setting.mail_from does not | |||||
# include it | |||||
mail_from = Mail::Address.new(Setting.mail_from) | |||||
if mail_from.display_name.blank? && mail_from.comments.blank? | |||||
mail_from.display_name = | |||||
(@author && @author.logged?) ? @author.name : Setting.app_title | |||||
end | |||||
headers.reverse_merge! 'X-Mailer' => 'Redmine', | headers.reverse_merge! 'X-Mailer' => 'Redmine', | ||||
'X-Redmine-Host' => Setting.host_name, | 'X-Redmine-Host' => Setting.host_name, | ||||
'X-Redmine-Site' => Setting.app_title, | 'X-Redmine-Site' => Setting.app_title, | ||||
'X-Auto-Response-Suppress' => 'All', | 'X-Auto-Response-Suppress' => 'All', | ||||
'Auto-Submitted' => 'auto-generated', | 'Auto-Submitted' => 'auto-generated', | ||||
'From' => Setting.mail_from, | |||||
'List-Id' => "<#{Setting.mail_from.to_s.tr('@', '.')}>" | |||||
'From' => mail_from.format, | |||||
'List-Id' => "<#{mail_from.address.to_s.tr('@', '.')}>" | |||||
# Replaces users with their email addresses | # Replaces users with their email addresses | ||||
[:to, :cc, :bcc].each do |key| | [:to, :cc, :bcc].each do |key| |
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s | assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s | ||||
end | end | ||||
def test_from_header_with_author_name | |||||
# Use the author's name or Setting.app_title as a display name | |||||
# when Setting.mail_from does not include a display name | |||||
with_settings :mail_from => 'redmine@example.net', :app_title => 'Foo' do | |||||
# Use @author.name as a display name | |||||
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, | |||||
:subject => 'Issue created by Dave Lopper', :author_id => 3) | |||||
mail = last_email | |||||
assert_equal 'redmine@example.net', mail.from_addrs.first | |||||
assert_equal 'Dave Lopper <redmine@example.net>', mail.header['From'].to_s | |||||
# Use app_title if @author is nil or AnonymousUser | |||||
Mailer.deliver_test_email(User.find(1)) | |||||
mail = last_email | |||||
assert_equal 'redmine@example.net', mail.from_addrs.first | |||||
assert_equal "Foo <redmine@example.net>", mail.header['From'].to_s | |||||
end | |||||
end | |||||
def test_should_not_send_email_without_recipient | def test_should_not_send_email_without_recipient | ||||
news = News.first | news = News.first | ||||
user = news.author | user = news.author |