A platform for community discussion. Free, open, simple.
FEATURE: Warn admins when QQ Mail SMTP is configured
Jake Goldsboroughf4a7f213f091
diff --git a/app/models/problem_check.rb b/app/models/problem_check.rbindex 0e77bdc9919..2ed640146ee 100644--- a/app/models/problem_check.rb+++ b/app/models/problem_check.rb@@ -81,6 +81,7 @@ class ProblemCheckProblemCheck::OutOfDateThemes,ProblemCheck::PollPop3Timeout,ProblemCheck::PollPop3AuthError,+ ProblemCheck::QqMailSmtp,ProblemCheck::RailsEnv,ProblemCheck::Ram,ProblemCheck::S3BackupConfig,diff --git a/app/services/problem_check/qq_mail_smtp.rb b/app/services/problem_check/qq_mail_smtp.rbnew file mode 100644index 00000000000..08fba095ea5--- /dev/null+++ b/app/services/problem_check/qq_mail_smtp.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true++class ProblemCheck::QqMailSmtp < ProblemCheck+ self.priority = "low"++ def call+ smtp_address = ActionMailer::Base.smtp_settings[:address].to_s.downcase+ return no_problem if !smtp_address.match?(/\A(?:qq\.com|.+\.qq\.com)\z/)++ problem+ end++ private++ def translation_data+ { smtp_address: ActionMailer::Base.smtp_settings[:address] }+ end+enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 3f24e3c9ef3..faf39faba81 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1711,6 +1711,7 @@ en:one: "Email polling has generated an error in the past 24 hours. Look at <a href='%{base_path}/logs' target='_blank'>the logs</a> for more details."other: "Email polling has generated %{count} errors in the past 24 hours. Look at <a href='%{base_path}/logs' target='_blank'>the logs</a> for more details."missing_mailgun_api_key: "The server is configured to send emails via Mailgun but you haven't provided an API key used to verify the webhook messages."+ qq_mail_smtp: "Your SMTP server (%{smtp_address}) is known to cause duplicate emails with Discourse. QQ Mail does not return proper acknowledgments, causing Discourse to retry sends that already succeeded. <a href='https://github.com/discourse/discourse/blob/main/docs/INSTALL-email.md' target='_blank'>See recommended alternatives</a>."bad_favicon_url: "The favicon is failing to load. Check your favicon setting in <a href='%{base_path}/admin/site_settings'>Site Settings</a>."poll_pop3_timeout: "Connection to the POP3 server is timing out. Incoming email could not be retrieved. Please check your <a href='%{base_path}/admin/site_settings/category/email'>POP3 settings</a> and service provider."poll_pop3_auth_error: "Connection to the POP3 server is failing with an authentication error. Please check your <a href='%{base_path}/admin/site_settings/category/email'>POP3 settings</a>."diff --git a/spec/services/problem_check/qq_mail_smtp_spec.rb b/spec/services/problem_check/qq_mail_smtp_spec.rbnew file mode 100644index 00000000000..276ab561742--- /dev/null+++ b/spec/services/problem_check/qq_mail_smtp_spec.rb@@ -0,0 +1,47 @@+# frozen_string_literal: true++RSpec.describe ProblemCheck::QqMailSmtp do+ subject(:check) { described_class.new }++ describe ".call" do+ before { ActionMailer::Base.stubs(smtp_settings: { address: smtp_address }) }++ context "when not using QQ Mail" do+ let(:smtp_address) { "smtp.mailgun.org" }++ it { expect(check).to be_chill_about_it }+ end++ context "when using QQ Mail" do+ let(:smtp_address) { "smtp.qq.com" }++ it do+ expect(check).to have_a_problem.with_priority("low").with_message(+ "Your SMTP server (smtp.qq.com) is known to cause duplicate emails with Discourse. QQ Mail does not return proper acknowledgments, causing Discourse to retry sends that already succeeded. <a href='https://github.com/discourse/discourse/blob/main/docs/INSTALL-email.md' target='_blank'>See recommended alternatives</a>.",+ )+ end+ end++ context "when using QQ Enterprise Mail (Exmail)" do+ let(:smtp_address) { "smtp.exmail.qq.com" }++ it do+ expect(check).to have_a_problem.with_priority("low").with_message(+ "Your SMTP server (smtp.exmail.qq.com) is known to cause duplicate emails with Discourse. QQ Mail does not return proper acknowledgments, causing Discourse to retry sends that already succeeded. <a href='https://github.com/discourse/discourse/blob/main/docs/INSTALL-email.md' target='_blank'>See recommended alternatives</a>.",+ )+ end+ end++ context "when SMTP address is nil" do+ let(:smtp_address) { nil }++ it { expect(check).to be_chill_about_it }+ end++ context "when SMTP address is a suffix false positive" do+ let(:smtp_address) { "notqq.com" }++ it { expect(check).to be_chill_about_it }+ end+ end+end