net-imap 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of net-imap might be problematic. Click here for more details.

@@ -769,8 +769,6 @@ module Net
769
769
  def response_data__ignored; response_data__unhandled(IgnoredResponse) end
770
770
  alias response_data__noop response_data__ignored
771
771
 
772
- alias esearch_response response_data__unhandled
773
- alias expunged_resp response_data__unhandled
774
772
  alias uidfetch_resp response_data__unhandled
775
773
  alias listrights_data response_data__unhandled
776
774
  alias myrights_data response_data__unhandled
@@ -842,6 +840,20 @@ module Net
842
840
  alias mailbox_data__exists response_data__simple_numeric
843
841
  alias mailbox_data__recent response_data__simple_numeric
844
842
 
843
+ # The name for this is confusing, because it *replaces* EXPUNGE
844
+ # >>>
845
+ # expunged-resp = "VANISHED" [SP "(EARLIER)"] SP known-uids
846
+ def expunged_resp
847
+ name = label "VANISHED"; SP!
848
+ earlier = if lpar? then label("EARLIER"); rpar; SP!; true else false end
849
+ uids = known_uids
850
+ data = VanishedData[uids, earlier]
851
+ UntaggedResponse.new name, data, @str
852
+ end
853
+
854
+ # TODO: replace with uid_set
855
+ alias known_uids sequence_set
856
+
845
857
  # RFC3501 & RFC9051:
846
858
  # msg-att = "(" (msg-att-dynamic / msg-att-static)
847
859
  # *(SP (msg-att-dynamic / msg-att-static)) ")"
@@ -1468,6 +1480,78 @@ module Net
1468
1480
  end
1469
1481
  alias sort_data mailbox_data__search
1470
1482
 
1483
+ # esearch-response = "ESEARCH" [search-correlator] [SP "UID"]
1484
+ # *(SP search-return-data)
1485
+ # ;; Note that SEARCH and ESEARCH responses
1486
+ # ;; SHOULD be mutually exclusive,
1487
+ # ;; i.e., only one of the response types
1488
+ # ;; should be
1489
+ # ;; returned as a result of a command.
1490
+ # esearch-response = "ESEARCH" [search-correlator] [SP "UID"]
1491
+ # *(SP search-return-data)
1492
+ # ; ESEARCH response replaces SEARCH response
1493
+ # ; from IMAP4rev1.
1494
+ # search-correlator = SP "(" "TAG" SP tag-string ")"
1495
+ def esearch_response
1496
+ name = label("ESEARCH")
1497
+ tag = search_correlator if peek_str?(" (")
1498
+ uid = peek_re?(/\G UID\b/i) && (SP!; label("UID"); true)
1499
+ data = []
1500
+ data << search_return_data while SP?
1501
+ esearch = ESearchResult.new(tag, uid, data)
1502
+ UntaggedResponse.new(name, esearch, @str)
1503
+ end
1504
+
1505
+ # From RFC4731 (ESEARCH):
1506
+ # search-return-data = "MIN" SP nz-number /
1507
+ # "MAX" SP nz-number /
1508
+ # "ALL" SP sequence-set /
1509
+ # "COUNT" SP number /
1510
+ # search-ret-data-ext
1511
+ # ; All return data items conform to
1512
+ # ; search-ret-data-ext syntax.
1513
+ # search-ret-data-ext = search-modifier-name SP search-return-value
1514
+ # search-modifier-name = tagged-ext-label
1515
+ # search-return-value = tagged-ext-val
1516
+ #
1517
+ # From RFC4731 (ESEARCH):
1518
+ # search-return-data =/ "MODSEQ" SP mod-sequence-value
1519
+ #
1520
+ def search_return_data
1521
+ label = search_modifier_name; SP!
1522
+ value =
1523
+ case label
1524
+ when "MIN" then nz_number
1525
+ when "MAX" then nz_number
1526
+ when "ALL" then sequence_set
1527
+ when "COUNT" then number
1528
+ when "MODSEQ" then mod_sequence_value # RFC7162: CONDSTORE
1529
+ else search_return_value
1530
+ end
1531
+ [label, value]
1532
+ end
1533
+
1534
+ # search-modifier-name = tagged-ext-label
1535
+ alias search_modifier_name tagged_ext_label
1536
+
1537
+ # search-return-value = tagged-ext-val
1538
+ # ; Data for the returned search option.
1539
+ # ; A single "nz-number"/"number"/"number64" value
1540
+ # ; can be returned as an atom (i.e., without
1541
+ # ; quoting). A sequence-set can be returned
1542
+ # ; as an atom as well.
1543
+ def search_return_value; ExtensionData.new(tagged_ext_val) end
1544
+
1545
+ # search-correlator = SP "(" "TAG" SP tag-string ")"
1546
+ def search_correlator
1547
+ SP!; lpar; label("TAG"); SP!; tag = tag_string; rpar
1548
+ tag
1549
+ end
1550
+
1551
+ # tag-string = astring
1552
+ # ; <tag> represented as <astring>
1553
+ alias tag_string astring
1554
+
1471
1555
  # RFC5256: THREAD
1472
1556
  # thread-data = "THREAD" [SP 1*thread-list]
1473
1557
  def thread_data
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Net
4
+ class IMAP < Protocol
5
+
6
+ # Net::IMAP::VanishedData represents the contents of a +VANISHED+ response,
7
+ # which is described by the
8
+ # {QRESYNC}[https://www.rfc-editor.org/rfc/rfc7162.html] extension.
9
+ # [{RFC7162 §3.2.10}[https://www.rfc-editor.org/rfc/rfc7162.html#section-3.2.10]].
10
+ #
11
+ # +VANISHED+ responses replace +EXPUNGE+ responses when either the
12
+ # {QRESYNC}[https://www.rfc-editor.org/rfc/rfc7162.html] or the
13
+ # {UIDONLY}[https://www.rfc-editor.org/rfc/rfc9586.html] extension has been
14
+ # enabled.
15
+ class VanishedData < Data.define(:uids, :earlier)
16
+
17
+ # Returns a new VanishedData object.
18
+ #
19
+ # * +uids+ will be converted by SequenceSet.[].
20
+ # * +earlier+ will be converted to +true+ or +false+
21
+ def initialize(uids:, earlier:)
22
+ uids = SequenceSet[uids]
23
+ earlier = !!earlier
24
+ super
25
+ end
26
+
27
+ ##
28
+ # :attr_reader: uids
29
+ #
30
+ # SequenceSet of UIDs that have been permanently removed from the mailbox.
31
+
32
+ ##
33
+ # :attr_reader: earlier
34
+ #
35
+ # +true+ when the response was caused by Net::IMAP#uid_fetch with
36
+ # <tt>vanished: true</tt> or Net::IMAP#select/Net::IMAP#examine with
37
+ # <tt>qresync: true</tt>.
38
+ #
39
+ # +false+ when the response is used to announce message removals within an
40
+ # already selected mailbox.
41
+
42
+ # rdoc doesn't handle attr aliases nicely. :(
43
+ alias earlier? earlier # :nodoc:
44
+ ##
45
+ # :attr_reader: earlier?
46
+ #
47
+ # Alias for #earlier.
48
+
49
+ # Returns an Array of all of the UIDs in #uids.
50
+ #
51
+ # See SequenceSet#numbers.
52
+ def to_a; uids.numbers end
53
+
54
+ end
55
+ end
56
+ end