From 9294826f312bbdb1ff0fbd22aced8e36c6756b67 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 29 Jun 2017 05:03:14 +0100 Subject: [PATCH] =?UTF-8?q?Allow=20inclusion=20of=20elided=20text=20from?= =?UTF-8?q?=20emails=20when=20sending=20to=20a=20category=E2=80=A6=20(#484?= =?UTF-8?q?4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow inclusion of elided text from emails when sending to a category address --- lib/email/receiver.rb | 1 + spec/components/email/receiver_spec.rb | 22 +++++++++++++++++++ .../emails/forwarded_email_to_category.eml | 18 +++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 spec/fixtures/emails/forwarded_email_to_category.eml diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 56bc320b5aa..d4cdee0f7fc 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -374,6 +374,7 @@ module Email create_topic(user: user, raw: body, + elided: elided, title: subject, category: category.id, skip_validations: user.staged?) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index fc531423cea..f93ec28b67a 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -309,6 +309,18 @@ describe Email::Receiver do expect(topic.posts.last.raw).to eq("This is a reply :)\n\n
\n···\n---Original Message---\nThis part should not be included\n
") end + it "doesn't include the 'elided' part of the original message when always_show_trimmed_content is disabled" do + SiteSetting.always_show_trimmed_content = false + expect { process(:original_message) }.to change { topic.posts.count }.from(1).to(2) + expect(topic.posts.last.raw).to eq("This is a reply :)") + end + + it "adds the 'elided' part of the original message for public replies when always_show_trimmed_content is enabled" do + SiteSetting.always_show_trimmed_content = true + expect { process(:original_message) }.to change { topic.posts.count }.from(1).to(2) + expect(topic.posts.last.raw).to eq("This is a reply :)\n\n
\n···\n---Original Message---\nThis part should not be included\n
") + end + it "supports attached images in TEXT part" do SiteSetting.queue_jobs = true @@ -483,6 +495,16 @@ describe Email::Receiver do expect { process(:new_user) }.to change(Topic, :count) end + it "adds the 'elided' part of the original message when always_show_trimmed_content is enabled" do + SiteSetting.always_show_trimmed_content = true + + user = Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust) + expect { process(:forwarded_email_to_category) }.to change{Topic.count}.by(1) # Topic created + + new_post, = Post.last + expect(new_post.raw).to include("Hi everyone, can you have a look at the email below?","···","Discoursing much today?") + end + it "works when approving is enabled" do SiteSetting.approve_unless_trust_level = 4 diff --git a/spec/fixtures/emails/forwarded_email_to_category.eml b/spec/fixtures/emails/forwarded_email_to_category.eml new file mode 100644 index 00000000000..681ebdaacf3 --- /dev/null +++ b/spec/fixtures/emails/forwarded_email_to_category.eml @@ -0,0 +1,18 @@ +Message-ID: <61@foo.bar.mail> +From: Foo Bar +To: Category +Date: Mon, 1 Dec 2016 13:37:42 +0100 +Subject: FW: Discoursing much? + +Hi everyone, can you have a look at the email below? + +From: Some One +To: Ba Bar +Date: Mon, 1 Dec 2016 00:13:37 +0100 +Subject: Discoursing much? + +Hello Ba Bar, + +Discoursing much today? + +XoXo