I am currently working on a monkey patch in the JRuby Mail-2.6.0 module. Specifically, I want to patch the ssl_context
class method. If it helps, this is the full path to the module.
An issue I am having with the monkey patch is that since I am looking to replace a class method, I am not quite sure what method to use to replace ssl_context
.
This is what I have for the monkey patch:
require 'mail/check_delivery_params'
class << Mail::SMTP
remove_method :ssl_context
end
module Mail
class SMTP
# Allow SSL context to be configured via settings, for Ruby >= 1.9
# Just returns openssl verify mode for Ruby 1.8.x
def ssl_context
openssl_verify_mode = settings[:openssl_verify_mode]
if openssl_verify_mode.kind_of?(String)
openssl_verify_mode = "OpenSSL::SSL::VERIFY_#{openssl_verify_mode.upcase}".constantize
end
# context = Net::SMTP.default_ssl_context
context = OpenSSL::SSL::SSLContext.new(settings[:ssl_version])
context.verify_mode = openssl_verify_mode
context.ca_path = settings[:ca_path] if settings[:ca_path]
context.ca_file = settings[:ca_file] if settings[:ca_file]
context
end
end
end
I am basically just trying to change:
context = Net::SMTP.default_ssl_context
To:
context = OpenSSL::SSL::SSLContext.new(settings[:ssl_version])
I've tried undef_method
, remove_class_variable
, and remove_method
, but kept getting the following type of error:
2017-05-17 11:44:03.423 -0700 [ERROR|007d0|main] :: Error starting Application: Undefined method ssl_context for 'Mail::SMTP'
org/jruby/RubyModule.java:2826:in `undef_method'
/Users/App/Code/yourtool/lib/helltool/mailer.rb:328:in `singleton class'
/Users/App/Code/yourtool//lib/helltool/mailer.rb:327:in `<main>'
org/jruby/RubyKernel.java:961:in `require'
Curious what I can do to make this work?