net-imap 0.4.22 → 0.6.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -2
  3. data/README.md +10 -4
  4. data/docs/styles.css +75 -14
  5. data/lib/net/imap/authenticators.rb +2 -2
  6. data/lib/net/imap/command_data.rb +40 -95
  7. data/lib/net/imap/config/attr_accessors.rb +8 -9
  8. data/lib/net/imap/config/attr_inheritance.rb +64 -1
  9. data/lib/net/imap/config/attr_type_coercion.rb +22 -10
  10. data/lib/net/imap/config/attr_version_defaults.rb +90 -0
  11. data/lib/net/imap/config.rb +241 -125
  12. data/lib/net/imap/connection_state.rb +48 -0
  13. data/lib/net/imap/data_encoding.rb +80 -31
  14. data/lib/net/imap/deprecated_client_options.rb +6 -3
  15. data/lib/net/imap/errors.rb +158 -0
  16. data/lib/net/imap/esearch_result.rb +225 -0
  17. data/lib/net/imap/fetch_data.rb +126 -47
  18. data/lib/net/imap/flags.rb +1 -1
  19. data/lib/net/imap/response_data.rb +123 -187
  20. data/lib/net/imap/response_parser/parser_utils.rb +19 -23
  21. data/lib/net/imap/response_parser.rb +182 -38
  22. data/lib/net/imap/response_reader.rb +10 -12
  23. data/lib/net/imap/sasl/anonymous_authenticator.rb +3 -3
  24. data/lib/net/imap/sasl/authentication_exchange.rb +52 -20
  25. data/lib/net/imap/sasl/authenticators.rb +8 -4
  26. data/lib/net/imap/sasl/client_adapter.rb +77 -26
  27. data/lib/net/imap/sasl/cram_md5_authenticator.rb +4 -4
  28. data/lib/net/imap/sasl/digest_md5_authenticator.rb +218 -56
  29. data/lib/net/imap/sasl/external_authenticator.rb +2 -2
  30. data/lib/net/imap/sasl/gs2_header.rb +7 -7
  31. data/lib/net/imap/sasl/login_authenticator.rb +4 -3
  32. data/lib/net/imap/sasl/oauthbearer_authenticator.rb +6 -6
  33. data/lib/net/imap/sasl/plain_authenticator.rb +7 -7
  34. data/lib/net/imap/sasl/protocol_adapters.rb +60 -4
  35. data/lib/net/imap/sasl/scram_authenticator.rb +8 -8
  36. data/lib/net/imap/sasl.rb +7 -4
  37. data/lib/net/imap/sasl_adapter.rb +0 -1
  38. data/lib/net/imap/search_result.rb +10 -5
  39. data/lib/net/imap/sequence_set.rb +1104 -421
  40. data/lib/net/imap/stringprep/nameprep.rb +1 -1
  41. data/lib/net/imap/stringprep/trace.rb +4 -4
  42. data/lib/net/imap/uidplus_data.rb +4 -147
  43. data/lib/net/imap/vanished_data.rb +65 -0
  44. data/lib/net/imap.rb +1002 -313
  45. data/net-imap.gemspec +1 -1
  46. data/rakelib/rfcs.rake +2 -0
  47. data/rakelib/string_prep_tables_generator.rb +6 -2
  48. metadata +7 -3
@@ -4,7 +4,7 @@ module Net
4
4
  class IMAP
5
5
  module StringPrep
6
6
 
7
- # Defined in RFC3491[https://tools.ietf.org/html/rfc3491], the +nameprep+
7
+ # Defined in RFC3491[https://www.rfc-editor.org/rfc/rfc3491], the +nameprep+
8
8
  # profile of "Stringprep" is:
9
9
  # >>>
10
10
  # used by the IDNA protocol for preparing domain names; it is not
@@ -4,11 +4,11 @@ module Net
4
4
  class IMAP
5
5
  module StringPrep
6
6
 
7
- # Defined in RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The +trace+
7
+ # Defined in RFC-4505[https://www.rfc-editor.org/rfc/rfc4505] §3, The +trace+
8
8
  # profile of \StringPrep is used by the +ANONYMOUS+ \SASL mechanism.
9
9
  module Trace
10
10
 
11
- # Defined in RFC-4505[https://tools.ietf.org/html/rfc4505] §3.
11
+ # Defined in RFC-4505[https://www.rfc-editor.org/rfc/rfc4505] §3.
12
12
  STRINGPREP_PROFILE = "trace"
13
13
 
14
14
  # >>>
@@ -23,7 +23,7 @@ module Net
23
23
  # No Unicode normalization is required by this profile.
24
24
  NORMALIZATION = nil
25
25
 
26
- # From RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The "trace"
26
+ # From RFC-4505[https://www.rfc-editor.org/rfc/rfc4505] §3, The "trace"
27
27
  # Profile of "Stringprep":
28
28
  # >>>
29
29
  # Characters from the following tables of [StringPrep] are prohibited:
@@ -47,7 +47,7 @@ module Net
47
47
 
48
48
  module_function
49
49
 
50
- # From RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The "trace"
50
+ # From RFC-4505[https://www.rfc-editor.org/rfc/rfc4505] §3, The "trace"
51
51
  # Profile of "Stringprep":
52
52
  # >>>
53
53
  # The character repertoire of this profile is Unicode 3.2 [Unicode].
@@ -3,107 +3,8 @@
3
3
  module Net
4
4
  class IMAP < Protocol
5
5
 
6
- # *NOTE:* <em>UIDPlusData is deprecated and will be removed in the +0.6.0+
7
- # release.</em> To use AppendUIDData and CopyUIDData before +0.6.0+, set
8
- # Config#parser_use_deprecated_uidplus_data to +false+.
9
- #
10
- # UIDPlusData represents the ResponseCode#data that accompanies the
11
- # +APPENDUID+ and +COPYUID+ {response codes}[rdoc-ref:ResponseCode].
12
- #
13
- # A server that supports +UIDPLUS+ should send UIDPlusData in response to
14
- # the append[rdoc-ref:Net::IMAP#append], copy[rdoc-ref:Net::IMAP#copy],
15
- # move[rdoc-ref:Net::IMAP#move], {uid copy}[rdoc-ref:Net::IMAP#uid_copy],
16
- # and {uid move}[rdoc-ref:Net::IMAP#uid_move] commands---unless the
17
- # destination mailbox reports +UIDNOTSTICKY+.
18
- #
19
- # Note that append[rdoc-ref:Net::IMAP#append], copy[rdoc-ref:Net::IMAP#copy]
20
- # and {uid_copy}[rdoc-ref:Net::IMAP#uid_copy] return UIDPlusData in their
21
- # TaggedResponse. But move[rdoc-ref:Net::IMAP#copy] and
22
- # {uid_move}[rdoc-ref:Net::IMAP#uid_move] _should_ send UIDPlusData in an
23
- # UntaggedResponse response before sending their TaggedResponse. However
24
- # some servers do send UIDPlusData in the TaggedResponse for +MOVE+
25
- # commands---this complies with the older +UIDPLUS+ specification but is
26
- # discouraged by the +MOVE+ extension and disallowed by +IMAP4rev2+.
27
- #
28
- # == Required capability
29
- # Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
30
- # or +IMAP4rev2+ capability.
31
- #
32
- class UIDPlusData < Struct.new(:uidvalidity, :source_uids, :assigned_uids)
33
- ##
34
- # method: uidvalidity
35
- # :call-seq: uidvalidity -> nonzero uint32
36
- #
37
- # The UIDVALIDITY of the destination mailbox.
38
-
39
- ##
40
- # method: source_uids
41
- # :call-seq: source_uids -> nil or an array of nonzero uint32
42
- #
43
- # The UIDs of the copied or moved messages.
44
- #
45
- # Note:: Returns +nil+ for Net::IMAP#append.
46
-
47
- ##
48
- # method: assigned_uids
49
- # :call-seq: assigned_uids -> an array of nonzero uint32
50
- #
51
- # The newly assigned UIDs of the copied, moved, or appended messages.
52
- #
53
- # Note:: This always returns an array, even when it contains only one UID.
54
-
55
- ##
56
- # :call-seq: uid_mapping -> nil or a hash
57
- #
58
- # Returns a hash mapping each source UID to the newly assigned destination
59
- # UID.
60
- #
61
- # Note:: Returns +nil+ for Net::IMAP#append.
62
- def uid_mapping
63
- source_uids&.zip(assigned_uids)&.to_h
64
- end
65
- end
66
-
67
- # This replaces the `Data.define` polyfill that's used by net-imap 0.5.
68
- class Data_define__uidvalidity___assigned_uids_ # :no-doc:
69
- attr_reader :uidvalidity, :assigned_uids
70
-
71
- def self.[](...) new(...) end
72
- def self.new(uidvalidity = (args = false; nil),
73
- assigned_uids = nil,
74
- **kwargs)
75
- if kwargs.empty?
76
- super(uidvalidity: uidvalidity, assigned_uids: assigned_uids)
77
- elsif !args
78
- super
79
- else
80
- raise ArgumentError, "sent both positional and keyword args"
81
- end
82
- end
83
-
84
- def ==(other)
85
- self.class == other.class &&
86
- self.uidvalidity == other.uidvalidity &&
87
- self.assigned_uids == other.assigned_uids
88
- end
89
-
90
- def eql?(other)
91
- self.class.eql?(other.class) &&
92
- self.uidvalidity.eql?(other.uidvalidity) &&
93
- self.assigned_uids.eql?(other.assigned_uids)
94
- end
95
-
96
- def hash; [self.class, uidvalidity, assigned_uids].hash end
97
-
98
- def initialize(uidvalidity:, assigned_uids:)
99
- @uidvalidity = uidvalidity
100
- @assigned_uids = assigned_uids
101
- freeze
102
- end
103
- end
104
-
105
6
  # >>>
106
- # *NOTE:* <em>AppendUIDData will replace UIDPlusData for +APPENDUID+ in the
7
+ # *NOTE:* <em>AppendUIDData replaced UIDPlusData for +APPENDUID+ in the
107
8
  # +0.6.0+ release.</em> To use AppendUIDData before +0.6.0+, set
108
9
  # Config#parser_use_deprecated_uidplus_data to +false+.
109
10
  #
@@ -118,7 +19,7 @@ module Net
118
19
  # == Required capability
119
20
  # Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
120
21
  # or +IMAP4rev2+ capability.
121
- class AppendUIDData < Data_define__uidvalidity___assigned_uids_
22
+ class AppendUIDData < Data.define(:uidvalidity, :assigned_uids)
122
23
  def initialize(uidvalidity:, assigned_uids:)
123
24
  uidvalidity = Integer(uidvalidity)
124
25
  assigned_uids = SequenceSet[assigned_uids]
@@ -146,52 +47,8 @@ module Net
146
47
  end
147
48
  end
148
49
 
149
- # This replaces the `Data.define` polyfill that's used by net-imap 0.5.
150
- class Data_define__uidvalidity___source_uids___assigned_uids_ # :no-doc:
151
- attr_reader :uidvalidity, :source_uids, :assigned_uids
152
-
153
- def self.[](...) new(...) end
154
- def self.new(uidvalidity = (args = false; nil),
155
- source_uids = nil,
156
- assigned_uids = nil,
157
- **kwargs)
158
- if kwargs.empty?
159
- super(uidvalidity: uidvalidity,
160
- source_uids: source_uids,
161
- assigned_uids: assigned_uids)
162
- elsif !args
163
- super(**kwargs)
164
- else
165
- raise ArgumentError, "sent both positional and keyword args"
166
- end
167
- end
168
-
169
- def initialize(uidvalidity:, source_uids:, assigned_uids:)
170
- @uidvalidity = uidvalidity
171
- @source_uids = source_uids
172
- @assigned_uids = assigned_uids
173
- freeze
174
- end
175
-
176
- def ==(other)
177
- self.class == other.class &&
178
- self.uidvalidity == other.uidvalidity &&
179
- self.source_uids == other.source_uids
180
- self.assigned_uids == other.assigned_uids
181
- end
182
-
183
- def eql?(other)
184
- self.class.eql?(other.class) &&
185
- self.uidvalidity.eql?(other.uidvalidity) &&
186
- self.source_uids.eql?(other.source_uids)
187
- self.assigned_uids.eql?(other.assigned_uids)
188
- end
189
-
190
- def hash; [self.class, uidvalidity, source_uids, assigned_uids].hash end
191
- end
192
-
193
50
  # >>>
194
- # *NOTE:* <em>CopyUIDData will replace UIDPlusData for +COPYUID+ in the
51
+ # *NOTE:* <em>CopyUIDData replaced UIDPlusData for +COPYUID+ in the
195
52
  # +0.6.0+ release.</em> To use CopyUIDData before +0.6.0+, set
196
53
  # Config#parser_use_deprecated_uidplus_data to +false+.
197
54
  #
@@ -216,7 +73,7 @@ module Net
216
73
  # == Required capability
217
74
  # Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
218
75
  # or +IMAP4rev2+ capability.
219
- class CopyUIDData < Data_define__uidvalidity___source_uids___assigned_uids_
76
+ class CopyUIDData < Data.define(:uidvalidity, :source_uids, :assigned_uids)
220
77
  def initialize(uidvalidity:, source_uids:, assigned_uids:)
221
78
  uidvalidity = Integer(uidvalidity)
222
79
  source_uids = SequenceSet[source_uids]
@@ -0,0 +1,65 @@
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] unless uids.equal? SequenceSet.empty
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
+ # Yields each UID in #uids and returns +self+. Returns an Enumerator when
55
+ # no block is given.
56
+ #
57
+ # See SequenceSet#each_number.
58
+ def each(&)
59
+ return to_enum unless block_given?
60
+ uids.each_number(&)
61
+ self
62
+ end
63
+ end
64
+ end
65
+ end