Skip to content

💥 Replace MessageSet with SequenceSet #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ def expunge
# [RFC4315[https://www.rfc-editor.org/rfc/rfc4315.html]].
def uid_expunge(uid_set)
synchronize do
send_command("UID EXPUNGE", MessageSet.new(uid_set))
send_command("UID EXPUNGE", SequenceSet.new(uid_set))
clear_responses("EXPUNGE")
end
end
Expand Down Expand Up @@ -2912,17 +2912,17 @@ def fetch_internal(cmd, set, attr, mod = nil, changedsince: nil)
synchronize do
clear_responses("FETCH")
if mod
send_command(cmd, MessageSet.new(set), attr, mod)
send_command(cmd, SequenceSet.new(set), attr, mod)
else
send_command(cmd, MessageSet.new(set), attr)
send_command(cmd, SequenceSet.new(set), attr)
end
clear_responses("FETCH")
end
end

def store_internal(cmd, set, attr, flags, unchangedsince: nil)
attr = RawData.new(attr) if attr.instance_of?(String)
args = [MessageSet.new(set)]
args = [SequenceSet.new(set)]
args << ["UNCHANGEDSINCE", Integer(unchangedsince)] if unchangedsince
args << attr << flags
synchronize do
Expand All @@ -2933,7 +2933,7 @@ def store_internal(cmd, set, attr, flags, unchangedsince: nil)
end

def copy_internal(cmd, set, mailbox)
send_command(cmd, MessageSet.new(set), mailbox)
send_command(cmd, SequenceSet.new(set), mailbox)
end

def sort_internal(cmd, sort_keys, search_keys, charset)
Expand Down Expand Up @@ -2964,7 +2964,7 @@ def normalize_searching_criteria(keys)
keys.collect! do |i|
case i
when -1, Range, Array
MessageSet.new(i)
SequenceSet.new(i)
else
i
end
Expand Down
10 changes: 10 additions & 0 deletions lib/net/imap/command_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def initialize(data)
end
end

# *DEPRECATED*. Replaced by SequenceSet.
class MessageSet # :nodoc:
def send_data(imap, tag)
imap.__send__(:put_string, format_internal(@data))
Expand All @@ -192,6 +193,15 @@ def validate

def initialize(data)
@data = data
warn "DEPRECATED: #{MessageSet} should be replaced with #{SequenceSet}."
begin
# to ensure the input works with SequenceSet, too
SequenceSet.new(data)
rescue
warn "MessageSet input is incompatible with SequenceSet: [%s] %s" % [
$!.class, $!.message
]
end
end

def format_internal(data)
Expand Down
23 changes: 13 additions & 10 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,17 +626,20 @@ def test_send_invalid_number
imap.__send__(:send_command, "TEST", 2**32)
end
# MessageSet numbers may be non-zero uint32
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(-1))
end
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(0))
end
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(1))
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(2**32 - 1))
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(2**32))
stderr = EnvUtil.verbose_warning do
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(-1))
end
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(0))
end
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(1))
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(2**32 - 1))
assert_raise(Net::IMAP::DataFormatError) do
imap.__send__(:send_command, "TEST", Net::IMAP::MessageSet.new(2**32))
end
end
assert_match(/DEPRECATED:.+MessageSet.+replace.+with.+SequenceSet/, stderr)
# SequenceSet numbers may be non-zero uint3, and -1 is translated to *
imap.__send__(:send_command, "TEST", Net::IMAP::SequenceSet.new(-1))
assert_raise(Net::IMAP::DataFormatError) do
Expand Down