diff --git a/app/models/mailer.rb b/app/models/mailer.rb index ddbc7b394..148b1da16 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -670,14 +670,18 @@ class Mailer < ActionMailer::Base @author&.logged? ? @author.name : Setting.app_title end from = mail_from.format - list_id = "<#{mail_from.address.to_s.tr('@', '.')}>" + from_addr = mail_from.address.to_s rescue Mail::Field::IncompleteParseError # Use Setting.mail_from as it is if Mail::Address cannot parse it # (probably the emission address is not RFC compliant) from = Setting.mail_from.to_s - list_id = "<#{from.tr('@', '.')}>" + from_addr = from end + project_identifier = + Setting.include_project_in_list_id? ? self.headers['X-Redmine-Project']&.value : nil + list_id = "<#{[project_identifier, from_addr.tr('@', '.')].compact.join('.')}>" + headers.reverse_merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, 'X-Redmine-Site' => Setting.app_title, diff --git a/app/views/settings/_notifications.html.erb b/app/views/settings/_notifications.html.erb index aafbe4340..342e006c3 100644 --- a/app/views/settings/_notifications.html.erb +++ b/app/views/settings/_notifications.html.erb @@ -7,6 +7,8 @@

<%= setting_check_box :plain_text_mail %>

<%= setting_check_box :show_status_changes_in_mail_subject %>

+ +

<%= setting_check_box :include_project_in_list_id %>

<%=l(:text_select_mail_notifications)%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 7d51ed1b7..6f832da31 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -521,6 +521,7 @@ en: setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject setting_project_list_defaults: Projects list defaults setting_twofa: Two-factor authentication + setting_include_project_in_list_id: Include project identifier in List-Id header permission_add_project: Create project permission_add_subprojects: Create subprojects diff --git a/config/settings.yml b/config/settings.yml index 19d3a33c7..e27add8ec 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -349,3 +349,5 @@ timelog_accept_future_dates: default: 1 show_status_changes_in_mail_subject: default: 1 +include_project_in_list_id: + default: 1 diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 0506e27d2..f6108a6fc 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -220,7 +220,7 @@ class MailerTest < ActiveSupport::TestCase assert_equal 'All', mail.header['X-Auto-Response-Suppress'].to_s assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s # List-Id should not include the display name "Redmine" - assert_equal '', mail.header['List-Id'].to_s + assert_equal '', mail.header['List-Id'].to_s assert_equal 'Bug', mail.header['X-Redmine-Issue-Tracker'].to_s assert_equal 'Low', mail.header['X-Redmine-Issue-Priority'].to_s end