@@ -2636,6 +2636,7 @@ def fetch(...)
2636
2636
2637
2637
# :call-seq:
2638
2638
# uid_fetch(set, attr, changedsince: nil, partial: nil) -> array of FetchData (or UIDFetchData)
2639
+ # uid_fetch(set, attr, changedsince:, vanished: true, partial: nil) -> array of VanishedData and FetchData (or UIDFetchData)
2639
2640
#
2640
2641
# Sends a {UID FETCH command [IMAP4rev1 §6.4.8]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8]
2641
2642
# to retrieve data associated with a message in the mailbox.
@@ -2652,6 +2653,23 @@ def fetch(...)
2652
2653
#
2653
2654
# +changedsince+ (optional) behaves the same as with #fetch.
2654
2655
#
2656
+ # +vanished+ can be used to request a list all of the message UIDs in +set+
2657
+ # that have been expunged since +changedsince+. Setting +vanished+ to true
2658
+ # prepends a VanishedData object to the returned array. If the server does
2659
+ # not return a +VANISHED+ response, an empty VanishedData object will still
2660
+ # be added.
2661
+ # <em>The +QRESYNC+ capabability must be enabled.</em>
2662
+ # {[RFC7162]}[https://rfc-editor.org/rfc/rfc7162]
2663
+ #
2664
+ # For example:
2665
+ #
2666
+ # # must enable "QRESYNC" before selecting the mailbox
2667
+ # imap.enable("QRESYNC")
2668
+ # imap.select("INBOX")
2669
+ # # first value in the array is VanishedData
2670
+ # vanished, *fetched = imap.uid_fetch(301..500, %w[flags],
2671
+ # changedsince: 12345, vanished: true)
2672
+ #
2655
2673
# +partial+ is an optional range to limit the number of results returned.
2656
2674
# It's useful when +set+ contains an unknown number of messages.
2657
2675
# <tt>1..500</tt> returns the first 500 messages in +set+ (in mailbox
@@ -2683,6 +2701,9 @@ def fetch(...)
2683
2701
#
2684
2702
# ==== Capabilities
2685
2703
#
2704
+ # QRESYNC[https://www.rfc-editor.org/rfc/rfc7162] must be enabled in order
2705
+ # to use the +vanished+ fetch modifier.
2706
+ #
2686
2707
# The server's capabilities must include +PARTIAL+
2687
2708
# {[RFC9394]}[https://rfc-editor.org/rfc/rfc9394] in order to use the
2688
2709
# +partial+ argument.
@@ -2962,9 +2983,8 @@ def uid_thread(algorithm, search_keys, charset)
2962
2983
# See {[RFC7162 §3.1]}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.1].
2963
2984
#
2964
2985
# [+QRESYNC+ {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html]]
2965
- # *NOTE:* Enabling QRESYNC will replace +EXPUNGE+ with +VANISHED+, but
2966
- # the extension arguments to #select, #examine, and #uid_fetch are not
2967
- # supported yet.
2986
+ # *NOTE:* The +QRESYNC+ argument to #select and #examine is not supported
2987
+ # yet.
2968
2988
#
2969
2989
# Adds quick resynchronization options to #select, #examine, and
2970
2990
# #uid_fetch. +QRESYNC+ _must_ be explicitly enabled before using any of
@@ -3683,19 +3703,23 @@ def search_internal(cmd, ...)
3683
3703
end
3684
3704
end
3685
3705
3686
- def fetch_internal ( cmd , set , attr , mod = nil , partial : nil , changedsince : nil )
3687
- if partial && !cmd . start_with? ( "UID " )
3706
+ def fetch_internal ( cmd , set , attr , mod = nil ,
3707
+ partial : nil ,
3708
+ changedsince : nil ,
3709
+ vanished : false )
3710
+ if cmd . start_with? ( "UID " )
3711
+ if vanished && !changedsince
3712
+ raise ArgumentError , "vanished must be used with changedsince"
3713
+ end
3714
+ elsif vanished
3715
+ raise ArgumentError , "vanished can only be used with uid_fetch"
3716
+ elsif partial
3688
3717
raise ArgumentError , "partial can only be used with uid_fetch"
3689
3718
end
3690
3719
set = SequenceSet [ set ]
3691
- if partial
3692
- mod ||= [ ]
3693
- mod << "PARTIAL" << PartialRange [ partial ]
3694
- end
3695
- if changedsince
3696
- mod ||= [ ]
3697
- mod << "CHANGEDSINCE" << Integer ( changedsince )
3698
- end
3720
+ ( mod ||= [ ] ) << "PARTIAL" << PartialRange [ partial ] if partial
3721
+ ( mod ||= [ ] ) << "CHANGEDSINCE" << Integer ( changedsince ) if changedsince
3722
+ ( mod ||= [ ] ) << "VANISHED" if vanished
3699
3723
case attr
3700
3724
when String then
3701
3725
attr = RawData . new ( attr )
@@ -3707,7 +3731,7 @@ def fetch_internal(cmd, set, attr, mod = nil, partial: nil, changedsince: nil)
3707
3731
3708
3732
args = [ cmd , set , attr ]
3709
3733
args << mod if mod
3710
- send_command_returning_fetch_results ( *args )
3734
+ send_command_returning_fetch_results ( *args , vanished : )
3711
3735
end
3712
3736
3713
3737
def store_internal ( cmd , set , attr , flags , unchangedsince : nil )
@@ -3718,14 +3742,20 @@ def store_internal(cmd, set, attr, flags, unchangedsince: nil)
3718
3742
send_command_returning_fetch_results ( cmd , *args )
3719
3743
end
3720
3744
3721
- def send_command_returning_fetch_results ( ... )
3745
+ def send_command_returning_fetch_results ( * args , vanished : false )
3722
3746
synchronize do
3723
3747
clear_responses ( "FETCH" )
3724
3748
clear_responses ( "UIDFETCH" )
3725
- send_command ( ... )
3749
+ send_command ( * args )
3726
3750
fetches = clear_responses ( "FETCH" )
3727
3751
uidfetches = clear_responses ( "UIDFETCH" )
3728
- uidfetches . any? ? uidfetches : fetches
3752
+ fetches = uidfetches if uidfetches . any?
3753
+ if vanished
3754
+ vanished = extract_responses ( "VANISHED" , &:earlier? ) . last ||
3755
+ VanishedData [ uids : SequenceSet . empty , earlier : true ]
3756
+ fetches = [ vanished , *fetches ] . freeze
3757
+ end
3758
+ fetches
3729
3759
end
3730
3760
end
3731
3761
0 commit comments