@@ -679,28 +679,6 @@ class IMAP < Protocol
679
679
include SSL
680
680
end
681
681
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
-
704
682
# Returns the debug mode.
705
683
def self . debug
706
684
return @@debug
@@ -727,6 +705,122 @@ class << self
727
705
alias default_ssl_port default_tls_port
728
706
end
729
707
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
+
730
824
def client_thread # :nodoc:
731
825
warn "Net::IMAP#client_thread is deprecated and will be removed soon."
732
826
@client_thread
@@ -2218,100 +2312,6 @@ def remove_response_handler(handler)
2218
2312
2219
2313
@@debug = false
2220
2314
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
-
2315
2315
def tcp_socket ( host , port )
2316
2316
s = Socket . tcp ( host , port , :connect_timeout => @open_timeout )
2317
2317
s . setsockopt ( :SOL_SOCKET , :SO_KEEPALIVE , true )
0 commit comments