Feature #5913 » 5913-authors-name-in-from-field.patch
| app/models/mailer.rb | ||
|---|---|---|
|
end
|
||
|
def mail(headers={}, &block)
|
||
|
# Assign 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',
|
||
|
'X-Redmine-Host' => Setting.host_name,
|
||
|
'X-Redmine-Site' => Setting.app_title,
|
||
|
'X-Auto-Response-Suppress' => 'All',
|
||
|
'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
|
||
|
[:to, :cc, :bcc].each do |key|
|
||
| test/unit/mailer_test.rb | ||
|---|---|---|
|
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
||
|
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
|
||
|
news = News.first
|
||
|
user = news.author
|
||