Project

General

Profile

Feature #5913 » 5913-authors-name-in-from-field.patch

Go MAEDA, 2019-02-14 02:42

View differences:

app/models/mailer.rb
615 615
  end
616 616

  
617 617
  def mail(headers={}, &block)
618
    # Assign a display name to the From field if Setting.mail_from does not
619
    # include it
620
    mail_from = Mail::Address.new(Setting.mail_from)
621
    if mail_from.display_name.blank? && mail_from.comments.blank?
622
      mail_from.display_name =
623
        (@author && @author.logged?) ? @author.name : Setting.app_title
624
    end
625

  
618 626
    headers.reverse_merge! 'X-Mailer' => 'Redmine',
619 627
            'X-Redmine-Host' => Setting.host_name,
620 628
            'X-Redmine-Site' => Setting.app_title,
621 629
            'X-Auto-Response-Suppress' => 'All',
622 630
            'Auto-Submitted' => 'auto-generated',
623
            'From' => Setting.mail_from,
624
            'List-Id' => "<#{Setting.mail_from.to_s.tr('@', '.')}>"
631
            'From' => mail_from.format,
632
            'List-Id' => "<#{mail_from.address.to_s.tr('@', '.')}>"
625 633

  
626 634
    # Replaces users with their email addresses
627 635
    [:to, :cc, :bcc].each do |key|
test/unit/mailer_test.rb
249 249
    assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
250 250
  end
251 251

  
252
  def test_from_header_with_author_name
253
    # Use the author's name or Setting.app_title as a display name
254
    # when Setting.mail_from does not include a display name
255
    with_settings :mail_from => 'redmine@example.net', :app_title => 'Foo' do
256
      # Use @author.name as a display name
257
      Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
258
      :subject => 'Issue created by Dave Lopper', :author_id => 3)
259
      mail = last_email
260
      assert_equal 'redmine@example.net', mail.from_addrs.first
261
      assert_equal 'Dave Lopper <redmine@example.net>', mail.header['From'].to_s
262

  
263
      # Use app_title if @author is nil or AnonymousUser
264
      Mailer.deliver_test_email(User.find(1))
265
      mail = last_email
266
      assert_equal 'redmine@example.net', mail.from_addrs.first
267
      assert_equal "Foo <redmine@example.net>", mail.header['From'].to_s
268
    end
269
  end
270

  
252 271
  def test_should_not_send_email_without_recipient
253 272
    news = News.first
254 273
    user = news.author
(3-3/4)