@@ -43,10 +43,16 @@ module Net
43
43
# To work on the messages within a mailbox, the client must
44
44
# first select that mailbox, using either #select or #examine
45
45
# (for read-only access). Once the client has successfully
46
- # selected a mailbox, they enter the "_selected_" state, and that
46
+ # selected a mailbox, they enter the +selected+ state, and that
47
47
# mailbox becomes the _current_ mailbox, on which mail-item
48
48
# related commands implicitly operate.
49
49
#
50
+ # === Connection state
51
+ #
52
+ # Once an IMAP connection is established, the connection is in one of four
53
+ # states: <tt>not authenticated</tt>, +authenticated+, +selected+, and
54
+ # +logout+. Most commands are valid only in certain states.
55
+ #
50
56
# === Sequence numbers and UIDs
51
57
#
52
58
# Messages have two sorts of identifiers: message sequence
@@ -199,6 +205,37 @@ module Net
199
205
#
200
206
# This script invokes the FETCH command and the SEARCH command concurrently.
201
207
#
208
+ # When running multiple commands, care must be taken to avoid ambiguity. For
209
+ # example, SEARCH responses are ambiguous about which command they are
210
+ # responding to, so search commands should not run simultaneously, unless the
211
+ # server supports +ESEARCH+ {[RFC4731]}[https://rfc-editor.org/rfc/rfc4731] or
212
+ # IMAP4rev2[https://www.rfc-editor.org/rfc/rfc9051]. See {RFC9051
213
+ # §5.5}[https://www.rfc-editor.org/rfc/rfc9051.html#section-5.5] for
214
+ # other examples of command sequences which should not be pipelined.
215
+ #
216
+ # == Unbounded memory use
217
+ #
218
+ # Net::IMAP reads server responses in a separate receiver thread per client.
219
+ # Unhandled response data is saved to #responses, and response_handlers run
220
+ # inside the receiver thread. See the list of methods for {handling server
221
+ # responses}[rdoc-ref:Net::IMAP@Handling+server+responses], below.
222
+ #
223
+ # Because the receiver thread continuously reads and saves new responses, some
224
+ # scenarios must be careful to avoid unbounded memory use:
225
+ #
226
+ # * Commands such as #list or #fetch can have an enormous number of responses.
227
+ # * Commands such as #fetch can result in an enormous size per response.
228
+ # * Long-lived connections will gradually accumulate unsolicited server
229
+ # responses, especially +EXISTS+, +FETCH+, and +EXPUNGE+ responses.
230
+ # * A buggy or untrusted server could send inappropriate responses, which
231
+ # could be very numerous, very large, and very rapid.
232
+ #
233
+ # Use paginated or limited versions of commands whenever possible.
234
+ #
235
+ # Use #add_response_handler to handle responses after each one is received.
236
+ # Use #extract_responses, #clear_responses, or #responses (with a block) to
237
+ # prune responses.
238
+ #
202
239
# == Errors
203
240
#
204
241
# An \IMAP server can send three different types of responses to indicate
@@ -260,8 +297,9 @@ module Net
260
297
#
261
298
# - Net::IMAP.new: Creates a new \IMAP client which connects immediately and
262
299
# waits for a successful server greeting before the method returns.
300
+ # - #connection_state: Returns the connection state.
263
301
# - #starttls: Asks the server to upgrade a clear-text connection to use TLS.
264
- # - #logout: Tells the server to end the session. Enters the "_logout_" state.
302
+ # - #logout: Tells the server to end the session. Enters the +logout+ state.
265
303
# - #disconnect: Disconnects the connection (without sending #logout first).
266
304
# - #disconnected?: True if the connection has been closed.
267
305
#
@@ -317,37 +355,36 @@ module Net
317
355
# <em>In general, #capable? should be used rather than explicitly sending a
318
356
# +CAPABILITY+ command to the server.</em>
319
357
# - #noop: Allows the server to send unsolicited untagged #responses.
320
- # - #logout: Tells the server to end the session. Enters the "_logout_" state.
358
+ # - #logout: Tells the server to end the session. Enters the +logout+ state.
321
359
#
322
360
# ==== Not Authenticated state
323
361
#
324
362
# In addition to the commands for any state, the following commands are valid
325
- # in the "<em>not authenticated</em>" state:
363
+ # in the +not_authenticated+ state:
326
364
#
327
365
# - #starttls: Upgrades a clear-text connection to use TLS.
328
366
#
329
367
# <em>Requires the +STARTTLS+ capability.</em>
330
368
# - #authenticate: Identifies the client to the server using the given
331
369
# {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
332
- # and credentials. Enters the "_authenticated_" state.
370
+ # and credentials. Enters the +authenticated+ state.
333
371
#
334
372
# <em>The server should list <tt>"AUTH=#{mechanism}"</tt> capabilities for
335
373
# supported mechanisms.</em>
336
374
# - #login: Identifies the client to the server using a plain text password.
337
- # Using #authenticate is generally preferred. Enters the "_authenticated_"
338
- # state.
375
+ # Using #authenticate is preferred. Enters the +authenticated+ state.
339
376
#
340
377
# <em>The +LOGINDISABLED+ capability</em> <b>must NOT</b> <em>be listed.</em>
341
378
#
342
379
# ==== Authenticated state
343
380
#
344
381
# In addition to the commands for any state, the following commands are valid
345
- # in the "_authenticated_" state:
382
+ # in the +authenticated+ state:
346
383
#
347
384
# - #enable: Enables backwards incompatible server extensions.
348
385
# <em>Requires the +ENABLE+ or +IMAP4rev2+ capability.</em>
349
- # - #select: Open a mailbox and enter the "_selected_" state.
350
- # - #examine: Open a mailbox read-only, and enter the "_selected_" state.
386
+ # - #select: Open a mailbox and enter the +selected+ state.
387
+ # - #examine: Open a mailbox read-only, and enter the +selected+ state.
351
388
# - #create: Creates a new mailbox.
352
389
# - #delete: Permanently remove a mailbox.
353
390
# - #rename: Change the name of a mailbox.
@@ -369,12 +406,12 @@ module Net
369
406
#
370
407
# ==== Selected state
371
408
#
372
- # In addition to the commands for any state and the "_authenticated_"
373
- # commands, the following commands are valid in the "_selected_" state:
409
+ # In addition to the commands for any state and the +authenticated+
410
+ # commands, the following commands are valid in the +selected+ state:
374
411
#
375
- # - #close: Closes the mailbox and returns to the "_authenticated_" state,
412
+ # - #close: Closes the mailbox and returns to the +authenticated+ state,
376
413
# expunging deleted messages, unless the mailbox was opened as read-only.
377
- # - #unselect: Closes the mailbox and returns to the "_authenticated_" state,
414
+ # - #unselect: Closes the mailbox and returns to the +authenticated+ state,
378
415
# without expunging any messages.
379
416
# <em>Requires the +UNSELECT+ or +IMAP4rev2+ capability.</em>
380
417
# - #expunge: Permanently removes messages which have the Deleted flag set.
@@ -395,7 +432,7 @@ module Net
395
432
#
396
433
# ==== Logout state
397
434
#
398
- # No \IMAP commands are valid in the "_logout_" state. If the socket is still
435
+ # No \IMAP commands are valid in the +logout+ state. If the socket is still
399
436
# open, Net::IMAP will close it after receiving server confirmation.
400
437
# Exceptions will be raised by \IMAP commands that have already started and
401
438
# are waiting for a response, as well as any that are called after logout.
@@ -449,7 +486,7 @@ module Net
449
486
# ==== RFC3691: +UNSELECT+
450
487
# Folded into IMAP4rev2[https://tools.ietf.org/html/rfc9051] and also included
451
488
# above with {Core IMAP commands}[rdoc-ref:Net::IMAP@Core+IMAP+commands].
452
- # - #unselect: Closes the mailbox and returns to the "_authenticated_" state,
489
+ # - #unselect: Closes the mailbox and returns to the +authenticated+ state,
453
490
# without expunging any messages.
454
491
#
455
492
# ==== RFC4314: +ACL+
@@ -741,9 +778,11 @@ class IMAP < Protocol
741
778
def self . config ; Config . global end
742
779
743
780
# Returns the global debug mode.
781
+ # Delegates to {Net::IMAP.config.debug}[rdoc-ref:Config#debug].
744
782
def self . debug ; config . debug end
745
783
746
784
# Sets the global debug mode.
785
+ # Delegates to {Net::IMAP.config.debug=}[rdoc-ref:Config#debug=].
747
786
def self . debug = ( val )
748
787
config . debug = val
749
788
end
@@ -764,7 +803,7 @@ class << self
764
803
alias default_ssl_port default_tls_port
765
804
end
766
805
767
- # Returns the initial greeting the server, an UntaggedResponse.
806
+ # Returns the initial greeting sent by the server, an UntaggedResponse.
768
807
attr_reader :greeting
769
808
770
809
# The client configuration. See Net::IMAP::Config.
@@ -773,13 +812,20 @@ class << self
773
812
# Net::IMAP.config.
774
813
attr_reader :config
775
814
776
- # Seconds to wait until a connection is opened.
777
- # If the IMAP object cannot open a connection within this time,
778
- # it raises a Net::OpenTimeout exception. The default value is 30 seconds .
779
- def open_timeout ; config . open_timeout end
815
+ ##
816
+ # :attr_reader: open_timeout
817
+ # Seconds to wait until a connection is opened. Also used by #starttls .
818
+ # Delegates to { config.open_timeout}[rdoc-ref:Config#open_timeout].
780
819
820
+ ##
821
+ # :attr_reader: idle_response_timeout
781
822
# Seconds to wait until an IDLE response is received.
782
- def idle_response_timeout ; config . idle_response_timeout end
823
+ # Delegates to {config.idle_response_timeout}[rdoc-ref:Config#idle_response_timeout].
824
+
825
+ # :stopdoc:
826
+ def open_timeout ; config . open_timeout end
827
+ def idle_response_timeout ; config . idle_response_timeout end
828
+ # :startdoc:
783
829
784
830
# The hostname this client connected to
785
831
attr_reader :host
@@ -1204,6 +1250,10 @@ def logout!
1204
1250
# both successful. Any error indicates that the connection has not been
1205
1251
# secured.
1206
1252
#
1253
+ # After the server agrees to start a TLS connection, this method waits up to
1254
+ # {config.open_timeout}[rdoc-ref:Config#open_timeout] before raising
1255
+ # +Net::OpenTimeout+.
1256
+ #
1207
1257
# *Note:*
1208
1258
# >>>
1209
1259
# Any #response_handlers added before STARTTLS should be aware that the
0 commit comments