Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: automatic PM when a user's email is revoked

Régis Hanolac2513b0f289
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index cc10f8c9cb8..8be2b79ee4c 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2593,6 +2593,15 @@ en:
Please make sure you have properly configured the POP credentials in [the site settings](%{base_url}/admin/site_settings/category/email).
If there is a web UI for the POP email account, you may need to log in on the web and check your settings there.
+
+ email_revoked:
+ title: "Email Revoked"
+ subject_template: "[%{email_prefix}] Is your email address correct?"
+ text_body_template: |
+ We're sorry, but we're having trouble reaching you via email.
+
+ Can you make sure [your email address](%{base_url}/my/preferences/email) is a valid and working email address?
+
too_many_spam_flags:
title: "Too Many Spam Flags"
subject_template: "New account on hold"
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index b819ef253f6..c0b7f201e13 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -232,9 +232,12 @@ module Email
reason = I18n.t("user.deactivated", email: user.email)
StaffActionLogger.new(Discourse.system_user).log_user_deactivate(user, reason)
elsif range === SiteSetting.bounce_score_threshold
- # NOTE: we check bounce_score before sending emails, nothing to do here other than log it happened.
+ # NOTE: we check bounce_score before sending emails
+ # So log we revoked the email...
reason = I18n.t("user.email.revoked", email: user.email, date: user.user_stat.reset_bounce_score_after)
StaffActionLogger.new(Discourse.system_user).log_revoke_email(user, reason)
+ # ... and PM the user
+ SystemMessage.create_from_system_user(user, :email_revoked)
end
end
end
diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb
index 3ee03ae17f9..244598ec160 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -129,6 +129,17 @@ describe Email::Receiver do
expect(email_log_2.bounced).to eq(true)
end
+ it "sends a system message once they reach the 'bounce_score_threshold'" do
+ expect(user.active).to eq(true)
+
+ user.user_stat.bounce_score = SiteSetting.bounce_score_threshold - 1
+ user.user_stat.save!
+
+ SystemMessage.expects(:create_from_system_user).with(user, :email_revoked)
+
+ expect { process(:hard_bounce_via_verp) }.to raise_error(Email::Receiver::BouncedEmailError)
+ end
+
it "automatically deactive users once they reach the 'bounce_score_threshold_deactivate' threshold" do
expect(user.active).to eq(true)