net-imap 0.4.22 → 0.5.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.

Potentially problematic release.


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

@@ -1,326 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Net
4
- class IMAP < Protocol
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
- # >>>
106
- # *NOTE:* <em>AppendUIDData will replace UIDPlusData for +APPENDUID+ in the
107
- # +0.6.0+ release.</em> To use AppendUIDData before +0.6.0+, set
108
- # Config#parser_use_deprecated_uidplus_data to +false+.
109
- #
110
- # AppendUIDData represents the ResponseCode#data that accompanies the
111
- # +APPENDUID+ {response code}[rdoc-ref:ResponseCode].
112
- #
113
- # A server that supports +UIDPLUS+ (or +IMAP4rev2+) should send
114
- # AppendUIDData inside every TaggedResponse returned by the
115
- # append[rdoc-ref:Net::IMAP#append] command---unless the target mailbox
116
- # reports +UIDNOTSTICKY+.
117
- #
118
- # == Required capability
119
- # Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
120
- # or +IMAP4rev2+ capability.
121
- class AppendUIDData < Data_define__uidvalidity___assigned_uids_
122
- def initialize(uidvalidity:, assigned_uids:)
123
- uidvalidity = Integer(uidvalidity)
124
- assigned_uids = SequenceSet[assigned_uids]
125
- NumValidator.ensure_nz_number(uidvalidity)
126
- if assigned_uids.include_star?
127
- raise DataFormatError, "uid-set cannot contain '*'"
128
- end
129
- super
130
- end
131
-
132
- ##
133
- # attr_reader: uidvalidity
134
- # :call-seq: uidvalidity -> nonzero uint32
135
- #
136
- # The UIDVALIDITY of the destination mailbox.
137
-
138
- ##
139
- # attr_reader: assigned_uids
140
- #
141
- # A SequenceSet with the newly assigned UIDs of the appended messages.
142
-
143
- # Returns the number of messages that have been appended.
144
- def size
145
- assigned_uids.count_with_duplicates
146
- end
147
- end
148
-
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
- # >>>
194
- # *NOTE:* <em>CopyUIDData will replace UIDPlusData for +COPYUID+ in the
195
- # +0.6.0+ release.</em> To use CopyUIDData before +0.6.0+, set
196
- # Config#parser_use_deprecated_uidplus_data to +false+.
197
- #
198
- # CopyUIDData represents the ResponseCode#data that accompanies the
199
- # +COPYUID+ {response code}[rdoc-ref:ResponseCode].
200
- #
201
- # A server that supports +UIDPLUS+ (or +IMAP4rev2+) should send CopyUIDData
202
- # in response to
203
- # copy[rdoc-ref:Net::IMAP#copy], {uid_copy}[rdoc-ref:Net::IMAP#uid_copy],
204
- # move[rdoc-ref:Net::IMAP#copy], and {uid_move}[rdoc-ref:Net::IMAP#uid_move]
205
- # commands---unless the destination mailbox reports +UIDNOTSTICKY+.
206
- #
207
- # Note that copy[rdoc-ref:Net::IMAP#copy] and
208
- # {uid_copy}[rdoc-ref:Net::IMAP#uid_copy] return CopyUIDData in their
209
- # TaggedResponse. But move[rdoc-ref:Net::IMAP#copy] and
210
- # {uid_move}[rdoc-ref:Net::IMAP#uid_move] _should_ send CopyUIDData in an
211
- # UntaggedResponse response before sending their TaggedResponse. However
212
- # some servers do send CopyUIDData in the TaggedResponse for +MOVE+
213
- # commands---this complies with the older +UIDPLUS+ specification but is
214
- # discouraged by the +MOVE+ extension and disallowed by +IMAP4rev2+.
215
- #
216
- # == Required capability
217
- # Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
218
- # or +IMAP4rev2+ capability.
219
- class CopyUIDData < Data_define__uidvalidity___source_uids___assigned_uids_
220
- def initialize(uidvalidity:, source_uids:, assigned_uids:)
221
- uidvalidity = Integer(uidvalidity)
222
- source_uids = SequenceSet[source_uids]
223
- assigned_uids = SequenceSet[assigned_uids]
224
- NumValidator.ensure_nz_number(uidvalidity)
225
- if source_uids.include_star? || assigned_uids.include_star?
226
- raise DataFormatError, "uid-set cannot contain '*'"
227
- elsif source_uids.count_with_duplicates != assigned_uids.count_with_duplicates
228
- raise DataFormatError, "mismatched uid-set sizes for %s and %s" % [
229
- source_uids, assigned_uids
230
- ]
231
- end
232
- super
233
- end
234
-
235
- ##
236
- # attr_reader: uidvalidity
237
- #
238
- # The +UIDVALIDITY+ of the destination mailbox (a nonzero unsigned 32 bit
239
- # integer).
240
-
241
- ##
242
- # attr_reader: source_uids
243
- #
244
- # A SequenceSet with the original UIDs of the copied or moved messages.
245
-
246
- ##
247
- # attr_reader: assigned_uids
248
- #
249
- # A SequenceSet with the newly assigned UIDs of the copied or moved
250
- # messages.
251
-
252
- # Returns the number of messages that have been copied or moved.
253
- # source_uids and the assigned_uids will both the same number of UIDs.
254
- def size
255
- assigned_uids.count_with_duplicates
256
- end
257
-
258
- # :call-seq:
259
- # assigned_uid_for(source_uid) -> uid
260
- # self[source_uid] -> uid
261
- #
262
- # Returns the UID in the destination mailbox for the message that was
263
- # copied from +source_uid+ in the source mailbox.
264
- #
265
- # This is the reverse of #source_uid_for.
266
- #
267
- # Related: source_uid_for, each_uid_pair, uid_mapping
268
- def assigned_uid_for(source_uid)
269
- idx = source_uids.find_ordered_index(source_uid) and
270
- assigned_uids.ordered_at(idx)
271
- end
272
- alias :[] :assigned_uid_for
273
-
274
- # :call-seq:
275
- # source_uid_for(assigned_uid) -> uid
276
- #
277
- # Returns the UID in the source mailbox for the message that was copied to
278
- # +assigned_uid+ in the source mailbox.
279
- #
280
- # This is the reverse of #assigned_uid_for.
281
- #
282
- # Related: assigned_uid_for, each_uid_pair, uid_mapping
283
- def source_uid_for(assigned_uid)
284
- idx = assigned_uids.find_ordered_index(assigned_uid) and
285
- source_uids.ordered_at(idx)
286
- end
287
-
288
- # Yields a pair of UIDs for each copied message. The first is the
289
- # message's UID in the source mailbox and the second is the UID in the
290
- # destination mailbox.
291
- #
292
- # Returns an enumerator when no block is given.
293
- #
294
- # Please note the warning on uid_mapping before calling methods like
295
- # +to_h+ or +to_a+ on the returned enumerator.
296
- #
297
- # Related: uid_mapping, assigned_uid_for, source_uid_for
298
- def each_uid_pair
299
- return enum_for(__method__) unless block_given?
300
- source_uids.each_ordered_number.lazy
301
- .zip(assigned_uids.each_ordered_number.lazy) do
302
- |source_uid, assigned_uid|
303
- yield source_uid, assigned_uid
304
- end
305
- end
306
- alias each_pair each_uid_pair
307
- alias each each_uid_pair
308
-
309
- # :call-seq: uid_mapping -> hash
310
- #
311
- # Returns a hash mapping each source UID to the newly assigned destination
312
- # UID.
313
- #
314
- # <em>*Warning:*</em> The hash that is created may consume _much_ more
315
- # memory than the data used to create it. When handling responses from an
316
- # untrusted server, check #size before calling this method.
317
- #
318
- # Related: each_uid_pair, assigned_uid_for, source_uid_for
319
- def uid_mapping
320
- each_uid_pair.to_h
321
- end
322
-
323
- end
324
-
325
- end
326
- end