diff --git a/app/models/mailer.rb b/app/models/mailer.rb index f58a1c88d..be5032a63 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -71,6 +71,7 @@ class Mailer < ActionMailer::Base # Builds a mail for notifying user about a new issue def issue_add(user, issue) + headers['Priority'] = priority_for_header(issue) redmine_headers 'Project' => issue.project.identifier, 'Issue-Tracker' => issue.tracker.name, 'Issue-Id' => issue.id, @@ -103,6 +104,7 @@ class Mailer < ActionMailer::Base # Builds a mail for notifying user about an issue update def issue_edit(user, journal) issue = journal.journalized + headers['Priority'] = priority_for_header(issue) redmine_headers 'Project' => issue.project.identifier, 'Issue-Tracker' => issue.tracker.name, 'Issue-Id' => issue.id, @@ -763,6 +765,19 @@ class Mailer < ActionMailer::Base h.each {|k, v| headers["X-Redmine-#{k}"] = v.to_s} end + def priority_for_header(issue) + # IssuePriority#low? and IssuePriority#high? are not used for + # performance reasons + position_name = issue.priority.position_name.to_s + if position_name == 'default' + 'normal' + elsif position_name.start_with?('high') + 'urgent' + elsif position_name.start_with?('low') + 'non-urgent' + end + end + # Singleton class method is public class << self def token_for(object, user) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index b25e17427..b1e5f4db3 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -210,6 +210,7 @@ class MailerTest < ActiveSupport::TestCase # List-Id should not include the display name "Redmine" assert_equal '', mail.header['List-Id'].to_s assert_equal 'Bug', mail.header['X-Redmine-Issue-Tracker'].to_s + assert_equal 'non-urgent', mail.header['Priority'].to_s end def test_email_headers_should_include_sender @@ -219,6 +220,24 @@ class MailerTest < ActiveSupport::TestCase assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s end + def test_email_headers_should_include_priority + to_test = { + IssuePriority.find(4) => 'non-urgent', # Low + IssuePriority.find(5) => 'normal', # Normal + IssuePriority.find(6) => 'urgent', # High + IssuePriority.find(7) => 'urgent', # Urgent + IssuePriority.find(8) => 'urgent', # Immediate + } + + issue = Issue.find(1) + to_test.each do |priority, expected| + issue.update_attribute :priority_id, priority.id + Mailer.deliver_issue_add(issue) + mail = last_email + assert_equal expected, mail.header['Priority'].to_s + end + end + def test_plain_text_mail Setting.plain_text_mail = 1 journal = Journal.find(2)