@@ -43,10 +43,16 @@ module Net
4343 # To work on the messages within a mailbox, the client must
4444 # first select that mailbox, using either #select or #examine
4545 # (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
4747 # mailbox becomes the _current_ mailbox, on which mail-item
4848 # related commands implicitly operate.
4949 #
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+ #
5056 # === Sequence numbers and UIDs
5157 #
5258 # Messages have two sorts of identifiers: message sequence
@@ -199,6 +205,37 @@ module Net
199205 #
200206 # This script invokes the FETCH command and the SEARCH command concurrently.
201207 #
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+ #
202239 # == Errors
203240 #
204241 # An \IMAP server can send three different types of responses to indicate
@@ -260,8 +297,9 @@ module Net
260297 #
261298 # - Net::IMAP.new: Creates a new \IMAP client which connects immediately and
262299 # waits for a successful server greeting before the method returns.
300+ # - #connection_state: Returns the connection state.
263301 # - #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.
265303 # - #disconnect: Disconnects the connection (without sending #logout first).
266304 # - #disconnected?: True if the connection has been closed.
267305 #
@@ -317,37 +355,36 @@ module Net
317355 # <em>In general, #capable? should be used rather than explicitly sending a
318356 # +CAPABILITY+ command to the server.</em>
319357 # - #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.
321359 #
322360 # ==== Not Authenticated state
323361 #
324362 # 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:
326364 #
327365 # - #starttls: Upgrades a clear-text connection to use TLS.
328366 #
329367 # <em>Requires the +STARTTLS+ capability.</em>
330368 # - #authenticate: Identifies the client to the server using the given
331369 # {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.
333371 #
334372 # <em>The server should list <tt>"AUTH=#{mechanism}"</tt> capabilities for
335373 # supported mechanisms.</em>
336374 # - #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.
339376 #
340377 # <em>The +LOGINDISABLED+ capability</em> <b>must NOT</b> <em>be listed.</em>
341378 #
342379 # ==== Authenticated state
343380 #
344381 # In addition to the commands for any state, the following commands are valid
345- # in the "_authenticated_" state:
382+ # in the +authenticated+ state:
346383 #
347384 # - #enable: Enables backwards incompatible server extensions.
348385 # <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.
351388 # - #create: Creates a new mailbox.
352389 # - #delete: Permanently remove a mailbox.
353390 # - #rename: Change the name of a mailbox.
@@ -369,12 +406,12 @@ module Net
369406 #
370407 # ==== Selected state
371408 #
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:
374411 #
375- # - #close: Closes the mailbox and returns to the "_authenticated_" state,
412+ # - #close: Closes the mailbox and returns to the +authenticated+ state,
376413 # 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,
378415 # without expunging any messages.
379416 # <em>Requires the +UNSELECT+ or +IMAP4rev2+ capability.</em>
380417 # - #expunge: Permanently removes messages which have the Deleted flag set.
@@ -395,7 +432,7 @@ module Net
395432 #
396433 # ==== Logout state
397434 #
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
399436 # open, Net::IMAP will close it after receiving server confirmation.
400437 # Exceptions will be raised by \IMAP commands that have already started and
401438 # are waiting for a response, as well as any that are called after logout.
@@ -449,7 +486,7 @@ module Net
449486 # ==== RFC3691: +UNSELECT+
450487 # Folded into IMAP4rev2[https://tools.ietf.org/html/rfc9051] and also included
451488 # 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,
453490 # without expunging any messages.
454491 #
455492 # ==== RFC4314: +ACL+
@@ -741,9 +778,11 @@ class IMAP < Protocol
741778 def self . config ; Config . global end
742779
743780 # Returns the global debug mode.
781+ # Delegates to {Net::IMAP.config.debug}[rdoc-ref:Config#debug].
744782 def self . debug ; config . debug end
745783
746784 # Sets the global debug mode.
785+ # Delegates to {Net::IMAP.config.debug=}[rdoc-ref:Config#debug=].
747786 def self . debug = ( val )
748787 config . debug = val
749788 end
@@ -764,7 +803,7 @@ class << self
764803 alias default_ssl_port default_tls_port
765804 end
766805
767- # Returns the initial greeting the server, an UntaggedResponse.
806+ # Returns the initial greeting sent by the server, an UntaggedResponse.
768807 attr_reader :greeting
769808
770809 # The client configuration. See Net::IMAP::Config.
@@ -773,13 +812,20 @@ class << self
773812 # Net::IMAP.config.
774813 attr_reader :config
775814
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].
780819
820+ ##
821+ # :attr_reader: idle_response_timeout
781822 # 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:
783829
784830 # The hostname this client connected to
785831 attr_reader :host
@@ -1204,6 +1250,10 @@ def logout!
12041250 # both successful. Any error indicates that the connection has not been
12051251 # secured.
12061252 #
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+ #
12071257 # *Note:*
12081258 # >>>
12091259 # Any #response_handlers added before STARTTLS should be aware that the
0 commit comments