FIX: from field of emails should be including email_site_title or site title settings

This commit is contained in:
Neil Lalonde 2017-02-27 14:22:56 -05:00
parent f7d413bb1b
commit e634b37f9a
2 changed files with 20 additions and 3 deletions

View File

@ -202,11 +202,16 @@ module Email
end
def alias_email(source)
return source if @opts[:from_alias].blank? && SiteSetting.email_site_title.blank?
return source if @opts[:from_alias].blank? &&
SiteSetting.email_site_title.blank? &&
SiteSetting.title.blank?
if !@opts[:from_alias].blank?
"#{Email.cleanup_alias(@opts[:from_alias])} <#{source}>"
elsif source == SiteSetting.notification_email || source == SiteSetting.reply_by_email_address
site_alias_email(source)
else
"#{Email.cleanup_alias(SiteSetting.email_site_title)} <#{source}>"
source
end
end

View File

@ -237,9 +237,15 @@ describe Email::MessageBuilder do
context "from field" do
it "has the default from" do
SiteSetting.title = ""
expect(build_args[:from]).to eq(SiteSetting.notification_email)
end
it "title setting will be added if present" do
SiteSetting.title = "Dog Talk"
expect(build_args[:from]).to eq("Dog Talk <#{SiteSetting.notification_email}>")
end
let(:finn_email) { 'finn@adventuretime.ooo' }
let(:custom_from) { Email::MessageBuilder.new(to_address, from: finn_email).build_args }
@ -262,7 +268,13 @@ describe Email::MessageBuilder do
end
it "email_site_title will be added if it's set" do
SiteSetting.stubs(:email_site_title).returns("The Forum")
SiteSetting.email_site_title = "The Forum"
expect(build_args[:from]).to eq("The Forum <#{SiteSetting.notification_email}>")
end
it "email_site_title overrides title" do
SiteSetting.title = "Dog Talk"
SiteSetting.email_site_title = "The Forum"
expect(build_args[:from]).to eq("The Forum <#{SiteSetting.notification_email}>")
end