net-imap 0.4.4 → 0.4.9

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.

@@ -2,6 +2,9 @@
2
2
 
3
3
  module Net
4
4
  class IMAP < Protocol
5
+ autoload :FetchData, "#{__dir__}/fetch_data"
6
+ autoload :SearchResult, "#{__dir__}/search_result"
7
+ autoload :SequenceSet, "#{__dir__}/sequence_set"
5
8
 
6
9
  # Net::IMAP::ContinuationRequest represents command continuation requests.
7
10
  #
@@ -70,7 +73,7 @@ module Net
70
73
  # unknown extensions to response types without a well-defined extension
71
74
  # grammar.
72
75
  #
73
- # See also: UnparsedNumericResponseData
76
+ # See also: UnparsedNumericResponseData, ExtensionData, IgnoredResponse
74
77
  class UnparsedData < Struct.new(:unparsed_data)
75
78
  ##
76
79
  # method: unparsed_data
@@ -86,7 +89,7 @@ module Net
86
89
  # Net::IMAP::UnparsedNumericResponseData represents data for unhandled
87
90
  # response types with a numeric prefix. See the documentation for #number.
88
91
  #
89
- # See also: UnparsedData
92
+ # See also: UnparsedData, ExtensionData, IgnoredResponse
90
93
  class UnparsedNumericResponseData < Struct.new(:number, :unparsed_data)
91
94
  ##
92
95
  # method: number
@@ -105,6 +108,23 @@ module Net
105
108
  # The unparsed data, not including #number or UntaggedResponse#name.
106
109
  end
107
110
 
111
+ # **Note:** This represents an intentionally _unstable_ API. Where
112
+ # instances of this class are returned, future releases may return a
113
+ # different (incompatible) object <em>without deprecation or warning</em>.
114
+ #
115
+ # Net::IMAP::ExtensionData represents data that is parsable according to the
116
+ # forward-compatible extension syntax in RFC3501, RFC4466, or RFC9051, but
117
+ # isn't directly known or understood by Net::IMAP yet.
118
+ #
119
+ # See also: UnparsedData, UnparsedNumericResponseData, IgnoredResponse
120
+ class ExtensionData < Struct.new(:data)
121
+ ##
122
+ # method: data
123
+ # :call-seq: data -> string
124
+ #
125
+ # The parsed extension data.
126
+ end
127
+
108
128
  # Net::IMAP::TaggedResponse represents tagged responses.
109
129
  #
110
130
  # The server completion result response indicates the success or
@@ -186,6 +206,7 @@ module Net
186
206
  # defines them. When unknown response code data is encountered, #data
187
207
  # will return an unparsed string.
188
208
  #
209
+ # ==== +IMAP4rev1+ Response Codes
189
210
  # See [IMAP4rev1[https://www.rfc-editor.org/rfc/rfc3501]] {§7.1, "Server
190
211
  # Responses - Status
191
212
  # Responses"}[https://www.rfc-editor.org/rfc/rfc3501#section-7.1] for full
@@ -209,13 +230,32 @@ module Net
209
230
  # {§2.3.1.1, "Unique Identifier (UID) Message
210
231
  # Attribute}[https://www.rfc-editor.org/rfc/rfc3501#section-2.3.1.1].
211
232
  # * +UIDVALIDITY+, #data is an Integer, the UID validity value of the
212
- # mailbox See [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501]],
233
+ # mailbox. See [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501]],
213
234
  # {§2.3.1.1, "Unique Identifier (UID) Message
214
235
  # Attribute}[https://www.rfc-editor.org/rfc/rfc3501#section-2.3.1.1].
215
236
  # * +UNSEEN+, #data is an Integer, the number of messages which do not have
216
237
  # the <tt>\Seen</tt> flag set.
217
- #
218
- # See RFC5530[https://www.rfc-editor.org/rfc/rfc5530], "IMAP Response
238
+ # <em>DEPRECATED by IMAP4rev2.</em>
239
+ #
240
+ # ==== +BINARY+ extension
241
+ # See {[RFC3516]}[https://www.rfc-editor.org/rfc/rfc3516].
242
+ # * +UNKNOWN-CTE+, with a tagged +NO+ response, when the server does not
243
+ # known how to decode a CTE (content-transfer-encoding). #data is +nil+.
244
+ # See IMAP#fetch.
245
+ #
246
+ # ==== +UIDPLUS+ extension
247
+ # See {[RFC4315 §3]}[https://www.rfc-editor.org/rfc/rfc4315#section-3].
248
+ # * +APPENDUID+, #data is UIDPlusData. See IMAP#append.
249
+ # * +COPYUID+, #data is UIDPlusData. See IMAP#copy.
250
+ # * +UIDNOTSTICKY+, #data is +nil+. See IMAP#select.
251
+ #
252
+ # ==== +SEARCHRES+ extension
253
+ # See {[RFC5182]}[https://www.rfc-editor.org/rfc/rfc5182].
254
+ # * +NOTSAVED+, with a tagged +NO+ response, when the search result variable
255
+ # is not saved. #data is +nil+.
256
+ #
257
+ # ==== +RFC5530+ Response Codes
258
+ # See {[RFC5530]}[https://www.rfc-editor.org/rfc/rfc5530], "IMAP Response
219
259
  # Codes" for the definition of the following response codes, which are all
220
260
  # machine-readable annotations for the human-readable ResponseText#text, and
221
261
  # have +nil+ #data of their own:
@@ -237,6 +277,35 @@ module Net
237
277
  # * +ALREADYEXISTS+
238
278
  # * +NONEXISTENT+
239
279
  #
280
+ # ==== +QRESYNC+ extension
281
+ # See {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html].
282
+ # * +CLOSED+, returned when the currently selected mailbox is closed
283
+ # implicity by selecting or examining another mailbox. #data is +nil+.
284
+ #
285
+ # ==== +IMAP4rev2+ Response Codes
286
+ # See {[RFC9051]}[https://www.rfc-editor.org/rfc/rfc9051] {§7.1, "Server
287
+ # Responses - Status
288
+ # Responses"}[https://www.rfc-editor.org/rfc/rfc9051#section-7.1] for full
289
+ # descriptions of IMAP4rev2 response codes. IMAP4rev2 includes all of the
290
+ # response codes listed above (except "UNSEEN") and adds the following:
291
+ # * +HASCHILDREN+, with a tagged +NO+ response, when a mailbox delete failed
292
+ # because the server doesn't allow deletion of mailboxes with children.
293
+ # #data is +nil+.
294
+ #
295
+ # ==== +CONDSTORE+ extension
296
+ # See {[RFC7162]}[https://www.rfc-editor.org/rfc/rfc7162.html].
297
+ # * +NOMODSEQ+, when selecting a mailbox that does not support
298
+ # mod-sequences. #data is +nil+. See IMAP#select.
299
+ # * +HIGHESTMODSEQ+, #data is an Integer, the highest mod-sequence value of
300
+ # all messages in the mailbox. See IMAP#select.
301
+ # * +MODIFIED+, #data is a SequenceSet, the messages that have been modified
302
+ # since the +UNCHANGEDSINCE+ mod-sequence given to +STORE+ or <tt>UID
303
+ # STORE</tt>.
304
+ #
305
+ # ==== +OBJECTID+ extension
306
+ # See {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html].
307
+ # * +MAILBOXID+, #data is a string
308
+ #
240
309
  class ResponseCode < Struct.new(:name, :data)
241
310
  ##
242
311
  # method: name
@@ -488,210 +557,6 @@ module Net
488
557
  # "UIDVALIDITY", "UNSEEN". Each value is a number.
489
558
  end
490
559
 
491
- # Net::IMAP::FetchData represents the contents of a FETCH response.
492
- #
493
- # Net::IMAP#fetch and Net::IMAP#uid_fetch both return an array of
494
- # FetchData objects.
495
- #
496
- # === Fetch attributes
497
- #
498
- #--
499
- # TODO: merge branch with accessor methods for each type of attr. Then
500
- # move nearly all of the +attr+ documentation onto the appropriate
501
- # accessor methods.
502
- #++
503
- #
504
- # Each key of the #attr hash is the data item name for the fetched value.
505
- # Each data item represents a message attribute, part of one, or an
506
- # interpretation of one. #seqno is not a message attribute. Most message
507
- # attributes are static and must never change for a given <tt>[server,
508
- # account, mailbox, UIDVALIDITY, UID]</tt> tuple. A few message attributes
509
- # can be dynamically changed, e.g. using the {STORE
510
- # command}[rdoc-ref:Net::IMAP#store].
511
- #
512
- # See {[IMAP4rev1] §7.4.2}[https://www.rfc-editor.org/rfc/rfc3501.html#section-7.4.2]
513
- # and {[IMAP4rev2] §7.5.2}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.5.2]
514
- # for full description of the standard fetch response data items, and
515
- # Net::IMAP@Message+envelope+and+body+structure for other relevant RFCs.
516
- #
517
- # ==== Static fetch data items
518
- #
519
- # The static data items
520
- # defined by [IMAP4rev1[https://www.rfc-editor.org/rfc/rfc3501.html]] are:
521
- #
522
- # [<tt>"UID"</tt>]
523
- # A number expressing the unique identifier of the message.
524
- #
525
- # [<tt>"BODY[]"</tt>, <tt>"BODY[]<#{offset}>"</tt>]
526
- # The [RFC5322[https://tools.ietf.org/html/rfc5322]] expression of the
527
- # entire message, as a string.
528
- #
529
- # If +offset+ is specified, this returned string is a substring of the
530
- # entire contents, starting at that origin octet. This means that
531
- # <tt>BODY[]<0></tt> MAY be truncated, but <tt>BODY[]</tt> is NEVER
532
- # truncated.
533
- #
534
- # <em>Messages can be parsed using the "mail" gem.</em>
535
- #
536
- # [Note]
537
- # When fetching <tt>BODY.PEEK[#{specifier}]</tt>, the data will be
538
- # returned in <tt>BODY[#{specifier}]</tt>, without the +PEEK+. This is
539
- # true for all of the <tt>BODY[...]</tt> attribute forms.
540
- #
541
- # [<tt>"BODY[HEADER]"</tt>, <tt>"BODY[HEADER]<#{offset}>"</tt>]
542
- # The [RFC5322[https://tools.ietf.org/html/rfc5322]] header of the
543
- # message.
544
- #
545
- # <em>Message headers can be parsed using the "mail" gem.</em>
546
- #
547
- # [<tt>"BODY[HEADER.FIELDS (#{fields.join(" ")})]"</tt>,]
548
- # [<tt>"BODY[HEADER.FIELDS (#{fields.join(" ")})]<#{offset}>"</tt>]
549
- # When field names are given, the subset contains only the header fields
550
- # that matches one of the names in the list. The field names are based
551
- # on what was requested, not on what was returned.
552
- #
553
- # [<tt>"BODY[HEADER.FIELDS.NOT (#{fields.join(" ")})]"</tt>,]
554
- # [<tt>"BODY[HEADER.FIELDS.NOT (#{fields.join(" ")})]<#{offset}>"</tt>]
555
- # When the <tt>HEADER.FIELDS.NOT</tt> is used, the subset is all of the
556
- # fields that <em>do not</em> match any names in the list.
557
- #
558
- # [<tt>"BODY[TEXT]"</tt>, <tt>"BODY[TEXT]<#{offset}>"</tt>]
559
- # The text body of the message, omitting
560
- # the [RFC5322[https://tools.ietf.org/html/rfc5322]] header.
561
- #
562
- # [<tt>"BODY[#{part}]"</tt>, <tt>"BODY[#{part}]<#{offset}>"</tt>]
563
- # The text of a particular body section, if it was fetched.
564
- #
565
- # Multiple part specifiers will be joined with <tt>"."</tt>. Numeric
566
- # part specifiers refer to the MIME part number, counting up from +1+.
567
- # Messages that don't use MIME, or MIME messages that are not multipart
568
- # and don't hold an encapsulated message, only have a part +1+.
569
- #
570
- # 8-bit textual data is permitted if
571
- # a [CHARSET[https://tools.ietf.org/html/rfc2978]] identifier is part of
572
- # the body parameter parenthesized list for this section. See
573
- # BodyTypeBasic.
574
- #
575
- # MESSAGE/RFC822 or MESSAGE/GLOBAL message, or a subset of the header, if
576
- # it was fetched.
577
- #
578
- # [<tt>"BODY[#{part}.HEADER]"</tt>,]
579
- # [<tt>"BODY[#{part}.HEADER]<#{offset}>"</tt>,]
580
- # [<tt>"BODY[#{part}.HEADER.FIELDS.NOT (#{fields.join(" ")})]"</tt>,]
581
- # [<tt>"BODY[#{part}.HEADER.FIELDS.NOT (#{fields.join(" ")})]<#{offset}>"</tt>,]
582
- # [<tt>"BODY[#{part}.TEXT]"</tt>,]
583
- # [<tt>"BODY[#{part}.TEXT]<#{offset}>"</tt>,]
584
- # [<tt>"BODY[#{part}.MIME]"</tt>,]
585
- # [<tt>"BODY[#{part}.MIME]<#{offset}>"</tt>]
586
- # +HEADER+, <tt>HEADER.FIELDS</tt>, <tt>HEADER.FIELDS.NOT</tt>, and
587
- # <tt>TEXT</tt> can be prefixed by numeric part specifiers, if it refers
588
- # to a part of type <tt>message/rfc822</tt> or <tt>message/global</tt>.
589
- #
590
- # +MIME+ refers to the [MIME-IMB[https://tools.ietf.org/html/rfc2045]]
591
- # header for this part.
592
- #
593
- # [<tt>"BODY"</tt>]
594
- # A form of +BODYSTRUCTURE+, without any extension data.
595
- #
596
- # [<tt>"BODYSTRUCTURE"</tt>]
597
- # Returns a BodyStructure object that describes
598
- # the [MIME-IMB[https://tools.ietf.org/html/rfc2045]] body structure of
599
- # a message, if it was fetched.
600
- #
601
- # [<tt>"ENVELOPE"</tt>]
602
- # An Envelope object that describes the envelope structure of a message.
603
- # See the documentation for Envelope for a description of the envelope
604
- # structure attributes.
605
- #
606
- # [<tt>"INTERNALDATE"</tt>]
607
- # The internal date and time of the message on the server. This is not
608
- # the date and time in
609
- # the [RFC5322[https://tools.ietf.org/html/rfc5322]] header, but rather
610
- # a date and time which reflects when the message was received.
611
- #
612
- # [<tt>"RFC822.SIZE"</tt>]
613
- # A number expressing the [RFC5322[https://tools.ietf.org/html/rfc5322]]
614
- # size of the message.
615
- #
616
- # [Note]
617
- # \IMAP was originally developed for the older RFC-822 standard, and
618
- # as a consequence several fetch items in \IMAP incorporate "RFC822"
619
- # in their name. With the exception of +RFC822.SIZE+, there are more
620
- # modern replacements; for example, the modern version of
621
- # +RFC822.HEADER+ is <tt>BODY.PEEK[HEADER]</tt>. In all cases,
622
- # "RFC822" should be interpreted as a reference to the
623
- # updated [RFC5322[https://tools.ietf.org/html/rfc5322]] standard.
624
- #
625
- # [<tt>"RFC822"</tt>]
626
- # Semantically equivalent to <tt>BODY[]</tt>.
627
- # [<tt>"RFC822.HEADER"</tt>]
628
- # Semantically equivalent to <tt>BODY[HEADER]</tt>.
629
- # [<tt>"RFC822.TEXT"</tt>]
630
- # Semantically equivalent to <tt>BODY[TEXT]</tt>.
631
- #
632
- # [Note:]
633
- # >>>
634
- # Additional static fields are defined in \IMAP extensions and
635
- # [IMAP4rev2[https://www.rfc-editor.org/rfc/rfc9051.html]], but
636
- # Net::IMAP can't parse them yet.
637
- #
638
- #--
639
- # <tt>"BINARY[#{section_binary}]<#{offset}>"</tt>:: TODO...
640
- # <tt>"BINARY.SIZE[#{sectionbinary}]"</tt>:: TODO...
641
- # <tt>"EMAILID"</tt>:: TODO...
642
- # <tt>"THREADID"</tt>:: TODO...
643
- # <tt>"SAVEDATE"</tt>:: TODO...
644
- #++
645
- #
646
- # ==== Dynamic message attributes
647
- # The only dynamic item defined
648
- # by [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501.html]] is:
649
- # [<tt>"FLAGS"</tt>]
650
- # An array of flags that are set for this message. System flags are
651
- # symbols that have been capitalized by String#capitalize. Keyword
652
- # flags are strings and their case is not changed.
653
- #
654
- # \IMAP extensions define new dynamic fields, e.g.:
655
- #
656
- # [<tt>"MODSEQ"</tt>]
657
- # The modification sequence number associated with this IMAP message.
658
- #
659
- # Requires the [CONDSTORE[https://tools.ietf.org/html/rfc7162]]
660
- # server {capability}[rdoc-ref:Net::IMAP#capability].
661
- #
662
- # [Note:]
663
- # >>>
664
- # Additional dynamic fields are defined in \IMAP extensions, but
665
- # Net::IMAP can't parse them yet.
666
- #
667
- #--
668
- # <tt>"ANNOTATE"</tt>:: TODO...
669
- # <tt>"PREVIEW"</tt>:: TODO...
670
- #++
671
- #
672
- class FetchData < Struct.new(:seqno, :attr)
673
- ##
674
- # method: seqno
675
- # :call-seq: seqno -> Integer
676
- #
677
- # The message sequence number.
678
- #
679
- # [Note]
680
- # This is never the unique identifier (UID), not even for the
681
- # Net::IMAP#uid_fetch result. If it was returned, the UID is available
682
- # from <tt>attr["UID"]</tt>.
683
-
684
- ##
685
- # method: attr
686
- # :call-seq: attr -> hash
687
- #
688
- # A hash. Each key is specifies a message attribute, and the value is the
689
- # corresponding data item.
690
- #
691
- # See rdoc-ref:FetchData@Fetch+attributes for descriptions of possible
692
- # values.
693
- end
694
-
695
560
  # Net::IMAP::Envelope represents envelope structures of messages.
696
561
  #
697
562
  # [Note]
@@ -705,6 +570,7 @@ module Net
705
570
  # for full description of the envelope fields, and
706
571
  # Net::IMAP@Message+envelope+and+body+structure for other relevant RFCs.
707
572
  #
573
+ # Returned by FetchData#envelope
708
574
  class Envelope < Struct.new(:date, :subject, :from, :sender, :reply_to,
709
575
  :to, :cc, :bcc, :in_reply_to, :message_id)
710
576
  ##
@@ -908,6 +774,19 @@ module Net
908
774
  #
909
775
  # An array of Net::IMAP::ThreadMember objects for mail items that are
910
776
  # children of this in the thread.
777
+
778
+ # Returns a SequenceSet containing #seqno and all #children's seqno,
779
+ # recursively.
780
+ def to_sequence_set
781
+ SequenceSet.new all_seqnos
782
+ end
783
+
784
+ protected
785
+
786
+ def all_seqnos(node = self)
787
+ [node.seqno].concat node.children.flat_map { _1.all_seqnos }
788
+ end
789
+
911
790
  end
912
791
 
913
792
  # Net::IMAP::BodyStructure is included by all of the structs that can be
@@ -1123,7 +1002,6 @@ module Net
1123
1002
  # * description[rdoc-ref:BodyTypeBasic#description]
1124
1003
  # * encoding[rdoc-ref:BodyTypeBasic#encoding]
1125
1004
  # * size[rdoc-ref:BodyTypeBasic#size]
1126
- #
1127
1005
  class BodyTypeMessage < Struct.new(:media_type, :subtype,
1128
1006
  :param, :content_id,
1129
1007
  :description, :encoding, :size,
@@ -8,7 +8,7 @@ module Net
8
8
  # (internal API, subject to change)
9
9
  module ParserUtils # :nodoc:
10
10
 
11
- module Generator
11
+ module Generator # :nodoc:
12
12
 
13
13
  LOOKAHEAD = "(@token ||= next_token)"
14
14
  SHIFT_TOKEN = "(@token = nil)"