A platform for community discussion. Free, open, simple.
FIX: Don't create staged users when processing forwarded email fails
Gerhard Schlager4a1755b78092
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 9af3d157322..904f83308aa 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -802,13 +802,13 @@ module Emailreturn false if email.blank? || !email["@"]- embedded_user = find_or_create_user(email, display_name)raw = try_to_encode(embedded.decoded, "UTF-8").presence || embedded.to_stitle = embedded.subject.presence || subjectcase destination[:type]when :groupgroup = destination[:obj]+ embedded_user = find_or_create_user(email, display_name)post = create_topic(user: embedded_user,raw: raw,title: title,@@ -825,6 +825,7 @@ module Emailreturn false if user.staged? && !category.email_in_allow_strangersreturn false if !user.has_trust_level?(SiteSetting.email_in_min_trust)+ embedded_user = find_or_create_user(email, display_name)post = create_topic(user: embedded_user,raw: raw,title: title,diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex a834f7cd100..c288a0e8047 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -1043,7 +1043,13 @@ describe Email::Receiver dostaged_user_count = User.where(staged: true).countUser.expects(:create).neverUser.expects(:create!).never- expect { process(email_name) }.to raise_error(expected_exception)++ if expected_exception+ expect { process(email_name) }.to raise_error(expected_exception)+ else+ process(email_name)+ end+expect(User.where(staged: true).count).to eq(staged_user_count)endend@@ -1159,6 +1165,24 @@ describe Email::Receiver docontext "when the email address isn't matching the one we sent the notification to" doinclude_examples "does not create staged users", :reply_user_not_matching, Email::Receiver::ReplyUserNotMatchingErrorend++ context "when forwarded emails are enabled" do+ before do+ SiteSetting.enable_forwarded_emails = true+ end++ context "when a reply contains a forwareded email" do+ include_examples "does not create staged users", :reply_and_forwarded+ end++ context "forwarded email to category that doesn't allow strangers" do+ before do+ category.update!(email_in: "[email protected]", email_in_allow_strangers: false)+ end++ include_examples "cleans up staged users", :forwarded_email_1, Email::Receiver::StrangersNotAllowedError+ end+ endendcontext "replying without key is allowed" dodiff --git a/spec/fixtures/emails/reply_and_forwarded.eml b/spec/fixtures/emails/reply_and_forwarded.emlnew file mode 100644index 00000000000..615cf12f176--- /dev/null+++ b/spec/fixtures/emails/reply_and_forwarded.eml@@ -0,0 +1,18 @@+Message-ID: <[email protected]>+From: Ba Bar <[email protected]>+To: [email protected]+Date: Mon, 1 Dec 2016 13:37:42 +0100+Subject: FW: Discoursing much?++@team, can you have a look at this email below?++From: Some One <[email protected]>+To: Ba Bar <[email protected]>+Date: Mon, 1 Dec 2016 00:13:37 +0100+Subject: Discoursing much?++Hello Ba Bar,++Discoursing much today?++XoXo