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.
This commit is contained in:
Neil Lalonde 2019-08-06 12:45:28 -04:00
parent a475c384d8
commit 4b9d35cd0e
4 changed files with 22 additions and 1 deletions

View File

@ -5,7 +5,7 @@
<%- if SiteSetting.private_email? %> <%- if SiteSetting.private_email? %>
<p><%= t('system_messages.contents_hidden') %></p> <p><%= t('system_messages.contents_hidden') %></p>
<% else %> <% 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? %> <% if in_reply_to_post.present? || context_posts.present? %>
<div class='footer'>%{respond_instructions}</div> <div class='footer'>%{respond_instructions}</div>

View File

@ -1815,6 +1815,7 @@ en:
always_show_trimmed_content: "Always show trimmed part of incoming emails. WARNING: might reveal email addresses." 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." 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." 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." manual_polling_enabled: "Push emails using the API for email replies."
pop3_polling_enabled: "Poll via POP3 for email replies." pop3_polling_enabled: "Poll via POP3 for email replies."

View File

@ -1034,6 +1034,7 @@ email:
email_total_attachment_size_limit_kb: email_total_attachment_size_limit_kb:
default: 0 default: 0
max: 51200 max: 51200
post_excerpts_in_emails: false
files: files:
max_image_size_kb: max_image_size_kb:

View File

@ -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(response.raw)
expect(mail.text_part.to_s).to_not include(topic.url) expect(mail.text_part.to_s).to_not include(topic.url)
end 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 end
describe '.user_posted' do describe '.user_posted' do