@@ -229,6 +229,9 @@ class IMAP < Protocol
229
229
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
230
230
attr_reader :open_timeout
231
231
232
+ # Seconds to wait until an IDLE response is received.
233
+ attr_reader :idle_response_timeout
234
+
232
235
# The thread to receive exceptions.
233
236
attr_accessor :client_thread
234
237
@@ -1056,7 +1059,7 @@ def idle(timeout = nil, &response_handler)
1056
1059
unless @receiver_thread_terminating
1057
1060
remove_response_handler ( response_handler )
1058
1061
put_string ( "DONE#{ CRLF } " )
1059
- response = get_tagged_response ( tag , "IDLE" )
1062
+ response = get_tagged_response ( tag , "IDLE" , @idle_response_timeout )
1060
1063
end
1061
1064
end
1062
1065
end
@@ -1142,6 +1145,7 @@ def self.format_datetime(time)
1142
1145
# If options[:ssl] is a hash, it's passed to
1143
1146
# OpenSSL::SSL::SSLContext#set_params as parameters.
1144
1147
# open_timeout:: Seconds to wait until a connection is opened
1148
+ # idle_response_timeout:: Seconds to wait until an IDLE response is received
1145
1149
#
1146
1150
# The most common errors are:
1147
1151
#
@@ -1171,6 +1175,7 @@ def initialize(host, port_or_options = {},
1171
1175
@tag_prefix = "RUBY"
1172
1176
@tagno = 0
1173
1177
@open_timeout = options [ :open_timeout ] || 30
1178
+ @idle_response_timeout = options [ :idle_response_timeout ] || 5
1174
1179
@parser = ResponseParser . new
1175
1180
@sock = tcp_socket ( @host , @port )
1176
1181
begin
@@ -1294,10 +1299,19 @@ def receive_responses
1294
1299
end
1295
1300
end
1296
1301
1297
- def get_tagged_response ( tag , cmd )
1302
+ def get_tagged_response ( tag , cmd , timeout = nil )
1303
+ if timeout
1304
+ deadline = Time . now + timeout
1305
+ end
1298
1306
until @tagged_responses . key? ( tag )
1299
1307
raise @exception if @exception
1300
- @tagged_response_arrival . wait
1308
+ if timeout
1309
+ timeout = deadline - Time . now
1310
+ if timeout <= 0
1311
+ return nil
1312
+ end
1313
+ end
1314
+ @tagged_response_arrival . wait ( timeout )
1301
1315
end
1302
1316
resp = @tagged_responses . delete ( tag )
1303
1317
case resp . name
0 commit comments