diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 3a2a6b17568..8817cddb77d 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -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 diff --git a/spec/components/email/message_builder_spec.rb b/spec/components/email/message_builder_spec.rb index eec704c6054..06cb06ce0dc 100644 --- a/spec/components/email/message_builder_spec.rb +++ b/spec/components/email/message_builder_spec.rb @@ -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