Skip to content

Commit 7f0ea41

Browse files
committed
🥅 Raise ArgumentError for #fetch with partial
The `PARTIAL` fetch modifier is only valid for `UID FETCH`. This raises an `ArgumentError`, rather than send an invalid command to the server.
1 parent 96f5008 commit 7f0ea41

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,9 @@ def search_internal(cmd, ...)
36843684
end
36853685

36863686
def fetch_internal(cmd, set, attr, mod = nil, partial: nil, changedsince: nil)
3687+
if partial && !cmd.start_with?("UID ")
3688+
raise ArgumentError, "partial can only be used with uid_fetch"
3689+
end
36873690
set = SequenceSet[set]
36883691
if partial
36893692
mod ||= []

test/net/imap/test_imap_fetch.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
class IMAPFetchTest < Net::IMAP::TestCase
88
include Net::IMAP::FakeServer::TestHelper
99

10+
test "argument errors" do
11+
with_fake_server select: "inbox" do |_, imap|
12+
assert_raise_with_message(ArgumentError, /\Apartial.*uid_fetch/) do
13+
imap.fetch(1, "FAST", partial: 1..10)
14+
end
15+
end
16+
end
17+
1018
test "#fetch with FETCH responses" do
1119
with_fake_server select: "inbox" do |server, imap|
1220
server.on("FETCH") do |resp|

0 commit comments

Comments
 (0)