FIX: Remove markers from all translated languages (#14081)

Emails can include the marker in a different language, depending on
site and user settings. The email receiver always looked for the marker
in default language.
This commit is contained in:
Bianca Nenciu 2021-08-18 19:42:04 +03:00 committed by GitHub
parent 7db3888f17
commit 5c9abab0cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 2 deletions

View File

@ -549,11 +549,19 @@ module Email
end
def previous_replies_regex
@previous_replies_regex ||= /^--[- ]\n\*#{I18n.t("user_notifications.previous_discussion")}\*\n/im
strings = I18n.available_locales.map do |locale|
I18n.with_locale(locale) { I18n.t("user_notifications.previous_discussion") }
end.uniq
@previous_replies_regex ||= /^--[- ]\n\*(?:#{strings.map { |x| Regexp.escape(x) }.join("|")})\*\n/im
end
def reply_above_line_regex
@reply_above_line_regex ||= /\n#{I18n.t("user_notifications.reply_above_line")}\n/im
strings = I18n.available_locales.map do |locale|
I18n.with_locale(locale) { I18n.t("user_notifications.reply_above_line") }
end.uniq
@reply_above_line_regex ||= /\n(?:#{strings.map { |x| Regexp.escape(x) }.join("|")})\n/im
end
def trim_discourse_markers(reply)

View File

@ -412,11 +412,21 @@ describe Email::Receiver do
expect(topic.posts.last.raw).to eq("This will not include the previous discussion that is present in this email.")
end
it "removes the trnaslated 'Previous Replies' marker" do
expect { process(:previous_replies_de) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This will not include the previous discussion that is present in this email.")
end
it "removes the 'type reply above' marker" do
expect { process(:reply_above) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This will not include the previous discussion that is present in this email.")
end
it "removes the translated 'Previous Replies' marker" do
expect { process(:reply_above_de) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This will not include the previous discussion that is present in this email.")
end
it "handles multiple paragraphs" do
expect { process(:paragraphs) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("Do you like liquorice?\n\nI really like them. One could even say that I am *addicted* to liquorice. And if\nyou can mix it up with some anise, then I'm in heaven ;)")

View File

@ -0,0 +1,23 @@
Return-Path: <discourse@bar.com>
From: Foo Bar <discourse@bar.com>
To: reply+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com
Date: Fri, 15 Jan 2016 00:12:43 +0100
Message-ID: <21@foo.bar.mail>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
This will not include the previous discussion that is present in this email.
---
*Vorherige Antworten*
This is previous reply #1.
Posted by foo bar on 01/15/2016
---
[Visit the Topic](https://bar.com/t/wat/1/1) to respond
To stop receiving notifications for this particular topic, [click here](h=
ttps://bar.com/t/wat/1/unsubscribe). To unsubscribe from these emails, ch=
ange your [user preferences](https://bar.com/my/preferences).

15
spec/fixtures/emails/reply_above_de.eml vendored Normal file
View File

@ -0,0 +1,15 @@
Return-Path: <discourse@bar.com>
From: Foo Bar <discourse@bar.com>
To: reply+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com
Date: Fri, 15 Jan 2016 00:12:43 +0100
Message-ID: <21@foo.bar.mail>
Mime-Version: 1.0
Content-Type: text/html; charset=UTF-8
<p>This will not include the previous discussion that is present in this email.</p>
<div>
## Bitte gib deine Antwort oberhalb dieser Zeile ein. ##
</div>
<div>previous discussion</div>