Skip to content

Commit 42d0186

Browse files
committed
🚚 Move UIDPlusData to its own file
1 parent a55269a commit 42d0186

File tree

2 files changed

+57
-49
lines changed

2 files changed

+57
-49
lines changed

lib/net/imap/response_data.rb

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class IMAP < Protocol
77
autoload :UIDFetchData, "#{__dir__}/fetch_data"
88
autoload :SearchResult, "#{__dir__}/search_result"
99
autoload :SequenceSet, "#{__dir__}/sequence_set"
10+
autoload :UIDPlusData, "#{__dir__}/uidplus_data"
1011
autoload :VanishedData, "#{__dir__}/vanished_data"
1112

1213
# Net::IMAP::ContinuationRequest represents command continuation requests.
@@ -344,55 +345,6 @@ class ResponseCode < Struct.new(:name, :data)
344345
# code data can take.
345346
end
346347

347-
# UIDPlusData represents the ResponseCode#data that accompanies the
348-
# +APPENDUID+ and +COPYUID+ {response codes}[rdoc-ref:ResponseCode].
349-
#
350-
# A server that supports +UIDPLUS+ should send a UIDPlusData object inside
351-
# every TaggedResponse returned by the append[rdoc-ref:Net::IMAP#append],
352-
# copy[rdoc-ref:Net::IMAP#copy], move[rdoc-ref:Net::IMAP#move], {uid
353-
# copy}[rdoc-ref:Net::IMAP#uid_copy], and {uid
354-
# move}[rdoc-ref:Net::IMAP#uid_move] commands---unless the destination
355-
# mailbox reports +UIDNOTSTICKY+.
356-
#
357-
# == Required capability
358-
# Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
359-
# or +IMAP4rev2+ capability.
360-
#
361-
class UIDPlusData < Struct.new(:uidvalidity, :source_uids, :assigned_uids)
362-
##
363-
# method: uidvalidity
364-
# :call-seq: uidvalidity -> nonzero uint32
365-
#
366-
# The UIDVALIDITY of the destination mailbox.
367-
368-
##
369-
# method: source_uids
370-
# :call-seq: source_uids -> nil or an array of nonzero uint32
371-
#
372-
# The UIDs of the copied or moved messages.
373-
#
374-
# Note:: Returns +nil+ for Net::IMAP#append.
375-
376-
##
377-
# method: assigned_uids
378-
# :call-seq: assigned_uids -> an array of nonzero uint32
379-
#
380-
# The newly assigned UIDs of the copied, moved, or appended messages.
381-
#
382-
# Note:: This always returns an array, even when it contains only one UID.
383-
384-
##
385-
# :call-seq: uid_mapping -> nil or a hash
386-
#
387-
# Returns a hash mapping each source UID to the newly assigned destination
388-
# UID.
389-
#
390-
# Note:: Returns +nil+ for Net::IMAP#append.
391-
def uid_mapping
392-
source_uids&.zip(assigned_uids)&.to_h
393-
end
394-
end
395-
396348
# MailboxList represents the data of an untagged +LIST+ response, for a
397349
# _single_ mailbox path. IMAP#list returns an array of MailboxList objects.
398350
#

lib/net/imap/uidplus_data.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
module Net
4+
class IMAP < Protocol
5+
6+
# UIDPlusData represents the ResponseCode#data that accompanies the
7+
# +APPENDUID+ and +COPYUID+ {response codes}[rdoc-ref:ResponseCode].
8+
#
9+
# A server that supports +UIDPLUS+ should send a UIDPlusData object inside
10+
# every TaggedResponse returned by the append[rdoc-ref:Net::IMAP#append],
11+
# copy[rdoc-ref:Net::IMAP#copy], move[rdoc-ref:Net::IMAP#move], {uid
12+
# copy}[rdoc-ref:Net::IMAP#uid_copy], and {uid
13+
# move}[rdoc-ref:Net::IMAP#uid_move] commands---unless the destination
14+
# mailbox reports +UIDNOTSTICKY+.
15+
#
16+
# == Required capability
17+
# Requires either +UIDPLUS+ [RFC4315[https://www.rfc-editor.org/rfc/rfc4315]]
18+
# or +IMAP4rev2+ capability.
19+
#
20+
class UIDPlusData < Struct.new(:uidvalidity, :source_uids, :assigned_uids)
21+
##
22+
# method: uidvalidity
23+
# :call-seq: uidvalidity -> nonzero uint32
24+
#
25+
# The UIDVALIDITY of the destination mailbox.
26+
27+
##
28+
# method: source_uids
29+
# :call-seq: source_uids -> nil or an array of nonzero uint32
30+
#
31+
# The UIDs of the copied or moved messages.
32+
#
33+
# Note:: Returns +nil+ for Net::IMAP#append.
34+
35+
##
36+
# method: assigned_uids
37+
# :call-seq: assigned_uids -> an array of nonzero uint32
38+
#
39+
# The newly assigned UIDs of the copied, moved, or appended messages.
40+
#
41+
# Note:: This always returns an array, even when it contains only one UID.
42+
43+
##
44+
# :call-seq: uid_mapping -> nil or a hash
45+
#
46+
# Returns a hash mapping each source UID to the newly assigned destination
47+
# UID.
48+
#
49+
# Note:: Returns +nil+ for Net::IMAP#append.
50+
def uid_mapping
51+
source_uids&.zip(assigned_uids)&.to_h
52+
end
53+
end
54+
55+
end
56+
end

0 commit comments

Comments
 (0)