net-imap 0.5.12 → 0.6.0
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/net/imap/command_data.rb +0 -68
- data/lib/net/imap/config/attr_inheritance.rb +14 -1
- data/lib/net/imap/config/attr_version_defaults.rb +93 -0
- data/lib/net/imap/config.rb +210 -122
- data/lib/net/imap/connection_state.rb +1 -1
- data/lib/net/imap/data_encoding.rb +77 -28
- data/lib/net/imap/esearch_result.rb +6 -0
- data/lib/net/imap/response_data.rb +2 -3
- data/lib/net/imap/response_parser.rb +8 -13
- data/lib/net/imap/search_result.rb +6 -0
- data/lib/net/imap/sequence_set.rb +621 -311
- data/lib/net/imap/uidplus_data.rb +2 -63
- data/lib/net/imap.rb +17 -23
- data/net-imap.gemspec +1 -1
- metadata +4 -4
- data/lib/net/imap/data_lite.rb +0 -226
|
@@ -155,57 +155,106 @@ module Net
|
|
|
155
155
|
|
|
156
156
|
# Common validators of number and nz_number types
|
|
157
157
|
module NumValidator # :nodoc
|
|
158
|
+
NUMBER_RE = /\A(?:0|[1-9]\d*)\z/
|
|
158
159
|
module_function
|
|
159
160
|
|
|
160
|
-
# Check is
|
|
161
|
+
# Check if argument is a valid 'number' according to RFC 3501
|
|
162
|
+
# number = 1*DIGIT
|
|
163
|
+
# ; Unsigned 32-bit integer
|
|
164
|
+
# ; (0 <= n < 4,294,967,296)
|
|
161
165
|
def valid_number?(num)
|
|
162
|
-
|
|
163
|
-
# number = 1*DIGIT
|
|
164
|
-
# ; Unsigned 32-bit integer
|
|
165
|
-
# ; (0 <= n < 4,294,967,296)
|
|
166
|
-
num >= 0 && num < 4294967296
|
|
166
|
+
0 <= num && num <= 0xffff_ffff
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
# Check is
|
|
169
|
+
# Check if argument is a valid 'nz-number' according to RFC 3501
|
|
170
|
+
# nz-number = digit-nz *DIGIT
|
|
171
|
+
# ; Non-zero unsigned 32-bit integer
|
|
172
|
+
# ; (0 < n < 4,294,967,296)
|
|
170
173
|
def valid_nz_number?(num)
|
|
171
|
-
|
|
172
|
-
# nz-number = digit-nz *DIGIT
|
|
173
|
-
# ; Non-zero unsigned 32-bit integer
|
|
174
|
-
# ; (0 < n < 4,294,967,296)
|
|
175
|
-
num != 0 && valid_number?(num)
|
|
174
|
+
0 < num && num <= 0xffff_ffff
|
|
176
175
|
end
|
|
177
176
|
|
|
178
|
-
# Check is
|
|
177
|
+
# Check if argument is a valid 'mod-sequence-value' according to RFC 4551
|
|
178
|
+
# mod-sequence-value = 1*DIGIT
|
|
179
|
+
# ; Positive unsigned 64-bit integer
|
|
180
|
+
# ; (mod-sequence)
|
|
181
|
+
# ; (1 <= n < 18,446,744,073,709,551,615)
|
|
179
182
|
def valid_mod_sequence_value?(num)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
1 <= num && num < 0xffff_ffff_ffff_ffff
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Check if argument is a valid 'mod-sequence-valzer' according to RFC 4551
|
|
187
|
+
# mod-sequence-valzer = "0" / mod-sequence-value
|
|
188
|
+
def valid_mod_sequence_valzer?(num)
|
|
189
|
+
0 <= num && num < 0xffff_ffff_ffff_ffff
|
|
185
190
|
end
|
|
186
191
|
|
|
187
192
|
# Ensure argument is 'number' or raise DataFormatError
|
|
188
193
|
def ensure_number(num)
|
|
189
194
|
return num if valid_number?(num)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
raise DataFormatError, msg
|
|
195
|
+
raise DataFormatError,
|
|
196
|
+
"number must be unsigned 32-bit integer: #{num}"
|
|
193
197
|
end
|
|
194
198
|
|
|
195
|
-
# Ensure argument is '
|
|
199
|
+
# Ensure argument is 'nz-number' or raise DataFormatError
|
|
196
200
|
def ensure_nz_number(num)
|
|
197
201
|
return num if valid_nz_number?(num)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
raise DataFormatError, msg
|
|
202
|
+
raise DataFormatError,
|
|
203
|
+
"nz-number must be non-zero unsigned 32-bit integer: #{num}"
|
|
201
204
|
end
|
|
202
205
|
|
|
203
|
-
# Ensure argument is '
|
|
206
|
+
# Ensure argument is 'mod-sequence-value' or raise DataFormatError
|
|
204
207
|
def ensure_mod_sequence_value(num)
|
|
205
208
|
return num if valid_mod_sequence_value?(num)
|
|
209
|
+
raise DataFormatError,
|
|
210
|
+
"mod-sequence-value must be non-zero unsigned 64-bit integer: #{num}"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Ensure argument is 'mod-sequence-valzer' or raise DataFormatError
|
|
214
|
+
def ensure_mod_sequence_valzer(num)
|
|
215
|
+
return num if valid_mod_sequence_valzer?(num)
|
|
216
|
+
raise DataFormatError,
|
|
217
|
+
"mod-sequence-valzer must be unsigned 64-bit integer: #{num}"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Like #ensure_number, but usable with numeric String input.
|
|
221
|
+
def coerce_number(num)
|
|
222
|
+
case num
|
|
223
|
+
when Integer then ensure_number num
|
|
224
|
+
when NUMBER_RE then ensure_number Integer num
|
|
225
|
+
else
|
|
226
|
+
raise DataFormatError, "%p is not a valid number" % [num]
|
|
227
|
+
end
|
|
228
|
+
end
|
|
206
229
|
|
|
207
|
-
|
|
208
|
-
|
|
230
|
+
# Like #ensure_nz_number, but usable with numeric String input.
|
|
231
|
+
def coerce_nz_number(num)
|
|
232
|
+
case num
|
|
233
|
+
when Integer then ensure_nz_number num
|
|
234
|
+
when NUMBER_RE then ensure_nz_number Integer num
|
|
235
|
+
else
|
|
236
|
+
raise DataFormatError, "%p is not a valid nz-number" % [num]
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Like #ensure_mod_sequence_value, but usable with numeric String input.
|
|
241
|
+
def coerce_mod_sequence_value(num)
|
|
242
|
+
case num
|
|
243
|
+
when Integer then ensure_mod_sequence_value num
|
|
244
|
+
when NUMBER_RE then ensure_mod_sequence_value Integer num
|
|
245
|
+
else
|
|
246
|
+
raise DataFormatError, "%p is not a valid mod-sequence-value" % [num]
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Like #ensure_mod_sequence_valzer, but usable with numeric String input.
|
|
251
|
+
def coerce_mod_sequence_valzer(num)
|
|
252
|
+
case num
|
|
253
|
+
when Integer then ensure_mod_sequence_valzer num
|
|
254
|
+
when NUMBER_RE then ensure_mod_sequence_valzer Integer num
|
|
255
|
+
else
|
|
256
|
+
raise DataFormatError, "%p is not a valid mod-sequence-valzer" % [num]
|
|
257
|
+
end
|
|
209
258
|
end
|
|
210
259
|
|
|
211
260
|
end
|
|
@@ -25,6 +25,12 @@ module Net
|
|
|
25
25
|
# Some search extensions may result in the server sending ESearchResult
|
|
26
26
|
# responses after the initiating command has completed. Use
|
|
27
27
|
# IMAP#add_response_handler to handle these responses.
|
|
28
|
+
#
|
|
29
|
+
# ==== Compatibility with SearchResult
|
|
30
|
+
#
|
|
31
|
+
# Note that both SearchResult and ESearchResult implement +each+, +to_a+,
|
|
32
|
+
# and +to_sequence_set+. These methods can be used regardless of whether
|
|
33
|
+
# the server returns +SEARCH+ or +ESEARCH+ data (or no data).
|
|
28
34
|
class ESearchResult < Data.define(:tag, :uid, :data)
|
|
29
35
|
def initialize(tag: nil, uid: nil, data: nil)
|
|
30
36
|
tag => String | nil; tag = -tag if tag
|
|
@@ -6,7 +6,6 @@ module Net
|
|
|
6
6
|
autoload :FetchData, "#{__dir__}/fetch_data"
|
|
7
7
|
autoload :UIDFetchData, "#{__dir__}/fetch_data"
|
|
8
8
|
autoload :SearchResult, "#{__dir__}/search_result"
|
|
9
|
-
autoload :UIDPlusData, "#{__dir__}/uidplus_data"
|
|
10
9
|
autoload :AppendUIDData, "#{__dir__}/uidplus_data"
|
|
11
10
|
autoload :CopyUIDData, "#{__dir__}/uidplus_data"
|
|
12
11
|
autoload :VanishedData, "#{__dir__}/vanished_data"
|
|
@@ -260,8 +259,8 @@ module Net
|
|
|
260
259
|
#
|
|
261
260
|
# === +UIDPLUS+ extension
|
|
262
261
|
# See {[RFC4315 §3]}[https://www.rfc-editor.org/rfc/rfc4315#section-3].
|
|
263
|
-
# * +APPENDUID+, #data is
|
|
264
|
-
# * +COPYUID+, #data is
|
|
262
|
+
# * +APPENDUID+, #data is AppendUIDData. See IMAP#append.
|
|
263
|
+
# * +COPYUID+, #data is CopyUIDData. See IMAP#copy.
|
|
265
264
|
# * +UIDNOTSTICKY+, #data is +nil+. See IMAP#select.
|
|
266
265
|
#
|
|
267
266
|
# === +SEARCHRES+ extension
|
|
@@ -2017,24 +2017,19 @@ module Net
|
|
|
2017
2017
|
CopyUID(validity, src_uids, dst_uids)
|
|
2018
2018
|
end
|
|
2019
2019
|
|
|
2020
|
-
def AppendUID(...) DeprecatedUIDPlus(...) || AppendUIDData.new(...) end
|
|
2021
|
-
def CopyUID(...) DeprecatedUIDPlus(...) || CopyUIDData.new(...) end
|
|
2022
|
-
|
|
2023
2020
|
# TODO: remove this code in the v0.6.0 release
|
|
2024
2021
|
def DeprecatedUIDPlus(validity, src_uids = nil, dst_uids)
|
|
2025
2022
|
return unless config.parser_use_deprecated_uidplus_data
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
dst_uids = dst_uids.each_ordered_number.to_a
|
|
2032
|
-
UIDPlusData.new(validity, src_uids, dst_uids)
|
|
2033
|
-
elsif config.parser_use_deprecated_uidplus_data != :up_to_max_size
|
|
2034
|
-
parse_error("uid-set is too large: %d > %d", count, max)
|
|
2035
|
-
end
|
|
2023
|
+
warn("#{Config}#parser_use_deprecated_uidplus_data is ignored " \
|
|
2024
|
+
"since v0.6.0. Disable this warning by setting " \
|
|
2025
|
+
"config.parser_use_deprecated_uidplus_data = false.",
|
|
2026
|
+
category: :deprecated, uplevel: 9)
|
|
2027
|
+
nil
|
|
2036
2028
|
end
|
|
2037
2029
|
|
|
2030
|
+
def AppendUID(...) DeprecatedUIDPlus(...) || AppendUIDData.new(...) end
|
|
2031
|
+
def CopyUID(...) DeprecatedUIDPlus(...) || CopyUIDData.new(...) end
|
|
2032
|
+
|
|
2038
2033
|
ADDRESS_REGEXP = /\G
|
|
2039
2034
|
\( (?: NIL | #{Patterns::QUOTED_rev2} ) # 1: NAME
|
|
2040
2035
|
\s (?: NIL | #{Patterns::QUOTED_rev2} ) # 2: ROUTE
|
|
@@ -7,6 +7,12 @@ module Net
|
|
|
7
7
|
# identifiers returned by Net::IMAP#uid_search.
|
|
8
8
|
#
|
|
9
9
|
# For backward compatibility, SearchResult inherits from Array.
|
|
10
|
+
#
|
|
11
|
+
# ==== Compatibility with ESearchResult
|
|
12
|
+
#
|
|
13
|
+
# Note that both SearchResult and ESearchResult implement +each+, +to_a+,
|
|
14
|
+
# and +to_sequence_set+. These methods can be used regardless of whether
|
|
15
|
+
# the server returns +SEARCH+ or +ESEARCH+ data (or no data).
|
|
10
16
|
class SearchResult < Array
|
|
11
17
|
|
|
12
18
|
# Returns a SearchResult populated with the given +seq_nums+.
|