From c0a8bb9a919ff5a11ed453007723ba671b12977d Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Fri, 4 Jan 2019 16:06:21 +0100 Subject: [PATCH] FEATURE: Include "via " in email From header --- app/mailers/user_notifications.rb | 2 +- config/locales/server.en.yml | 1 + lib/email.rb | 4 ++++ lib/email/message_builder.rb | 8 ++++---- spec/mailers/user_notifications_spec.rb | 10 +++++----- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index af664694dc6..429e78b17a2 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -412,7 +412,7 @@ class UserNotifications < ActionMailer::Base title: notification_data[:topic_title], post: post, username: original_username, - from_alias: user_name, + from_alias: I18n.t('email_from', user_name: user_name, site_name: Email.site_title), allow_reply_by_email: allow_reply_by_email, use_site_subject: opts[:use_site_subject], add_re_to_subject: opts[:add_re_to_subject], diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 0cfb9cdd120..906e5eea508 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2884,6 +2884,7 @@ en: subject_re: "Re: " subject_pm: "[PM] " + email_from: "%{user_name} via %{site_name}" user_notifications: previous_discussion: "Previous Replies" diff --git a/lib/email.rb b/lib/email.rb index ed9182980db..9b7e13e81de 100644 --- a/lib/email.rb +++ b/lib/email.rb @@ -37,4 +37,8 @@ module Email [text&.decoded, html&.decoded] end + def self.site_title + SiteSetting.email_site_title.presence || SiteSetting.title + end + end diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 0d39cd5eff6..146f49774ba 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -208,8 +208,8 @@ module Email SiteSetting.email_site_title.blank? && SiteSetting.title.blank? - if !@opts[:from_alias].blank? - "\"#{Email.cleanup_alias(@opts[:from_alias])}\" <#{source}>" + if @opts[:from_alias].present? + %Q|"#{Email.cleanup_alias(@opts[:from_alias])}" <#{source}>| elsif source == SiteSetting.notification_email || source == SiteSetting.reply_by_email_address site_alias_email(source) else @@ -218,8 +218,8 @@ module Email end def site_alias_email(source) - from_alias = SiteSetting.email_site_title.presence || SiteSetting.title - "\"#{Email.cleanup_alias(from_alias)}\" <#{source}>" + from_alias = Email.site_title + %Q|"#{Email.cleanup_alias(from_alias)}" <#{source}>| end end diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index bd56dbd542e..4c350124ee9 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -247,7 +247,7 @@ describe UserNotifications do notification_data_hash: notification.data_hash ) # from should include full user name - expect(mail[:from].display_names).to eql(['John Doe']) + expect(mail[:from].display_names).to eql(['John Doe via Discourse']) # subject should include category name expect(mail.subject).to match(/India/) @@ -350,7 +350,7 @@ describe UserNotifications do expect(mail[:from].display_names).to_not eql(['John Doe']) # from should include username if "show user full names" is disabled - expect(mail[:from].display_names).to eql(['john']) + expect(mail[:from].display_names).to eql(['john via Discourse']) # subject should not include category name expect(mail.subject).not_to match(/Uncategorized/) @@ -397,7 +397,7 @@ describe UserNotifications do ) # from should include username if full user name is not provided - expect(mail[:from].display_names).to eql(['john']) + expect(mail[:from].display_names).to eql(['john via Discourse']) # subject should include "[PM]" expect(mail.subject).to include("[PM] ") @@ -656,13 +656,13 @@ describe UserNotifications do it "should have user name as from_alias" do SiteSetting.enable_names = true SiteSetting.display_name_on_posts = true - expects_build_with(has_entry(:from_alias, "#{user.name}")) + expects_build_with(has_entry(:from_alias, "#{user.name} via Discourse")) end it "should not have user name as from_alias if display_name_on_posts is disabled" do SiteSetting.enable_names = false SiteSetting.display_name_on_posts = false - expects_build_with(has_entry(:from_alias, "walterwhite")) + expects_build_with(has_entry(:from_alias, "walterwhite via Discourse")) end it "should explain how to respond" do