Skip to content

Commit a8369da

Browse files
committed
🚚 Reorder method definitions in imap.rb
To match the most common order in modern ruby projects: * Moved `attr_reader`s down below class methods. * Moved `#initialize` up above all public instance method `def`s. * Moved an method down with other public instance method `def`s. This commit should contain no other code changes.
1 parent 831df73 commit a8369da

File tree

1 file changed

+116
-116
lines changed

1 file changed

+116
-116
lines changed

lib/net/imap.rb

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -679,28 +679,6 @@ class IMAP < Protocol
679679
include SSL
680680
end
681681

682-
# Returns the initial greeting the server, an UntaggedResponse.
683-
attr_reader :greeting
684-
685-
# Seconds to wait until a connection is opened.
686-
# If the IMAP object cannot open a connection within this time,
687-
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
688-
attr_reader :open_timeout
689-
690-
# Seconds to wait until an IDLE response is received.
691-
attr_reader :idle_response_timeout
692-
693-
# The hostname this client connected to
694-
attr_reader :host
695-
696-
# The port this client connected to
697-
attr_reader :port
698-
699-
# Returns true after the TLS negotiation has completed and the remote
700-
# hostname has been verified. Returns false when TLS has been established
701-
# but peer verification was disabled.
702-
def tls_verified?; @tls_verified end
703-
704682
# Returns the debug mode.
705683
def self.debug
706684
return @@debug
@@ -727,6 +705,122 @@ class << self
727705
alias default_ssl_port default_tls_port
728706
end
729707

708+
# Returns the initial greeting the server, an UntaggedResponse.
709+
attr_reader :greeting
710+
711+
# Seconds to wait until a connection is opened.
712+
# If the IMAP object cannot open a connection within this time,
713+
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
714+
attr_reader :open_timeout
715+
716+
# Seconds to wait until an IDLE response is received.
717+
attr_reader :idle_response_timeout
718+
719+
# The hostname this client connected to
720+
attr_reader :host
721+
722+
# The port this client connected to
723+
attr_reader :port
724+
725+
# :call-seq:
726+
# Net::IMAP.new(host, options = {})
727+
#
728+
# Creates a new Net::IMAP object and connects it to the specified
729+
# +host+.
730+
#
731+
# +options+ is an option hash, each key of which is a symbol.
732+
#
733+
# The available options are:
734+
#
735+
# port:: Port number (default value is 143 for imap, or 993 for imaps)
736+
# ssl:: If +options[:ssl]+ is true, then an attempt will be made
737+
# to use SSL (now TLS) to connect to the server.
738+
# If +options[:ssl]+ is a hash, it's passed to
739+
# OpenSSL::SSL::SSLContext#set_params as parameters.
740+
# open_timeout:: Seconds to wait until a connection is opened
741+
# idle_response_timeout:: Seconds to wait until an IDLE response is received
742+
#
743+
# The most common errors are:
744+
#
745+
# Errno::ECONNREFUSED:: Connection refused by +host+ or an intervening
746+
# firewall.
747+
# Errno::ETIMEDOUT:: Connection timed out (possibly due to packets
748+
# being dropped by an intervening firewall).
749+
# Errno::ENETUNREACH:: There is no route to that network.
750+
# SocketError:: Hostname not known or other socket error.
751+
# Net::IMAP::ByeResponseError:: The connected to the host was successful, but
752+
# it immediately said goodbye.
753+
def initialize(host, port_or_options = {},
754+
usessl = false, certs = nil, verify = true)
755+
super()
756+
@host = host
757+
begin
758+
options = port_or_options.to_hash
759+
rescue NoMethodError
760+
# for backward compatibility
761+
options = {}
762+
options[:port] = port_or_options
763+
if usessl
764+
options[:ssl] = create_ssl_params(certs, verify)
765+
end
766+
end
767+
@port = options[:port] || (options[:ssl] ? SSL_PORT : PORT)
768+
@tag_prefix = "RUBY"
769+
@tagno = 0
770+
@utf8_strings = false
771+
@open_timeout = options[:open_timeout] || 30
772+
@idle_response_timeout = options[:idle_response_timeout] || 5
773+
@tls_verified = false
774+
@parser = ResponseParser.new
775+
@sock = tcp_socket(@host, @port)
776+
begin
777+
if options[:ssl]
778+
start_tls_session(options[:ssl])
779+
@usessl = true
780+
else
781+
@usessl = false
782+
end
783+
@responses = Hash.new {|h, k| h[k] = [] }
784+
@tagged_responses = {}
785+
@response_handlers = []
786+
@tagged_response_arrival = new_cond
787+
@continued_command_tag = nil
788+
@continuation_request_arrival = new_cond
789+
@continuation_request_exception = nil
790+
@idle_done_cond = nil
791+
@logout_command_tag = nil
792+
@debug_output_bol = true
793+
@exception = nil
794+
795+
@greeting = get_response
796+
if @greeting.nil?
797+
raise Error, "connection closed"
798+
end
799+
record_untagged_response_code @greeting
800+
@capabilities = capabilities_from_resp_code @greeting
801+
if @greeting.name == "BYE"
802+
raise ByeResponseError, @greeting
803+
end
804+
805+
@client_thread = Thread.current
806+
@receiver_thread = Thread.start {
807+
begin
808+
receive_responses
809+
rescue Exception
810+
end
811+
}
812+
@receiver_thread_terminating = false
813+
rescue Exception
814+
@sock.close
815+
raise
816+
end
817+
end
818+
819+
# Returns true after the TLS negotiation has completed and the remote
820+
# hostname has been verified. Returns false when TLS has been established
821+
# but peer verification was disabled.
822+
def tls_verified?; @tls_verified end
823+
730824
def client_thread # :nodoc:
731825
warn "Net::IMAP#client_thread is deprecated and will be removed soon."
732826
@client_thread
@@ -2218,100 +2312,6 @@ def remove_response_handler(handler)
22182312

22192313
@@debug = false
22202314

2221-
# :call-seq:
2222-
# Net::IMAP.new(host, options = {})
2223-
#
2224-
# Creates a new Net::IMAP object and connects it to the specified
2225-
# +host+.
2226-
#
2227-
# +options+ is an option hash, each key of which is a symbol.
2228-
#
2229-
# The available options are:
2230-
#
2231-
# port:: Port number (default value is 143 for imap, or 993 for imaps)
2232-
# ssl:: If +options[:ssl]+ is true, then an attempt will be made
2233-
# to use SSL (now TLS) to connect to the server.
2234-
# If +options[:ssl]+ is a hash, it's passed to
2235-
# OpenSSL::SSL::SSLContext#set_params as parameters.
2236-
# open_timeout:: Seconds to wait until a connection is opened
2237-
# idle_response_timeout:: Seconds to wait until an IDLE response is received
2238-
#
2239-
# The most common errors are:
2240-
#
2241-
# Errno::ECONNREFUSED:: Connection refused by +host+ or an intervening
2242-
# firewall.
2243-
# Errno::ETIMEDOUT:: Connection timed out (possibly due to packets
2244-
# being dropped by an intervening firewall).
2245-
# Errno::ENETUNREACH:: There is no route to that network.
2246-
# SocketError:: Hostname not known or other socket error.
2247-
# Net::IMAP::ByeResponseError:: The connected to the host was successful, but
2248-
# it immediately said goodbye.
2249-
def initialize(host, port_or_options = {},
2250-
usessl = false, certs = nil, verify = true)
2251-
super()
2252-
@host = host
2253-
begin
2254-
options = port_or_options.to_hash
2255-
rescue NoMethodError
2256-
# for backward compatibility
2257-
options = {}
2258-
options[:port] = port_or_options
2259-
if usessl
2260-
options[:ssl] = create_ssl_params(certs, verify)
2261-
end
2262-
end
2263-
@port = options[:port] || (options[:ssl] ? SSL_PORT : PORT)
2264-
@tag_prefix = "RUBY"
2265-
@tagno = 0
2266-
@utf8_strings = false
2267-
@open_timeout = options[:open_timeout] || 30
2268-
@idle_response_timeout = options[:idle_response_timeout] || 5
2269-
@tls_verified = false
2270-
@parser = ResponseParser.new
2271-
@sock = tcp_socket(@host, @port)
2272-
begin
2273-
if options[:ssl]
2274-
start_tls_session(options[:ssl])
2275-
@usessl = true
2276-
else
2277-
@usessl = false
2278-
end
2279-
@responses = Hash.new {|h, k| h[k] = [] }
2280-
@tagged_responses = {}
2281-
@response_handlers = []
2282-
@tagged_response_arrival = new_cond
2283-
@continued_command_tag = nil
2284-
@continuation_request_arrival = new_cond
2285-
@continuation_request_exception = nil
2286-
@idle_done_cond = nil
2287-
@logout_command_tag = nil
2288-
@debug_output_bol = true
2289-
@exception = nil
2290-
2291-
@greeting = get_response
2292-
if @greeting.nil?
2293-
raise Error, "connection closed"
2294-
end
2295-
record_untagged_response_code @greeting
2296-
@capabilities = capabilities_from_resp_code @greeting
2297-
if @greeting.name == "BYE"
2298-
raise ByeResponseError, @greeting
2299-
end
2300-
2301-
@client_thread = Thread.current
2302-
@receiver_thread = Thread.start {
2303-
begin
2304-
receive_responses
2305-
rescue Exception
2306-
end
2307-
}
2308-
@receiver_thread_terminating = false
2309-
rescue Exception
2310-
@sock.close
2311-
raise
2312-
end
2313-
end
2314-
23152315
def tcp_socket(host, port)
23162316
s = Socket.tcp(host, port, :connect_timeout => @open_timeout)
23172317
s.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, true)

0 commit comments

Comments
 (0)