module Net::IMAP::DeprecatedClientOptions
def create_ssl_params(certs = nil, verify = true)
def create_ssl_params(certs = nil, verify = true) params = {} if certs if File.file?(certs) params[:ca_file] = certs elsif File.directory?(certs) params[:ca_path] = certs end end params[:verify_mode] = verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE params end
def initialize(host, port_or_options = nil, *deprecated, **options)
Net::IMAP.new("imap.example.com", ssl: {verify_mode: OpenSSL::SSL::VERIFY_NONE})
# Use instead:
Net::IMAP.new("imap.example.com", nil, true, nil, false) # => prints a warning
# DEPRECATED:
OpenSSL::SSL::VERIFY_NONE.
When +verify+ is +false+, it is converted to verify_mode:
Net::IMAP.new("imap.example.com", ssl: {ca_file: "/path/to/cert.pem"})
# Use instead:
Net::IMAP.new("imap.example.com", nil, true, "/path/to/cert.pem") # => prints a warning
# DEPRECATED:
certs.
When +certs+ is a path to a file, it is converted to ca_file:
Net::IMAP.new("imap.example.com", ssl: {ca_path: "/path/to/certs"})
# Use instead:
Net::IMAP.new("imap.example.com", nil, true, "/path/to/certs") # => prints a warning
# DEPRECATED:
certs.
When +certs+ is a path to a directory, it is converted to ca_path:
Net::IMAP.new("imap.example.com", ssl: true)
# Use instead:
Net::IMAP.new("imap.example.com", nil, true) # => prints a warning
# DEPRECATED:
Without +certs+ or +verify+, it is converted to ssl: true.
all three arguments are converted to the +ssl+ keyword argument.
If +usessl+ is false, +certs+, and +verify+ are ignored. When it true,
a future release.
arguments to avoid the warning. Deprecated arguments will be removed in
Using deprecated arguments prints a warning. Convert to keyword
==== Deprecated arguments
Net::IMAP.new("imap.example.com", port: 114433)
# Use instead:
Net::IMAP.new("imap.example.com", 114433)
# Obsolete:
converted to the +port+ keyword argument.
If a second positional argument is given and it is not a hash, it is
Net::IMAP.new("imap.example.com", **options_hash)
# Use instead:
Net::IMAP.new("imap.example.com", options_hash)
# Obsolete:
convertable via +#to_hash+), it is converted to keyword arguments.
If a second positional argument is given and it is a hash (or is
deprecated by a future release.
Using obsolete arguments does not a warning. Obsolete arguments will be
==== Obsolete arguments
Translates Net::IMAP.new arguments for backward compatibility.
Net::IMAP.new(host, port, usessl, certs = nil, verify = true) # deprecated SSL arguments
Net::IMAP.new(host, port) # obsolete port argument
Net::IMAP.new(host, options) # obsolete hash options
Net::IMAP.new(host, **options) # standard keyword options
:call-seq:
def initialize(host, port_or_options = nil, *deprecated, **options) if port_or_options.nil? && deprecated.empty? super host, **options elsif options.any? # Net::IMAP.new(host, *__invalid__, **options) raise ArgumentError, "Do not combine deprecated and keyword arguments" elsif port_or_options.respond_to?(:to_hash) and deprecated.any? # Net::IMAP.new(host, options, *__invalid__) raise ArgumentError, "Do not use deprecated SSL params with options hash" elsif port_or_options.respond_to?(:to_hash) super host, **Hash.try_convert(port_or_options) elsif deprecated.empty? super host, port: port_or_options elsif deprecated.shift warn "DEPRECATED: Call Net::IMAP.new with keyword options", uplevel: 1 super host, port: port_or_options, ssl: create_ssl_params(*deprecated) else warn "DEPRECATED: Call Net::IMAP.new with keyword options", uplevel: 1 super host, port: port_or_options, ssl: false end end
def starttls(*deprecated, **options)
Support for +certs+ and +verify+ will be dropped in a future release.
Translates Net::IMAP#starttls arguments for backward compatibility.
starttls(certs = nil, verify = true) # deprecated
starttls(options = {}) # obsolete
starttls(**options) # standard
:call-seq:
def starttls(*deprecated, **options) if deprecated.empty? super(**options) elsif options.any? # starttls(*__invalid__, **options) raise ArgumentError, "Do not combine deprecated and keyword options" elsif deprecated.first.respond_to?(:to_hash) && deprecated.length > 1 # starttls(*__invalid__, **options) raise ArgumentError, "Do not use deprecated verify param with options hash" elsif deprecated.first.respond_to?(:to_hash) super(**Hash.try_convert(deprecated.first)) else warn "DEPRECATED: Call Net::IMAP#starttls with keyword options", uplevel: 1 super(**create_ssl_params(*deprecated)) end end