Skip to content

Commit 06677aa

Browse files
committed
🔧 Add client config (currently unused)
An (unused) client config object has been added to both Net::IMAP and to ResponseParser. Every client creates its own config object. By default, the client config inherits from the global config. Unlike the client, which always creates a new Config object, the parser simply shares the client's config.
1 parent 716804f commit 06677aa

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

lib/net/imap.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ class << self
769769
# Returns the initial greeting the server, an UntaggedResponse.
770770
attr_reader :greeting
771771

772+
# The client configuration. See Net::IMAP::Config.
773+
#
774+
# By default, config inherits from the global Net::IMAP.config.
775+
attr_reader :config
776+
772777
# Seconds to wait until a connection is opened.
773778
# If the IMAP object cannot open a connection within this time,
774779
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
@@ -816,11 +821,20 @@ class << self
816821
# the keys are names of attribute assignment methods on
817822
# SSLContext[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html].
818823
#
824+
# [config]
825+
# A Net::IMAP::Config object to base the client #config on. By default
826+
# the global Net::IMAP.config is used. Note that this sets the _parent_
827+
# config object for inheritance. Every Net::IMAP client has its own
828+
# unique #config for overrides.
829+
#
819830
# [open_timeout]
820831
# Seconds to wait until a connection is opened
821832
# [idle_response_timeout]
822833
# Seconds to wait until an IDLE response is received
823834
#
835+
# Any other keyword arguments will be forwarded to Config.new, to create the
836+
# client's #config.
837+
#
824838
# See DeprecatedClientOptions.new for deprecated arguments.
825839
#
826840
# ==== Examples
@@ -877,10 +891,12 @@ class << self
877891
# Connected to the host successfully, but it immediately said goodbye.
878892
#
879893
def initialize(host, port: nil, ssl: nil,
880-
open_timeout: 30, idle_response_timeout: 5)
894+
open_timeout: 30, idle_response_timeout: 5,
895+
config: Config.global, **config_options)
881896
super()
882897
# Config options
883898
@host = host
899+
@config = Config.new(config, **config_options)
884900
@port = port || (ssl ? SSL_PORT : PORT)
885901
@open_timeout = Integer(open_timeout)
886902
@idle_response_timeout = Integer(idle_response_timeout)
@@ -894,7 +910,7 @@ def initialize(host, port: nil, ssl: nil,
894910
@capabilities = nil
895911

896912
# Client Protocol Receiver
897-
@parser = ResponseParser.new
913+
@parser = ResponseParser.new(config: @config)
898914
@responses = Hash.new {|h, k| h[k] = [] }
899915
@response_handlers = []
900916
@receiver_thread = nil

lib/net/imap/config.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class IMAP
1010

1111
# Net::IMAP::Config stores configuration options for Net::IMAP clients.
1212
# The global configuration can be seen at either Net::IMAP.config or
13-
# Net::IMAP::Config.global.
13+
# Net::IMAP::Config.global, and the client-specific configuration can be
14+
# seen at Net::IMAP#config. When creating a new client, all unhandled
15+
# keyword arguments to Net::IMAP.new are delegated to Config.new. Every
16+
# client has its own config.
1417
#
1518
# ## Inheritance
1619
#
1720
# Configs have a parent[rdoc-ref:Config::AttrInheritance#parent] config, and
1821
# any attributes which have not been set locally will inherit the parent's
19-
# value. Config.global inherits from Config.default.
22+
# value. Every client creates its own specific config. By default, client
23+
# configs inherit from Config.global which inherits from Config.default.
2024
#
2125
# See the following methods, defined by Config::AttrInheritance:
2226
# - {#new}[rdoc-ref:Config::AttrInheritance#reset] -- create a new config

lib/net/imap/response_parser.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ class ResponseParser
1111
include ParserUtils
1212
extend ParserUtils::Generator
1313

14+
attr_reader :config
15+
1416
# :call-seq: Net::IMAP::ResponseParser.new -> Net::IMAP::ResponseParser
15-
def initialize
17+
def initialize(config: Config.global)
1618
@str = nil
1719
@pos = nil
1820
@lex_state = nil
1921
@token = nil
22+
@config = Config[config]
2023
end
2124

2225
# :call-seq:

0 commit comments

Comments
 (0)