@@ -2424,12 +2424,12 @@ def uid_search(...)
2424
2424
# {[RFC7162]}[https://tools.ietf.org/html/rfc7162] in order to use the
2425
2425
# +changedsince+ argument. Using +changedsince+ implicitly enables the
2426
2426
# +CONDSTORE+ extension.
2427
- def fetch ( set , attr , mod = nil , changedsince : nil )
2428
- fetch_internal ( "FETCH" , set , attr , mod , changedsince : changedsince )
2427
+ def fetch ( ... )
2428
+ fetch_internal ( "FETCH" , ... )
2429
2429
end
2430
2430
2431
2431
# :call-seq:
2432
- # uid_fetch(set, attr, changedsince: nil) -> array of FetchData
2432
+ # uid_fetch(set, attr, changedsince: nil, partial: nil ) -> array of FetchData
2433
2433
#
2434
2434
# Sends a {UID FETCH command [IMAP4rev1 §6.4.8]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8]
2435
2435
# to retrieve data associated with a message in the mailbox.
@@ -2446,13 +2446,44 @@ def fetch(set, attr, mod = nil, changedsince: nil)
2446
2446
#
2447
2447
# +changedsince+ (optional) behaves the same as with #fetch.
2448
2448
#
2449
+ # +partial+ is an optional range to limit the number of results returned.
2450
+ # It's useful when +set+ contains an unknown number of messages.
2451
+ # <tt>1..500</tt> returns the first 500 messages in +set+ (in mailbox
2452
+ # order), <tt>501..1000</tt> the second 500, and so on. +partial+ may also
2453
+ # be negative: <tt>-500..-1</tt> selects the last 500 messages in +set+.
2454
+ # <em>Requires the +PARTIAL+ capabability.</em>
2455
+ # {[RFC9394]}[https://rfc-editor.org/rfc/rfc9394]
2456
+ #
2457
+ # For example:
2458
+ #
2459
+ # # Without partial, the size of the results may be unknown beforehand:
2460
+ # results = imap.uid_fetch(next_uid_to_fetch.., %w(UID FLAGS))
2461
+ # # ... maybe wait for a long time ... and allocate a lot of memory ...
2462
+ # results.size # => 0..2**32-1
2463
+ # process results # may also take a long time and use a lot of memory...
2464
+ #
2465
+ # # Using partial, the results may be paginated:
2466
+ # loop do
2467
+ # results = imap.uid_fetch(next_uid_to_fetch.., %w(UID FLAGS),
2468
+ # partial: 1..500)
2469
+ # # fetch should return quickly and allocate little memory
2470
+ # results.size # => 0..500
2471
+ # break if results.empty?
2472
+ # next_uid_to_fetch = results.last.uid + 1
2473
+ # process results
2474
+ # end
2475
+ #
2449
2476
# Related: #fetch, FetchData
2450
2477
#
2451
2478
# ==== Capabilities
2452
2479
#
2453
- # Same as #fetch.
2454
- def uid_fetch ( set , attr , mod = nil , changedsince : nil )
2455
- fetch_internal ( "UID FETCH" , set , attr , mod , changedsince : changedsince )
2480
+ # The server's capabilities must include +PARTIAL+
2481
+ # {[RFC9394]}[https://rfc-editor.org/rfc/rfc9394] in order to use the
2482
+ # +partial+ argument.
2483
+ #
2484
+ # Otherwise, the same as #fetch.
2485
+ def uid_fetch ( ...)
2486
+ fetch_internal ( "UID FETCH" , ...)
2456
2487
end
2457
2488
2458
2489
# :call-seq:
@@ -3398,7 +3429,12 @@ def search_internal(cmd, ...)
3398
3429
end
3399
3430
end
3400
3431
3401
- def fetch_internal ( cmd , set , attr , mod = nil , changedsince : nil )
3432
+ def fetch_internal ( cmd , set , attr , mod = nil , partial : nil , changedsince : nil )
3433
+ set = SequenceSet [ set ]
3434
+ if partial
3435
+ mod ||= [ ]
3436
+ mod << "PARTIAL" << PartialRange [ partial ]
3437
+ end
3402
3438
if changedsince
3403
3439
mod ||= [ ]
3404
3440
mod << "CHANGEDSINCE" << Integer ( changedsince )
@@ -3415,9 +3451,9 @@ def fetch_internal(cmd, set, attr, mod = nil, changedsince: nil)
3415
3451
synchronize do
3416
3452
clear_responses ( "FETCH" )
3417
3453
if mod
3418
- send_command ( cmd , SequenceSet . new ( set ) , attr , mod )
3454
+ send_command ( cmd , set , attr , mod )
3419
3455
else
3420
- send_command ( cmd , SequenceSet . new ( set ) , attr )
3456
+ send_command ( cmd , set , attr )
3421
3457
end
3422
3458
clear_responses ( "FETCH" )
3423
3459
end
0 commit comments