From fc1d155bd1b31ad75e6bc9785121849a677bf289 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Thu, 27 Aug 2026 23:54:30 +0300 Subject: [PATCH 1/2] Preserve caller SSL context options when starting SMTP --- lib/net/smtp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index cca06e6..ecaf480 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -626,7 +626,7 @@ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil secret ||= password || args[2] authtype ||= args[3] if defined?(OpenSSL::VERSION) - ssl_context_params = @ssl_context_params || {} + ssl_context_params = @ssl_context_params&.dup || {} unless ssl_context_params.has_key?(:verify_mode) ssl_context_params[:verify_mode] = @tls_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE end From 1b7e49aeff7de1d948af9b6e0922d9be2fe246da Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:24:15 +0300 Subject: [PATCH 2/2] Add regression coverage for preserve caller ssl context options when starting smtp --- test/net/smtp/test_sslcontext.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/net/smtp/test_sslcontext.rb b/test/net/smtp/test_sslcontext.rb index 7563d60..fa279da 100644 --- a/test/net/smtp/test_sslcontext.rb +++ b/test/net/smtp/test_sslcontext.rb @@ -222,5 +222,16 @@ def test_ssl_context_params_after_initialize smtp.start assert_equal(123, smtp.__ssl_context.timeout) end + + def test_frozen_ssl_context_params + params = {}.freeze + smtp = SMTP.new("example.invalid", starttls: false) + smtp.ssl_context_params = params + smtp.define_singleton_method(:do_start) { |*| @started = true } + smtp.define_singleton_method(:do_finish) { @started = false } + + assert_equal :started, smtp.start { :started } + assert_equal({}, params) + end end end