Skip to content

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.rb
index 9af3d157322..904f83308aa 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -802,13 +802,13 @@ module Email
return 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_s
title = embedded.subject.presence || subject
case destination[:type]
when :group
group = 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 Email
return false if user.staged? && !category.email_in_allow_strangers
return 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.rb
index a834f7cd100..c288a0e8047 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -1043,7 +1043,13 @@ describe Email::Receiver do
staged_user_count = User.where(staged: true).count
User.expects(:create).never
User.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)
end
end
@@ -1159,6 +1165,24 @@ describe Email::Receiver do
context "when the email address isn't matching the one we sent the notification to" do
include_examples "does not create staged users", :reply_user_not_matching, Email::Receiver::ReplyUserNotMatchingError
end
+
+ 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
+ end
end
context "replying without key is allowed" do
diff --git a/spec/fixtures/emails/reply_and_forwarded.eml b/spec/fixtures/emails/reply_and_forwarded.eml
new file mode 100644
index 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]>
+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