Feature #13359 ยป 13359.patch
app/models/mailer.rb | ||
---|---|---|
661 | 661 |
end |
662 | 662 | |
663 | 663 |
def mail(headers={}, &block) |
664 |
# Add a display name to the From field if Setting.mail_from does not |
|
665 |
# include it |
|
666 | 664 |
begin |
665 |
# Add a display name to the From field if Setting.mail_from does not |
|
666 |
# include it |
|
667 | 667 |
mail_from = Mail::Address.new(Setting.mail_from) |
668 | 668 |
if mail_from.display_name.blank? && mail_from.comments.blank? |
669 | 669 |
mail_from.display_name = |
670 | 670 |
@author&.logged? ? @author.name : Setting.app_title |
671 | 671 |
end |
672 | 672 |
from = mail_from.format |
673 |
list_id = "<#{mail_from.address.to_s.tr('@', '.')}>" |
|
673 | ||
674 |
# Construct the value of the List-Id header field |
|
675 |
from_addr = mail_from.address.to_s |
|
676 |
project_identifier = self.headers['X-Redmine-Project']&.value |
|
677 |
list_id = if project_identifier.present? |
|
678 |
"<#{project_identifier}.#{from_addr.tr('@', '.')}>" |
|
679 |
else |
|
680 |
# Emails outside of a project context |
|
681 |
"<#{from_addr.tr('@', '.')}>" |
|
682 |
end |
|
674 | 683 |
rescue Mail::Field::IncompleteParseError |
675 | 684 |
# Use Setting.mail_from as it is if Mail::Address cannot parse it |
676 | 685 |
# (probably the emission address is not RFC compliant) |
test/unit/mailer_test.rb | ||
---|---|---|
220 | 220 |
assert_equal 'All', mail.header['X-Auto-Response-Suppress'].to_s |
221 | 221 |
assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s |
222 | 222 |
# List-Id should not include the display name "Redmine" |
223 |
assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s |
|
223 |
assert_equal '<ecookbook.redmine.example.net>', mail.header['List-Id'].to_s
|
|
224 | 224 |
assert_equal 'Bug', mail.header['X-Redmine-Issue-Tracker'].to_s |
225 | 225 |
assert_equal 'Low', mail.header['X-Redmine-Issue-Priority'].to_s |
226 | 226 |
end |
... | ... | |
327 | 327 |
end |
328 | 328 |
end |
329 | 329 | |
330 |
def test_list_id_header_should_include_project_identifier |
|
331 |
with_settings :mail_from => 'redmine@example.net' do |
|
332 |
content = WikiContent.find(1) |
|
333 |
Mailer.deliver_wiki_content_added(content) |
|
334 |
mail = last_email |
|
335 |
assert_equal '<ecookbook.redmine.example.net>', mail.header['List-Id'].to_s |
|
336 |
end |
|
337 |
end |
|
338 | ||
339 |
def test_list_id_header_excludes_project_identifier_for_non_project_emails |
|
340 |
with_settings :mail_from => 'redmine@example.net' do |
|
341 |
Mailer.deliver_test_email(User.find(1)) |
|
342 |
mail = last_email |
|
343 |
assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s |
|
344 |
end |
|
345 |
end |
|
346 | ||
330 | 347 |
def test_should_not_send_email_without_recipient |
331 | 348 |
news = News.first |
332 | 349 |
user = news.author |