FEATURE: add option to always send excerpts in emails

FEATURE: add option to always send excerpts in emails

Enable the new setting “post excerpts in emails” to send excerpts instead of complete posts in notification emails. Control the length of excerpts with the “post excerpt maxlength” setting.

diff --git a/app/views/email/notification.html.erb b/app/views/email/notification.html.erb
index d5d458c..cc30418 100644
--- a/app/views/email/notification.html.erb
+++ b/app/views/email/notification.html.erb
@@ -5,7 +5,7 @@
   <%- if SiteSetting.private_email? %>
     <p><%= t('system_messages.contents_hidden') %></p>
   <% else %>
-    <%= render partial: 'email/post', locals: { post: post, use_excerpt: false } %>
+    <%= render partial: 'email/post', locals: { post: post, use_excerpt: SiteSetting.post_excerpts_in_emails } %>
 
     <% if in_reply_to_post.present? || context_posts.present? %>
       <div class='footer'>%{respond_instructions}</div>
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index f181103..c40cdf9 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1815,6 +1815,7 @@ en:
     always_show_trimmed_content: "Always show trimmed part of incoming emails. WARNING: might reveal email addresses."
     private_email: "Don't include content from posts or topics in email title or email body. NOTE: also disables digest emails."
     email_total_attachment_size_limit_kb: "Max total size of files attached to outgoing emails. Set to 0 to disable sending of attachments."
+    post_excerpts_in_emails: "In notification emails, always send excerpts instead of full posts"
 
     manual_polling_enabled: "Push emails using the API for email replies."
     pop3_polling_enabled: "Poll via POP3 for email replies."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index a4b26ff..ad28491 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1034,6 +1034,7 @@ email:
   email_total_attachment_size_limit_kb:
     default: 0
     max: 51200
+  post_excerpts_in_emails: false
 
 files:
   max_image_size_kb:
diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb
index f86892b..420655b 100644
--- a/spec/mailers/user_notifications_spec.rb
+++ b/spec/mailers/user_notifications_spec.rb
@@ -336,6 +336,25 @@ describe UserNotifications do
       expect(mail.text_part.to_s).to_not include(response.raw)
       expect(mail.text_part.to_s).to_not include(topic.url)
     end
+
+    it "includes excerpt when post_excerpts_in_emails is enabled" do
+      paragraphs = [
+        "This is the first paragraph, but you should read more.",
+        "And here is its friend, the second paragraph."
+      ]
+      SiteSetting.post_excerpts_in_emails = true
+      SiteSetting.post_excerpt_maxlength = paragraphs.first.length
+      response.update_attributes!(raw: paragraphs.join("\n\n"))
+      mail = UserNotifications.user_replied(
+        user,
+        post: response,
+        notification_type: notification.notification_type,
+        notification_data_hash: notification.data_hash
+      )
+      mail_html = mail.html_part.body.to_s
+      expect(mail_html.scan(/#{paragraphs[0]}/).count).to eq(1)
+      expect(mail_html.scan(/#{paragraphs[1]}/).count).to eq(0)
+    end
   end
 
   describe '.user_posted' do

GitHub sha: 4b9d35cd

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: