mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Don't raise an exception when the emission email address is not RFC compliant (#5913).
Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@18050 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
cae8905b7c
commit
ce6e9ca950
@ -629,19 +629,28 @@ class Mailer < ActionMailer::Base
|
|||||||
def mail(headers={}, &block)
|
def mail(headers={}, &block)
|
||||||
# Add a display name to the From field if Setting.mail_from does not
|
# Add a display name to the From field if Setting.mail_from does not
|
||||||
# include it
|
# include it
|
||||||
|
begin
|
||||||
mail_from = Mail::Address.new(Setting.mail_from)
|
mail_from = Mail::Address.new(Setting.mail_from)
|
||||||
if mail_from.display_name.blank? && mail_from.comments.blank?
|
if mail_from.display_name.blank? && mail_from.comments.blank?
|
||||||
mail_from.display_name =
|
mail_from.display_name =
|
||||||
@author&.logged? ? @author.name : Setting.app_title
|
@author&.logged? ? @author.name : Setting.app_title
|
||||||
end
|
end
|
||||||
|
from = mail_from.format
|
||||||
|
list_id = "<#{mail_from.address.to_s.tr('@', '.')}>"
|
||||||
|
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('@', '.')}>"
|
||||||
|
end
|
||||||
|
|
||||||
headers.reverse_merge! 'X-Mailer' => 'Redmine',
|
headers.reverse_merge! 'X-Mailer' => 'Redmine',
|
||||||
'X-Redmine-Host' => Setting.host_name,
|
'X-Redmine-Host' => Setting.host_name,
|
||||||
'X-Redmine-Site' => Setting.app_title,
|
'X-Redmine-Site' => Setting.app_title,
|
||||||
'X-Auto-Response-Suppress' => 'All',
|
'X-Auto-Response-Suppress' => 'All',
|
||||||
'Auto-Submitted' => 'auto-generated',
|
'Auto-Submitted' => 'auto-generated',
|
||||||
'From' => mail_from.format,
|
'From' => from,
|
||||||
'List-Id' => "<#{mail_from.address.to_s.tr('@', '.')}>"
|
'List-Id' => list_id
|
||||||
|
|
||||||
# Replaces users with their email addresses
|
# Replaces users with their email addresses
|
||||||
[:to, :cc, :bcc].each do |key|
|
[:to, :cc, :bcc].each do |key|
|
||||||
|
|||||||
@ -252,6 +252,18 @@ class MailerTest < ActiveSupport::TestCase
|
|||||||
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_from_header_with_rfc_non_compliant_phrase
|
||||||
|
# Send out the email instead of raising an exception
|
||||||
|
# no matter if the emission email address is not RFC compliant
|
||||||
|
assert_nothing_raised do
|
||||||
|
with_settings :mail_from => '[Redmine app] <redmine@example.net>' do
|
||||||
|
Mailer.deliver_test_email(User.find(1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
mail = last_email
|
||||||
|
assert_match /<redmine@example\.net>/, mail.from_addrs.first
|
||||||
|
assert_equal '[Redmine app] <redmine@example.net>', mail.header['From'].to_s
|
||||||
|
end
|
||||||
def test_from_header_with_author_name
|
def test_from_header_with_author_name
|
||||||
# Use the author's name or Setting.app_title as a display name
|
# Use the author's name or Setting.app_title as a display name
|
||||||
# when Setting.mail_from does not include a display name
|
# when Setting.mail_from does not include a display name
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user