From 453bec9394d260f38a6ec90ac0dfe5af3c9b0ff0 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 11 Feb 2020 15:48:58 +0100 Subject: [PATCH] FEATURE: Add small action post to indicate forwarded email This happens only when the sender of the email didn't write anything in their email. --- config/locales/client.en.yml | 1 + lib/email/receiver.rb | 4 +++- spec/components/email/receiver_spec.rb | 12 ++++++++++++ spec/fixtures/emails/forwarded_email_4.eml | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/emails/forwarded_email_4.eml diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f8bb80d9779..8c36aa47dda 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -184,6 +184,7 @@ en: banner: enabled: "made this a banner %{when}. It will appear at the top of every page until it is dismissed by the user." disabled: "removed this banner %{when}. It will no longer appear at the top of every page." + forwarded: "forwarded the above email" topic_admin_menu: "topic actions" diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index a66c8cf0302..69f7ccf2704 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -844,7 +844,7 @@ module Email embedded_user: lambda { find_or_create_user(email, display_name) }) return false unless post - if post&.topic + if post.topic # mark post as seen for the forwarder PostTiming.record_timing(user_id: user.id, topic_id: post.topic_id, post_number: post.post_number, msecs: 5000) @@ -859,6 +859,8 @@ module Email topic: post.topic, post_type: post_type, skip_validations: user.staged?) + else + post.topic.add_small_action(user, "forwarded") end end diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index ca7b9257a6e..a7dd5e6b71c 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -888,6 +888,18 @@ describe Email::Receiver do expect { process(:forwarded_email_3) }.to change(Topic, :count) end + it "adds a small action post to explain who forwarded the email when the sender didn't write anything" do + expect { process(:forwarded_email_4) }.to change(Topic, :count) + + forwarded_post, last_post = *Post.last(2) + + expect(forwarded_post.user.email).to eq("some@one.com") + expect(forwarded_post.raw).to match(/XoXo/) + + expect(last_post.user.email).to eq("ba@bar.com") + expect(last_post.post_type).to eq(Post.types[:small_action]) + expect(last_post.action_code).to eq("forwarded") + end end context "with forwarded emails behaviour set to quote" do diff --git a/spec/fixtures/emails/forwarded_email_4.eml b/spec/fixtures/emails/forwarded_email_4.eml new file mode 100644 index 00000000000..c50c1d129a1 --- /dev/null +++ b/spec/fixtures/emails/forwarded_email_4.eml @@ -0,0 +1,17 @@ +Message-ID: <62@foo.bar.mail> +From: Ba Bar +To: Team +Date: Mon, 1 Dec 2016 13:37:42 +0100 +Subject: Fwd: Discoursing much? + +---------- Forwarded message --------- +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