@@ -2494,37 +2494,78 @@ def idle_done
2494
2494
# responses {|hash| ...} -> block result
2495
2495
# responses(type) {|array| ...} -> block result
2496
2496
#
2497
- # Yields unhandled responses and returns the result of the block.
2498
- #
2497
+ # Yields unhandled server responses and returns the result of the block.
2499
2498
# Unhandled responses are stored in a hash, with arrays of
2500
2499
# <em>non-+nil+</em> UntaggedResponse#data keyed by UntaggedResponse#name
2501
- # and ResponseCode#data keyed by ResponseCode#name. Call without +type+ to
2502
- # yield the entire responses hash. Call with +type+ to yield only the array
2503
- # of responses for that type.
2500
+ # and ResponseCode#data keyed by ResponseCode#name.
2501
+ #
2502
+ # [With +type+]
2503
+ # Yield only the array of responses for that +type+.
2504
+ # When no block is given, an +ArgumentError+ is raised.
2505
+ # [Without +type+]
2506
+ # Yield or return the entire responses hash.
2507
+ #
2508
+ # When no block is given, the behavior is determined by
2509
+ # Config#responses_without_block:
2510
+ # >>>
2511
+ # [+:silence_deprecation_warning+ <em>(original behavior)</em>]
2512
+ # Returns the mutable responses hash (without any warnings).
2513
+ # <em>This is not thread-safe.</em>
2514
+ #
2515
+ # [+:warn+ <em>(default since +v0.5+)</em>]
2516
+ # Prints a warning and returns the mutable responses hash.
2517
+ # <em>This is not thread-safe.</em>
2518
+ #
2519
+ # [+:raise+ <em>(planned future default)</em>]
2520
+ # Raise an +ArgumentError+ with the deprecation warning.
2504
2521
#
2505
2522
# For example:
2506
2523
#
2507
2524
# imap.select("inbox")
2508
2525
# p imap.responses("EXISTS", &:last)
2509
2526
# #=> 2
2527
+ # p imap.responses("UIDNEXT", &:last)
2528
+ # #=> 123456
2510
2529
# p imap.responses("UIDVALIDITY", &:last)
2511
2530
# #=> 968263756
2531
+ # p imap.responses {|responses|
2532
+ # {
2533
+ # exists: responses.delete("EXISTS").last,
2534
+ # uidnext: responses.delete("UIDNEXT").last,
2535
+ # uidvalidity: responses.delete("UIDVALIDITY").last,
2536
+ # }
2537
+ # }
2538
+ # #=> {:exists=>2, :uidnext=>123456, :uidvalidity=>968263756}
2539
+ # # "EXISTS", "UIDNEXT", and "UIDVALIDITY" have been removed:
2540
+ # p imap.responses(&:keys)
2541
+ # #=> ["FLAGS", "OK", "PERMANENTFLAGS", "RECENT", "HIGHESTMODSEQ"]
2512
2542
#
2543
+ # Related: #extract_responses, #clear_responses, #response_handlers, #greeting
2544
+ #
2545
+ # ===== Thread safety
2513
2546
# >>>
2514
2547
# *Note:* Access to the responses hash is synchronized for thread-safety.
2515
2548
# The receiver thread and response_handlers cannot process new responses
2516
2549
# until the block completes. Accessing either the response hash or its
2517
- # response type arrays outside of the block is unsafe.
2550
+ # response type arrays outside of the block is unsafe. They can be safely
2551
+ # updated inside the block. Consider using #clear_responses or
2552
+ # #extract_responses instead.
2553
+ #
2554
+ # Net::IMAP will add and remove responses from the responses hash and its
2555
+ # array values, in the calling threads for commands and in the receiver
2556
+ # thread, but will not modify any responses after adding them to the
2557
+ # responses hash.
2518
2558
#
2519
- # Calling without a block is unsafe and deprecated. Future releases will
2520
- # raise ArgumentError unless a block is given.
2521
- # See Config#responses_without_block.
2559
+ # ===== Clearing responses
2522
2560
#
2523
2561
# Previously unhandled responses are automatically cleared before entering a
2524
2562
# mailbox with #select or #examine. Long-lived connections can receive many
2525
2563
# unhandled server responses, which must be pruned or they will continually
2526
2564
# consume more memory. Update or clear the responses hash or arrays inside
2527
- # the block, or use #clear_responses.
2565
+ # the block, or remove responses with #extract_responses, #clear_responses,
2566
+ # or #add_response_handler.
2567
+ #
2568
+ # ===== Missing responses
2528
2569
#
2529
2570
# Only non-+nil+ data is stored. Many important response codes have no data
2530
2571
# of their own, but are used as "tags" on the ResponseText object they are
@@ -2535,8 +2576,6 @@ def idle_done
2535
2576
# ResponseCode#data on tagged responses. Although some command methods do
2536
2577
# return the TaggedResponse directly, #add_response_handler must be used to
2537
2578
# handle all response codes.
2538
- #
2539
- # Related: #extract_responses, #clear_responses, #response_handlers, #greeting
2540
2579
def responses ( type = nil )
2541
2580
if block_given?
2542
2581
synchronize { yield ( type ? @responses [ type . to_s . upcase ] : @responses ) }
0 commit comments