From 9feba112a704edc23b4c2240a546363f9e1158b1 Mon Sep 17 00:00:00 2001 From: F Date: Thu, 10 Nov 2022 20:06:21 +0000 Subject: Make enable_starttls configurable by envvars (#20321) ENABLE_STARTTLS is designed to replace ENABLE_STARTTLS_AUTO by accepting three values: 'auto' (the default), 'always', and 'never'. If ENABLE_STARTTLS isn't provided, we fall back to ENABLE_STARTTLS_AUTO. In this way, this change should be fully backwards compatible. Resolves #20311 --- config/environments/production.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'config/environments') diff --git a/config/environments/production.rb b/config/environments/production.rb index f41a0f197..48b134949 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -101,6 +101,20 @@ Rails.application.configure do config.action_mailer.default_options[:reply_to] = ENV['SMTP_REPLY_TO'] if ENV['SMTP_REPLY_TO'].present? config.action_mailer.default_options[:return_path] = ENV['SMTP_RETURN_PATH'] if ENV['SMTP_RETURN_PATH'].present? + enable_starttls = nil + enable_starttls_auto = nil + + case env['SMTP_ENABLE_STARTTLS'] + when 'always' + enable_starttls = true + when 'never' + enable_starttls = false + when 'auto' + enable_starttls_auto = true + else + enable_starttls_auto = ENV['SMTP_ENABLE_STARTTLS_AUTO'] != 'false' + end + config.action_mailer.smtp_settings = { :port => ENV['SMTP_PORT'], :address => ENV['SMTP_SERVER'], @@ -110,7 +124,8 @@ Rails.application.configure do :authentication => ENV['SMTP_AUTH_METHOD'] == 'none' ? nil : ENV['SMTP_AUTH_METHOD'] || :plain, :ca_file => ENV['SMTP_CA_FILE'].presence || '/etc/ssl/certs/ca-certificates.crt', :openssl_verify_mode => ENV['SMTP_OPENSSL_VERIFY_MODE'], - :enable_starttls_auto => ENV['SMTP_ENABLE_STARTTLS_AUTO'] != 'false', + :enable_starttls => enable_starttls, + :enable_starttls_auto => enable_starttls_auto, :tls => ENV['SMTP_TLS'].presence && ENV['SMTP_TLS'] == 'true', :ssl => ENV['SMTP_SSL'].presence && ENV['SMTP_SSL'] == 'true', } -- cgit From 19a8563905cf613bb24e10e4e19bdbc1d0ff3b8a Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Fri, 11 Nov 2022 09:33:32 +0900 Subject: Fix `ENV` (#20377) --- config/environments/production.rb | 2 +- lib/tasks/mastodon.rake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'config/environments') diff --git a/config/environments/production.rb b/config/environments/production.rb index 48b134949..dc5319535 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -104,7 +104,7 @@ Rails.application.configure do enable_starttls = nil enable_starttls_auto = nil - case env['SMTP_ENABLE_STARTTLS'] + case ENV['SMTP_ENABLE_STARTTLS'] when 'always' enable_starttls = true when 'never' diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 76089ebac..3ec685c74 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -326,7 +326,7 @@ namespace :mastodon do when 'auto' enable_starttls_auto = true else - enable_starttls_auto = ENV['SMTP_ENABLE_STARTTLS_AUTO'] != 'false' + enable_starttls_auto = env['SMTP_ENABLE_STARTTLS_AUTO'] != 'false' end ActionMailer::Base.smtp_settings = { -- cgit