A platform for community discussion. Free, open, simple.
FEATURE: better email subject lines (#36040)
David Battersby5f710afcc399
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rbindex 633e10affed..43bf6d68730 100644--- a/app/mailers/user_notifications.rb+++ b/app/mailers/user_notifications.rb@@ -365,14 +365,15 @@ class UserNotifications < ActionMailer::Base@preheader_text = I18n.t("user_notifications.digest.preheader", since: @since)+ subject_key = "user_notifications.digest.subject_template"++ if SiteSetting.simple_email_subject && I18n.exists?("#{subject_key}_improved")+ subject_key += "_improved"+ end+opts = {from_alias: I18n.t("user_notifications.digest.from", site_name: Email.site_title),- subject:- I18n.t(- "user_notifications.digest.subject_template",- email_prefix: @email_prefix,- date: short_date(Time.now),- ),+ subject: I18n.t(subject_key, email_prefix: @email_prefix, date: short_date(Time.now)),add_unsubscribe_link: !opts[:skip_unsubscribe_links],unsubscribe_url: "#{Discourse.base_url}/email/unsubscribe/#{@unsubscribe_key}",topic_ids: topics_for_digest.pluck(:id),@@ -662,9 +663,9 @@ class UserNotifications < ActionMailer::Basesubject_pm =if opts[:show_group_in_subject] && group.present?if group.full_name- "[#{group.full_name}] "+ SiteSetting.simple_email_subject ? "#{group.full_name}: " : "[#{group.full_name}] "else- "[#{group.name}] "+ SiteSetting.simple_email_subject ? "#{group.name}: " : "[#{group.name}] "endelseI18n.t("subject_pm")diff --git a/app/services/site_setting/action/simple_email_subject_toggled.rb b/app/services/site_setting/action/simple_email_subject_toggled.rbnew file mode 100644index 00000000000..fd13635d191--- /dev/null+++ b/app/services/site_setting/action/simple_email_subject_toggled.rb@@ -0,0 +1,56 @@+# frozen_string_literal: true++class SiteSetting::Action::SimpleEmailSubjectToggled+ include Service::Base++ SIMPLE_EMAIL_SUBJECT = "%{site_name}: %{topic_title}"++ params { attribute :setting_enabled, :boolean }++ step :update_email_subject+ only_if(:has_setting_enabled) { step :copy_translation_overrides }+ step :request_refresh++ def has_setting_enabled(params:)+ params.setting_enabled+ end++ private++ def update_email_subject(params:)+ if params.setting_enabled+ return if SiteSetting.email_subject != SiteSetting.defaults.get(:email_subject)+ SiteSetting.set_and_log(:email_subject, SIMPLE_EMAIL_SUBJECT)+ else+ return if SiteSetting.email_subject != SIMPLE_EMAIL_SUBJECT+ SiteSetting.set_and_log(:email_subject, SiteSetting.defaults.get(:email_subject))+ end+ end++ def copy_translation_overrides+ TranslationOverride+ .where(locale: SiteSetting.default_locale)+ .where.not("translation_key LIKE '%_improved'")+ .find_each do |override|+ improved_key = improved_variant_of(override.translation_key)+ next unless improved_key++ TranslationOverride.upsert!(SiteSetting.default_locale, improved_key, override.value)+ end+ end++ def improved_variant_of(key)+ return "#{key}_improved" if I18n.exists?("#{key}_improved")++ # pluralized keys store suffix on the parent: "foo.one" maps to "foo_improved.one"+ match = key.match(/\A(.+)\.(zero|one|two|few|many|other)\z/)+ return nil unless match++ pluralized = "#{match[1]}_improved.#{match[2]}"+ I18n.exists?(pluralized) ? pluralized : nil+ end++ def request_refresh+ Discourse.request_refresh!+ end+enddiff --git a/config/initializers/015-track-upcoming-change-toggle.rb b/config/initializers/015-track-upcoming-change-toggle.rbindex a84eb5a3651..1f804ba3f12 100644--- a/config/initializers/015-track-upcoming-change-toggle.rb+++ b/config/initializers/015-track-upcoming-change-toggle.rb@@ -18,8 +18,14 @@ Rails.application.config.after_initialize { UpcomingChanges.clear_caches! }DiscourseEvent.on(:upcoming_change_enabled) do |setting_name|# Respond to event here, e.g. if setting_name == :enable_form_templates do X.+ if setting_name == :simple_email_subject+ SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: true })+ endendDiscourseEvent.on(:upcoming_change_disabled) do |setting_name|# Respond to event here, e.g. if setting_name == :enable_form_templates do X.+ if setting_name == :simple_email_subject+ SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: false })+ endenddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 852a1cce929..aa092cd7170 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1863,6 +1863,7 @@ en:notification_email: "The from: email address used when sending all essential system emails. The domain specified here must have SPF, DKIM and reverse PTR records set correctly for email to arrive."email_custom_headers: "A list of custom email headers"email_subject: "Customizable subject format for standard emails. See <a href='https://meta.discourse.org/t/customizing-specific-system-email-templates/88323' target='_blank'>https://meta.discourse.org/t/customizing-specific-system-email-templates/88323</a>"+ simple_email_subject: "When enabled, the email subject lines will be more concise, containing only the essential information. This makes it easier for users to quickly understand the purpose of the email at a glance."detailed_404: "Provides more details to users about why they can’t access a particular topic. Note: This is less secure because users will know if a URL links to a valid topic."enforce_second_factor: "Require users to enable two-factor authentication (2FA) before they can access the Discourse UI. This setting does not affect API or 'DiscourseConnect provider' authentication. If enforce_second_factor_on_external_auth is enabled, users will not be able to log in with external authentication providers after they set up 2FA."enforce_second_factor_on_external_auth: "Require users to use two-factor authentication (2FA) at all times. When enabled, this will prevent users logging in with external authentication methods like social logins if they have 2FA enabled. When disabled, users will only need to confirm their 2FA when logging in with a username and password. Also see the `enforce_second_factor` setting."@@ -3344,6 +3345,7 @@ en:download_backup_mailer:title: "Download Backup Mailer"subject_template: "[%{email_prefix}] Site Backup Download"+ subject_template_improved: "%{email_prefix}: Site backup download"text_body_template: |Here's the [site backup download](%{backup_file_path}) you requested.@@ -3356,6 +3358,7 @@ en:admin_confirmation_mailer:title: "Admin Confirmation"subject_template: "[%{email_prefix}] Confirm new Admin Account"+ subject_template_improved: "%{email_prefix}: Confirm new admin account"text_body_template: |Please confirm that you'd like to add **%{target_username} (%{target_email})** as an administrator for your forum.@@ -3364,6 +3367,7 @@ en:test_mailer:title: "Test Mailer"subject_template: "[%{email_prefix}] Email Deliverability Test"+ subject_template_improved: "%{email_prefix}: Email deliverability test"text_body_template: |This is a test email from@@ -3383,6 +3387,7 @@ en:new_version_mailer:title: "New Version Mailer"subject_template: "[%{email_prefix}] New Discourse version, update available"+ subject_template_improved: "%{email_prefix}: New Discourse version, update available"text_body_template: |Hooray, a new version of [Discourse](https://www.discourse.org) is available!@@ -3398,6 +3403,7 @@ en:new_version_mailer_with_notes:title: "New Version Mailer with Notes"subject_template: "[%{email_prefix}] update available"+ subject_template_improved: "%{email_prefix}: Update available"text_body_template: |Hooray, a new version of [Discourse](https://www.discourse.org) is available!@@ -3786,6 +3792,7 @@ en:email_reject_insufficient_trust_level:title: "Email Reject insufficient Trust Level"subject_template: "[%{email_prefix}] Email issue -- Insufficient Trust Level"+ subject_template_improved: "%{email_prefix}: Email issue -- insufficient trust level"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3794,6 +3801,7 @@ en:email_reject_user_not_found:title: "Email Reject User Not Found"subject_template: "[%{email_prefix}] Email issue -- User Not Found"+ subject_template_improved: "%{email_prefix}: Email issue -- user not found"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3802,6 +3810,7 @@ en:email_reject_screened_email:title: "Email Reject Screened Email"subject_template: "[%{email_prefix}] Email issue -- Blocked Email"+ subject_template_improved: "%{email_prefix}: Email issue -- blocked email"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3809,7 +3818,8 @@ en:email_reject_not_allowed_email:title: "Email Reject Not Allowed Email"- subject_template: "[%{email_prefix}] Email issue -- Blocked Email"+ subject_template: "[%{email_prefix}] Email issue -- blocked email"+ subject_template_improved: "%{email_prefix}: Email issue -- blocked email"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3818,6 +3828,7 @@ en:email_reject_inactive_user:title: "Email Reject Inactive User"subject_template: "[%{email_prefix}] Email issue -- Inactive User"+ subject_template_improved: "%{email_prefix}: Email issue -- inactive user"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3826,6 +3837,7 @@ en:email_reject_silenced_user:title: "Email Reject Silenced User"subject_template: "[%{email_prefix}] Email issue -- Silenced User"+ subject_template_improved: "%{email_prefix}: Email issue -- silenced user"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3834,6 +3846,7 @@ en:email_reject_reply_user_not_matching:title: "Email Reject User Not Matching"subject_template: "[%{email_prefix}] Email issue -- Unexpected Reply Address"+ subject_template_improved: "%{email_prefix}: Email issue -- unexpected reply address"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3842,6 +3855,7 @@ en:email_reject_empty:title: "Email Reject Empty"subject_template: "[%{email_prefix}] Email issue -- No Content"+ subject_template_improved: "%{email_prefix}: Email issue -- no content"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3852,6 +3866,7 @@ en:email_reject_parsing:title: "Email Reject Parsing"subject_template: "[%{email_prefix}] Email issue -- Content Unrecognized"+ subject_template_improved: "%{email_prefix}: Email issue -- content unrecognized"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3860,6 +3875,7 @@ en:email_reject_invalid_access:title: "Email Reject Invalid Access"subject_template: "[%{email_prefix}] Email issue -- Invalid Access"+ subject_template_improved: "%{email_prefix}: Email issue -- invalid access"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3868,6 +3884,7 @@ en:email_reject_strangers_not_allowed:title: "Email Reject Strangers Not Allowed"subject_template: "[%{email_prefix}] Email issue -- Invalid Access"+ subject_template_improved: "%{email_prefix}: Email issue -- invalid access"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3876,6 +3893,7 @@ en:email_reject_invalid_post:title: "Email Reject Invalid Post"subject_template: "[%{email_prefix}] Email issue -- Posting error"+ subject_template_improved: "%{email_prefix}: Email issue -- posting error"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3884,6 +3902,7 @@ en:email_reject_invalid_post_specified:title: "Email Reject Invalid Post Specified"subject_template: "[%{email_prefix}] Email issue -- Posting error"+ subject_template_improved: "%{email_prefix}: Email issue -- posting error"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3897,6 +3916,7 @@ en:email_reject_post_too_short:title: "Email Reject Post Too Short"subject_template: "[%{email_prefix}] Email issue -- Post too short"+ subject_template_improved: "%{email_prefix}: Email issue -- post too short"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3905,6 +3925,7 @@ en:email_reject_invalid_post_action:title: "Email Reject Invalid Post Action"subject_template: "[%{email_prefix}] Email issue -- Invalid Post Action"+ subject_template_improved: "%{email_prefix}: Email issue -- invalid post action"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3913,6 +3934,7 @@ en:email_reject_reply_key:title: "Email Reject Reply Key"subject_template: "[%{email_prefix}] Email issue -- Unknown Reply Key"+ subject_template_improved: "%{email_prefix}: Email issue -- unknown reply key"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3921,6 +3943,7 @@ en:email_reject_bad_destination_address:title: "Email Reject Bad Destination Address"subject_template: "[%{email_prefix}] Email issue -- Unknown To: Address"+ subject_template_improved: "%{email_prefix}: Email issue -- unknown to: address"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3937,6 +3960,7 @@ en:email_reject_old_destination:title: "Email Reject Old Destination"subject_template: "[%{email_prefix}] Email issue -- You are trying to reply to an old notification"+ subject_template_improved: "%{email_prefix}: Email issue -- you are trying to reply to an old notification"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3945,6 +3969,7 @@ en:email_reject_topic_not_found:title: "Email Reject Topic Not Found"subject_template: "[%{email_prefix}] Email issue -- Topic Not Found"+ subject_template_improved: "%{email_prefix}: Email issue -- topic not found"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3953,6 +3978,7 @@ en:email_reject_topic_closed:title: "Email Reject Topic Closed"subject_template: "[%{email_prefix}] Email issue -- Topic Closed"+ subject_template_improved: "%{email_prefix}: Email issue -- topic closed"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3961,6 +3987,7 @@ en:email_reject_auto_generated:title: "Email Reject Auto Generated"subject_template: "[%{email_prefix}] Email issue -- Auto Generated Reply"+ subject_template_improved: "%{email_prefix}: Email issue -- auto generated reply"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3969,6 +3996,7 @@ en:email_reject_unrecognized_error:title: "Email Reject Unrecognized Error"subject_template: "[%{email_prefix}] Email issue -- Unrecognized Error"+ subject_template_improved: "%{email_prefix}: Email issue -- unrecognized error"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3977,6 +4005,7 @@ en:email_reject_attachment:title: "Email Attachment Rejected"subject_template: "[%{email_prefix}] Email issue -- Attachment Rejected"+ subject_template_improved: "%{email_prefix}: Email issue -- attachment rejected"text_body_template: |Unfortunately some attachments in your email message to %{destination} (titled %{former_title}) were rejected.@@ -3988,6 +4017,7 @@ en:email_reject_reply_not_allowed:title: "Email Reject Reply Not Allowed"subject_template: "[%{email_prefix}] Email issue -- Reply Not Allowed"+ subject_template_improved: "%{email_prefix}: Email issue -- reply not allowed"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -3995,7 +4025,8 @@ en:email_reject_reply_to_digest:title: "Email Reject Reply To Summary"- subject_template: "[%{email_prefix}] Email issue -- Reply to Summary"+ subject_template: "[%{email_prefix}] Email issue -- Reply To Summary"+ subject_template_improved: "%{email_prefix}: Email issue -- reply to summary"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -4006,6 +4037,7 @@ en:email_reject_too_many_recipients:title: "Email Reject Too Many Recipients"subject_template: "[%{email_prefix}] Email issue -- Too Many Recipients"+ subject_template_improved: "%{email_prefix}: Email issue -- too many recipients"text_body_template: |We're sorry, but your email message to %{destination} (titled %{former_title}) didn't work.@@ -4016,6 +4048,7 @@ en:email_error_notification:title: "Email Error Notification"subject_template: "[%{email_prefix}] Email issue -- POP authentication error"+ subject_template_improved: "%{email_prefix}: Email issue -- POP authentication error"text_body_template: |Unfortunately, there was an authentication error while polling mails from the POP server.@@ -4153,7 +4186,7 @@ en:new_user_of_the_month:title: "You're a New User of the Month!"- subject_template: "You're a New User of the Month!"+ subject_template: "You're a new user of the month!"text_body_template: |Congratulations, you've earned the **New User of the Month award for %{month_year}**. :trophy:@@ -4268,6 +4301,7 @@ en:user_invited_to_private_message_pm_group:title: "User Invited Group to PM"subject_template: "[%{email_prefix}] %{username} invited @%{group_name} to a message '%{topic_title}'"+ subject_template_improved: "%{email_prefix}: %{username} invited @%{group_name} to a message '%{topic_title}'"text_body_template: |%{header_instructions}@@ -4278,6 +4312,7 @@ en:user_invited_to_private_message_pm:title: "User Invited to PM"subject_template: "[%{email_prefix}] %{username} invited you to a message '%{topic_title}'"+ subject_template_improved: "%{email_prefix}: %{username} invited you to a message '%{topic_title}'"text_body_template: |%{header_instructions}@@ -4288,6 +4323,7 @@ en:user_invited_to_private_message_pm_staged:title: "User Invited to PM Staged"subject_template: "[%{email_prefix}] %{username} invited you to a message '%{topic_title}'"+ subject_template_improved: "%{email_prefix}: %{username} invited you to a message '%{topic_title}'"text_body_template: |%{header_instructions}@@ -4298,6 +4334,7 @@ en:user_invited_to_topic:title: "User Invited to Topic"subject_template: "[%{email_prefix}] %{username} invited you to '%{topic_title}'"+ subject_template_improved: "%{email_prefix}: %{username} invited you to '%{topic_title}'"text_body_template: |%{header_instructions}@@ -4309,6 +4346,7 @@ en:title: "User Replied"preview: "Someone replied to your post."subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4321,6 +4359,7 @@ en:user_replied_pm:title: "User Replied PM"subject_template: "[%{email_prefix}] [PM] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4334,6 +4373,7 @@ en:title: "User Quoted"preview: "Someone quoted you in a post."subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4347,6 +4387,7 @@ en:title: "User Linked"preview: "Post linked in another topic."subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4360,6 +4401,7 @@ en:title: "User Mentioned"preview: "Someone mentioned you in a post."subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4372,6 +4414,7 @@ en:user_mentioned_pm:title: "User Mentioned PM"subject_template: "[%{email_prefix}] [PM] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4384,6 +4427,7 @@ en:user_group_mentioned:title: "User Group Mentioned"subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4396,6 +4440,7 @@ en:user_group_mentioned_pm:title: "User Group Mentioned PM"subject_template: "[%{email_prefix}] [PM] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4408,6 +4453,7 @@ en:user_group_mentioned_pm_group:title: "User Group Mentioned PM"subject_template: "[%{email_prefix}] [PM] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4421,6 +4467,7 @@ en:title: "User Posted"preview: "Someone replied to a topic you are Watching."subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4433,6 +4480,7 @@ en:user_watching_category_or_tag:title: "User Watching Category or Tag"subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4445,6 +4493,7 @@ en:user_watching_first_post:title: "User Watching First Post"subject_template: "[%{email_prefix}] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4458,6 +4507,7 @@ en:title: "User Posted PM"preview: "Someone sent you a PM."subject_template: "[%{email_prefix}] [PM] %{topic_title}"+ subject_template_improved: "%{email_prefix}: %{topic_title}"text_body_template: |%{header_instructions}@@ -4477,6 +4527,7 @@ en:account_suspended:title: "Account Suspended"subject_template: "[%{email_prefix}] Your account has been suspended"+ subject_template_improved: "Your account has been suspended"text_body_template: |You have been suspended from the forum until %{suspended_till}.@@ -4485,6 +4536,7 @@ en:account_suspended_forever:title: "Account Suspended"subject_template: "[%{email_prefix}] Your account has been suspended"+ subject_template_improved: "Your account has been suspended"text_body_template: |You have been suspended from the forum.@@ -4493,6 +4545,7 @@ en:account_silenced:title: "Account Silenced"subject_template: "[%{email_prefix}] Your account has been silenced"+ subject_template_improved: "Your account has been silenced"text_body_template: |You have been silenced from the forum until %{silenced_till}.@@ -4501,6 +4554,7 @@ en:account_silenced_forever:title: "Account Silenced"subject_template: "[%{email_prefix}] Your account has been silenced"+ subject_template_improved: "Your account has been silenced"text_body_template: |You have been silenced from the forum.@@ -4509,6 +4563,7 @@ en:account_deleted:title: "Account Deleted"subject_template: "[%{email_prefix}] Your account has been deleted"+ subject_template_improved: "Your account has been deleted"text_body_template: |Hello,@@ -4521,6 +4576,7 @@ en:account_exists:title: "Account already exists"subject_template: "[%{email_prefix}] Account already exists"+ subject_template_improved: "Account already exists"text_body_template: |You just tried to create an account at %{site_name}, or tried to change the email of an account to %{email}. However, an account already exists for %{email}.@@ -4533,6 +4589,7 @@ en:account_second_factor_disabled:title: "Two-Factor Authentication disabled"subject_template: "[%{email_prefix}] Two-Factor Authentication disabled"+ subject_template_improved: "Two-Factor Authentication disabled"text_body_template: |Two-factor authentication has been disabled on your account at %{site_name}. You can now log in with only your password; an additional authentication code is no longer required.@@ -4553,6 +4610,7 @@ en:popular_posts: "Popular Posts"more_new: "New for you"subject_template: "[%{email_prefix}] Summary"+ subject_template_improved: "Summary"unsubscribe: "This summary is sent from %{site_link} when we haven't seen you in a while. Change %{email_preferences_link}, or %{unsubscribe_link} to unsubscribe."your_email_settings: "your email settings"click_here: "click here"@@ -4585,6 +4643,7 @@ en:title: "Forgot Password"preview: "Reset your password."subject_template: "[%{email_prefix}] Password reset"+ subject_template_improved: "Password reset"text_body_template: |Somebody asked to reset your password on [%{site_name}](%{base_url}).@@ -4597,6 +4656,7 @@ en:title: "Log in via link"preview: "Log in via link."subject_template: "[%{email_prefix}] Log in via link"+ subject_template_improved: "Log in via link"text_body_template: |Here's your link to log in at [%{site_name}](%{base_url}).@@ -4608,7 +4668,8 @@ en:set_password:title: "Set Password"preview: "Set account password."- subject_template: "[%{email_prefix}] Set Password"+ subject_template: "[%{email_prefix}] Set password"+ subject_template_improved: "Set password"text_body_template: |Somebody asked to add a password to your account on [%{site_name}](%{base_url}). Alternatively, you can log in using any supported online service (Google, Facebook, etc) that is associated with this validated email address.@@ -4621,6 +4682,7 @@ en:title: "Admin Login"preview: "Admin login requested."subject_template: "[%{email_prefix}] Login"+ subject_template_improved: "Login"text_body_template: |Somebody asked to log in to your account on [%{site_name}](%{base_url}).@@ -4632,7 +4694,8 @@ en:account_created:title: "Account Created"preview: "New account created for you."- subject_template: "[%{email_prefix}] Your New Account"+ subject_template: "[%{email_prefix}] Your new account"+ subject_template_improved: "Your new account"text_body_template: |A new account was created for you at %{site_name}@@ -4642,6 +4705,7 @@ en:confirm_new_email:title: "Confirm New Email"subject_template: "[%{email_prefix}] Confirm your new email address"+ subject_template_improved: "Confirm your new email address"text_body_template: |Confirm your new email address for %{site_name} by clicking on the following link:@@ -4652,6 +4716,7 @@ en:confirm_new_email_via_admin:title: "Confirm New Email"subject_template: "[%{email_prefix}] Confirm your new email address"+ subject_template_improved: "Confirm your new email address"text_body_template: |Confirm your new email address for %{site_name} by clicking on the following link:@@ -4662,6 +4727,7 @@ en:confirm_old_email:title: "Confirm Old Email"subject_template: "[%{email_prefix}] Confirm your current email address"+ subject_template_improved: "Confirm your current email address"text_body_template: |Before we can change your email address, we need you to confirm that you controlthe current email account. After you complete this step, we will have you confirm@@ -4674,6 +4740,7 @@ en:confirm_old_email_add:title: "Confirm Old Email (Add)"subject_template: "[%{email_prefix}] Confirm your current email address"+ subject_template_improved: "Confirm your current email address"text_body_template: |Before we can add a new email address, we need you to confirm that you controlthe current email account. After you complete this step, we will have you confirm@@ -4687,6 +4754,7 @@ en:title: "Notify Old Email"preview: "Email address updated."subject_template: "[%{email_prefix}] Your email address has been changed"+ subject_template_improved: "Your email address has been changed"text_body_template: |This is an automated message to let you know that your email address for%{site_name} has been changed. If this was done in error, please contact@@ -4699,6 +4767,7 @@ en:notify_old_email_add:title: "Notify Old Email (Add)"subject_template: "[%{email_prefix}] A new email address has been added"+ subject_template_improved: "A new email address has been added"text_body_template: |This is an automated message to let you know that an email address for%{site_name} has been added. If this was done in error, please contact@@ -4740,6 +4809,7 @@ en:title: "Signup"preview: "Confirm your account."subject_template: "[%{email_prefix}] Confirm your new account"+ subject_template_improved: "Confirm your new account"text_body_template: |Welcome to %{site_name}!@@ -4751,6 +4821,7 @@ en:activation_reminder:title: "Activation Reminder"subject_template: "[%{email_prefix}] Reminder to confirm your account"+ subject_template_improved: "Reminder to confirm your account"text_body_template: |Welcome to %{site_name}!@@ -4764,7 +4835,8 @@ en:suspicious_login:title: "New Login Alert"preview: "Verify your device."- subject_template: "[%{site_name}] New Login from %{location}"+ subject_template: "[%{site_name}] New login from %{location}"+ subject_template_improved: "%{site_name}: New login from %{location}"text_body_template: |Hello,@@ -4781,6 +4853,7 @@ en:post_approved:title: "Your post was approved"subject_template: "[%{site_name}] Your post was approved"+ subject_template_improved: "%{site_name}: Your post was approved"text_body_template: |Hello,diff --git a/config/site_settings.yml b/config/site_settings.ymlindex ad4d0c3f179..42df0cabdb2 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1944,6 +1944,15 @@ email:email_subject:default: "[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}"area: "email"+ simple_email_subject:+ default: false+ client: true+ hidden: true+ upcoming_change:+ status: "experimental"+ impact: "feature,all_members"+ disallow_enabled_for_groups: true+ learn_more_url: "https://meta.discourse.org/t/-/395927"reply_by_email_enabled:default: falsevalidator: "ReplyByEmailEnabledValidator"diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rbindex 75a23f4088c..71180f2721d 100644--- a/lib/email/message_builder.rb+++ b/lib/email/message_builder.rb@@ -139,7 +139,13 @@ module Emailsubject = @opts[:add_re_to_subject] ? I18n.t("subject_re") : ""subject = "#{subject}#{@template_args[:topic_title]}"elsif @opts[:template]- subject = I18n.t("#{@opts[:template]}.subject_template", @template_args)+ subject_key = "#{@opts[:template]}.subject_template"++ if SiteSetting.simple_email_subject && I18n.exists?("#{subject_key}_improved")+ subject_key += "_improved"+ end++ subject = I18n.t(subject_key, @template_args)elsesubject = @opts[:subject]enddiff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.ymlindex 853678d8486..f2ba2a65cdb 100644--- a/plugins/chat/config/locales/server.en.yml+++ b/plugins/chat/config/locales/server.en.yml@@ -266,23 +266,43 @@ en:private_email:one: "[%{site_name}] New message"other: "[%{site_name}] New messages"+ private_email_improved:+ one: "New message"+ other: "New messages"watched_thread:one: "[%{site_name}] New thread message in %{channel}"other: "[%{site_name}] New thread messages in %{channel}"+ watched_thread_improved:+ one: "New thread message in %{channel}"+ other: "New thread messages in %{channel}"watched_threads:one: "[%{site_name}] New thread messages in %{channel} and %{count} other channel"other: "[%{site_name}] New thread messages in %{channel} and %{count} other channels"+ watched_threads_improved:+ one: "New thread messages in %{channel} and %{count} other channel"+ other: "New thread messages in %{channel} and %{count} other channels"chat_dm_1:one: "[%{site_name}] New message from %{name}"other: "[%{site_name}] New messages from %{name}"+ chat_dm_1_improved:+ one: "New message from %{name}"+ other: "New messages from %{name}"chat_dm_2: "[%{site_name}] New messages from %{name_1} and %{name_2}"+ chat_dm_2_improved: "New messages from %{name_1} and %{name_2}"chat_dm_3_or_more: "[%{site_name}] New messages from %{name} and %{count} other direct message channels"+ chat_dm_3_or_more_improved: "New messages from %{name} and %{count} other direct message channels"chat_channel_1:one: "[%{site_name}] New message in %{channel}"other: "[%{site_name}] New messages in %{channel}"+ chat_channel_1_improved:+ one: "New message in %{channel}"+ other: "New messages in %{channel}"chat_channel_2: "[%{site_name}] New messages in %{channel_1} and %{channel_2}"+ chat_channel_2_improved: "New messages in %{channel_1} and %{channel_2}"chat_channel_3_or_more: "[%{site_name}] New messages in %{channel} and %{count} other channels"+ chat_channel_3_or_more_improved: "New messages in %{channel} and %{count} other channels"chat_channel_and_dm: "[%{site_name}] New messages in %{channel} and from %{name}"+ chat_channel_and_dm_improved: "New messages in %{channel} and from %{name}"unsubscribe: "This chat summary is sent from %{site_link} when you are away. Change your %{email_preferences_link}, or %{unsubscribe_link} to unsubscribe."unsubscribe_no_link: "This chat summary is sent from %{site_link} when you are away. Change your %{email_preferences_link}."view_messages:diff --git a/plugins/chat/lib/chat/user_notifications_extension.rb b/plugins/chat/lib/chat/user_notifications_extension.rbindex 18ca672543b..dd966ffc74b 100644--- a/plugins/chat/lib/chat/user_notifications_extension.rb+++ b/plugins/chat/lib/chat/user_notifications_extension.rb@@ -81,7 +81,10 @@ module Chatenddef subject(type, **args)- I18n.t("user_notifications.chat_summary.subject.#{type}", { site_name: @site_name, **args })+ key = "user_notifications.chat_summary.subject.#{type}"+ key += "_improved" if SiteSetting.simple_email_subject && I18n.exists?("#{key}_improved")++ I18n.t(key, { site_name: @site_name, **args })enddef chat_summary_subject(grouped_channels, grouped_dms, grouped_threads, count)diff --git a/plugins/chat/spec/mailers/user_notifications_spec.rb b/plugins/chat/spec/mailers/user_notifications_spec.rbindex c90b60f9c26..ec285784520 100644--- a/plugins/chat/spec/mailers/user_notifications_spec.rb+++ b/plugins/chat/spec/mailers/user_notifications_spec.rb@@ -646,4 +646,23 @@ describe UserNotifications doendendend++ describe "when SiteSetting.simple_email_subject is enabled" do+ before do+ SiteSetting.simple_email_subject = true+ followed_channel.add(user)+ create_message(followed_channel, "hello @#{user.username}", Chat::UserMention)+ end++ it "uses the improved chat summary subject" do+ expect(chat_summary_email.subject).to eq(+ I18n.t(+ "user_notifications.chat_summary.subject.chat_channel_1_improved",+ site_name:,+ channel: followed_channel.name,+ count: 1,+ ),+ )+ end+ endenddiff --git a/plugins/discourse-assign/config/locales/server.en.yml b/plugins/discourse-assign/config/locales/server.en.ymlindex 2530203f66b..5239a8bb9a0 100644--- a/plugins/discourse-assign/config/locales/server.en.yml+++ b/plugins/discourse-assign/config/locales/server.en.yml@@ -59,6 +59,7 @@ en:assign_mailer:title: "Assign Mailer"subject_template: "[%{email_prefix}] %{assignee_name} assigned you to '%{topic_title}'!"+ subject_template_improved: "%{email_prefix}: %{assignee_name} assigned you to '%{topic_title}'!"text_body_template: |Hey, %{assignee_name} **assigned** you to a discussion> **%{topic_title}**diff --git a/spec/jobs/download_backup_email_spec.rb b/spec/jobs/download_backup_email_spec.rbindex 258bf4d81bb..01e58f9ed5d 100644--- a/spec/jobs/download_backup_email_spec.rb+++ b/spec/jobs/download_backup_email_spec.rb@@ -3,13 +3,15 @@RSpec.describe Jobs::DownloadBackupEmail dofab!(:user, :admin)+ before { SiteSetting.simple_email_subject = true }+it "should work" dodescribed_class.new.execute(user_id: user.id, backup_file_path: "http://some.example.test/")email = ActionMailer::Base.deliveries.lastexpect(email.subject).to eq(- I18n.t("download_backup_mailer.subject_template", email_prefix: SiteSetting.title),+ I18n.t("download_backup_mailer.subject_template_improved", email_prefix: SiteSetting.title),)expect(email.body.raw_source).to include(diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rbindex 92c8fd0d02f..f3defcb2559 100644--- a/spec/mailers/user_notifications_spec.rb+++ b/spec/mailers/user_notifications_spec.rb@@ -4,6 +4,8 @@ RSpec.describe UserNotifications dolet(:user) { Fabricate(:admin) }describe "#get_context_posts" do+ fab!(:category)+it "does not include hidden/deleted/user_deleted posts in context" dopost1 = create_post_post2 = Fabricate(:post, topic: post1.topic, deleted_at: 1.day.ago)@@ -146,6 +148,8 @@ RSpec.describe UserNotifications dolet(:email_html) { Email::Renderer.new(email).html }+ before { SiteSetting.simple_email_subject = false }+it "generates the right email" doexpect(email.to).to eq([user.email])expect(email.from).to eq([SiteSetting.notification_email])@@ -170,8 +174,11 @@ RSpec.describe UserNotifications doenddescribe ".digest" do+ fab!(:category)subject(:email) { UserNotifications.digest(user) }+ before { SiteSetting.uncategorized_category_id = category.id }+after { Discourse.redis.keys("summary-new-users:*").each { |key| Discourse.redis.del(key) } }context "without new topics" do@@ -248,11 +255,17 @@ RSpec.describe UserNotifications doit "includes email_prefix in email subject instead of site title" doSiteSetting.email_prefix = "Try Discourse"SiteSetting.title = "Discourse Meta"+ SiteSetting.simple_email_subject = falseexpect(email.subject).to match(/Try Discourse/)expect(email.subject).not_to match(/Discourse Meta/)end+ it "does not include site name or email prefix in simple email subject" do+ SiteSetting.simple_email_subject = true+ expect(email.subject).to eq(I18n.t("user_notifications.digest.subject_template_improved"))+ end+it "includes unread likes received count within the since date" doFabricate(:notification,@@ -971,7 +984,10 @@ RSpec.describe UserNotifications doendcontext "when SiteSetting.group_name_in_subject is true" do- before { SiteSetting.group_in_subject = true }+ before do+ SiteSetting.group_in_subject = true+ SiteSetting.simple_email_subject = true+ endlet(:group) { Fabricate(:group, name: "my_group") }let(:mail) do@@ -985,14 +1001,14 @@ RSpec.describe UserNotifications doshared_examples "includes first group name" doit "includes first group name in subject" do- expect(mail.subject).to include("[my_group] ")+ expect(mail.subject).to include("my_group: ")endcontext "when first group has full name" doit "includes full name in subject" dogroup.full_name = "My Group"group.save- expect(mail.subject).to include("[My Group] ")+ expect(mail.subject).to include("My Group: ")endendend@@ -1807,4 +1823,42 @@ RSpec.describe UserNotifications doendendend++ describe "improved email subject templates" do+ def assert_improved_template_format(base_key)+ original = I18n.t("user_notifications.#{base_key}.subject_template")+ improved = I18n.t("user_notifications.#{base_key}.subject_template_improved")++ # subject changed from "[Discourse] my topic title" to "Discourse: my topic title"+ expect(original).to include("[%{email_prefix}]")+ expect(improved).to include("%{email_prefix}:")+ expect(improved).not_to match(/\[.*\]/)+ end++ describe "notification email templates" do+ %w[+ user_replied+ user_replied_pm+ user_quoted+ user_mentioned+ user_mentioned_pm+ user_posted+ user_posted_pm+ ].each do |template_key|+ it "has improved version for #{template_key}" do+ assert_improved_template_format(template_key)+ end+ end+ end++ describe "account-related email templates" do+ %w[account_exists account_suspended account_silenced].each do |template_key|+ it "has improved version for #{template_key} without email_prefix" do+ improved = I18n.t("user_notifications.#{template_key}.subject_template_improved")++ expect(improved).not_to include("%{email_prefix}")+ end+ end+ end+ endenddiff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rbindex 538247e6394..53eea9615fc 100644--- a/spec/models/reviewable_flagged_post_spec.rb+++ b/spec/models/reviewable_flagged_post_spec.rb@@ -261,11 +261,12 @@ RSpec.describe ReviewableFlaggedPost, type: :model doendit "sends email when deleting a spammer" do+ SiteSetting.simple_email_subject = trueexpect { reviewable.perform(moderator, :delete_user) }.to change {ActionMailer::Base.deliveries.count}expect(ActionMailer::Base.deliveries.last.subject).to include(- I18n.t("user_notifications.account_deleted.subject_template", email_prefix: "Discourse"),+ I18n.t("user_notifications.account_deleted.subject_template_improved"),)end@@ -278,11 +279,12 @@ RSpec.describe ReviewableFlaggedPost, type: :model doendit "sends email when deleting and blocking a spammer" do+ SiteSetting.simple_email_subject = trueexpect { reviewable.perform(moderator, :delete_user_block) }.to change {ActionMailer::Base.deliveries.count}expect(ActionMailer::Base.deliveries.last.subject).to include(- I18n.t("user_notifications.account_deleted.subject_template", email_prefix: "Discourse"),+ I18n.t("user_notifications.account_deleted.subject_template_improved"),)enddiff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 0d5526d5235..05493c0ce9d 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -2625,6 +2625,8 @@ RSpec.describe PostAlerter doit "skips sending a notification email to the group and all other email addresses that are _not_ members of the group,sends a group_smtp_email instead" doNotificationEmailer.enable+ SiteSetting.simple_email_subject = true+ SiteSetting.email_subject = "%{site_name}: %{topic_title}"incoming_email_post = create_post_with_incomingtopic = incoming_email_post.topic@@ -2658,7 +2660,7 @@ RSpec.describe PostAlerter doexpect(email.from).to eq([SiteSetting.notification_email])expect(email.to).to contain_exactly(group_user1.user.email)expect(email.cc).to eq(nil)- expect(email.subject).to eq("[Discourse] [PM] #{topic.title}")+ expect(email.subject).to eq("Discourse: #{topic.title}")endit "excludes users with email_messages_level set to never from group SMTP emails" dodiff --git a/spec/services/site_setting/action/simple_email_subject_toggled_spec.rb b/spec/services/site_setting/action/simple_email_subject_toggled_spec.rbnew file mode 100644index 00000000000..2689d0e7333--- /dev/null+++ b/spec/services/site_setting/action/simple_email_subject_toggled_spec.rb@@ -0,0 +1,155 @@+# frozen_string_literal: true++RSpec.describe SiteSetting::Action::SimpleEmailSubjectToggled do+ describe ".call" do+ subject(:result) { described_class.call(params:) }++ let(:default_email_subject) { SiteSetting.defaults.get(:email_subject) }+ let(:simple_email_subject) { described_class::SIMPLE_EMAIL_SUBJECT }++ context "when enabling" do+ let(:params) { { setting_enabled: true } }++ it { is_expected.to run_successfully }++ it "updates email_subject to the simple format" do+ result+ expect(SiteSetting.email_subject).to eq(simple_email_subject)+ end++ context "when admin has customized email_subject" do+ before { SiteSetting.email_subject = "custom subject" }++ it "does not overwrite the custom email_subject" do+ result+ expect(SiteSetting.email_subject).to eq("custom subject")+ end+ end++ context "when translation overrides exist for keys with _improved variants" do+ let(:translation_key) { "user_notifications.user_posted.subject_template" }+ let(:improved_key) { "#{translation_key}_improved" }+ let(:custom_value) { "custom override" }++ before do+ TranslationOverride.upsert!(SiteSetting.default_locale, translation_key, custom_value)+ end++ it "copies the override to the _improved key" do+ result+ improved_override =+ TranslationOverride.find_by(+ locale: SiteSetting.default_locale,+ translation_key: improved_key,+ )+ expect(improved_override).to be_present+ expect(improved_override.value).to eq(custom_value)+ end+ end++ context "when translation overrides exist for pluralized keys with _improved variants" do+ let(:translation_key) { "user_notifications.chat_summary.subject.chat_dm_1.one" }+ let(:improved_key) { "user_notifications.chat_summary.subject.chat_dm_1_improved.one" }+ let(:custom_value) { "custom plural override" }++ before do+ TranslationOverride.upsert!(SiteSetting.default_locale, translation_key, custom_value)+ end++ it "copies the override to the pluralized _improved leaf" do+ result+ improved_override =+ TranslationOverride.find_by(+ locale: SiteSetting.default_locale,+ translation_key: improved_key,+ )+ expect(improved_override).to be_present+ expect(improved_override.value).to eq(custom_value)+ end+ end++ context "when a translation override key already ends with _improved" do+ let(:original_key) { "user_notifications.user_posted.subject_template" }+ let(:improved_key) { "user_notifications.user_posted.subject_template_improved" }+ let(:original_value) { "original override" }+ let(:improved_value) { "improved override" }++ before do+ TranslationOverride.upsert!(SiteSetting.default_locale, improved_key, improved_value)+ end++ it "does not try to copy the value" do+ result+ improved_override =+ TranslationOverride.find_by(+ locale: SiteSetting.default_locale,+ translation_key: improved_key,+ )+ expect(improved_override).to be_present+ expect(improved_override.value).to eq(improved_value)+ end+ end++ context "when a pluralized translation override key already targets an _improved variant" do+ let(:improved_key) { "user_notifications.chat_summary.subject.chat_dm_1_improved.one" }+ let(:improved_value) { "custom improved plural" }++ before do+ TranslationOverride.upsert!(SiteSetting.default_locale, improved_key, improved_value)+ end++ it "does not overwrite the improved override" do+ result+ improved_override =+ TranslationOverride.find_by(+ locale: SiteSetting.default_locale,+ translation_key: improved_key,+ )+ expect(improved_override).to be_present+ expect(improved_override.value).to eq(improved_value)+ end+ end+ end++ context "when disabling" do+ let(:params) { { setting_enabled: false } }++ before { SiteSetting.email_subject = simple_email_subject }++ it { is_expected.to run_successfully }++ it "resets email_subject to the default" do+ result+ expect(SiteSetting.email_subject).to eq(default_email_subject)+ end++ context "when admin has customized email_subject" do+ before { SiteSetting.email_subject = "custom subject" }++ it "does not overwrite the custom email_subject" do+ result+ expect(SiteSetting.email_subject).to eq("custom subject")+ end+ end++ context "when _improved translation overrides exist" do+ let(:improved_key) { "user_notifications.user_posted.subject_template_improved" }++ before do+ TranslationOverride.upsert!(SiteSetting.default_locale, improved_key, "custom improved")+ end++ it "does not revert the _improved overrides" do+ result+ override =+ TranslationOverride.find_by(+ locale: SiteSetting.default_locale,+ translation_key: improved_key,+ )+ expect(override).to be_present+ expect(override.value).to eq("custom improved")+ end+ end+ end+ end+end