Skip to content

Commit 0ec4fd3

Browse files
committed
🥅 Validate #setquota storage limit argument
There's no reason to use `RawData` for this. We can use Net::IMAP's standard command argument formatting to send a parenthesized list.
1 parent a4f7649 commit 0ec4fd3

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/net/imap.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,11 @@ def getquota(quota_root)
19261926
# Sends a {SETQUOTA command [RFC2087 §4.1]}[https://www.rfc-editor.org/rfc/rfc2087#section-4.1]
19271927
# along with the specified +quota_root+ and +storage_limit+. If
19281928
# +storage_limit+ is +nil+, resource limits are unset for that quota root.
1929-
# Otherwise, it sets the +STORAGE+ resource limit.
1929+
# If +storage_limit+ is a number, it sets the +STORAGE+ resource limit.
1930+
#
1931+
# imap.setquota "#user/alice", 100
1932+
# imap.getquota "#user/alice"
1933+
# # => [#<struct Net::IMAP::MailboxQuota mailbox="#user/alice" usage=54 quota=100>]
19301934
#
19311935
# Typically one needs to be logged in as a server admin for this to work.
19321936
#
@@ -1942,11 +1946,11 @@ def getquota(quota_root)
19421946
# resource type.
19431947
def setquota(quota_root, storage_limit)
19441948
if storage_limit.nil?
1945-
list = '()'
1949+
list = []
19461950
else
1947-
list = '(STORAGE ' + storage_limit.to_s + ')'
1951+
list = ["STORAGE", NumValidator.coerce_number64(storage_limit)]
19481952
end
1949-
send_command("SETQUOTA", quota_root, RawData.new(list))
1953+
send_command("SETQUOTA", quota_root, list)
19501954
end
19511955

19521956
# Sends a {SETACL command [RFC4314 §3.1]}[https://www.rfc-editor.org/rfc/rfc4314#section-3.1]

test/net/imap/test_imap_quota.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ class IMAPQuotaTest < Net::IMAP::TestCase
2828
rcvd_cmd = server.commands.pop
2929
assert_equal "SETQUOTA", rcvd_cmd.name
3030
assert_equal '"" ()', rcvd_cmd.args
31+
32+
assert_raise_with_message(Net::IMAP::DataFormatError,
33+
"512.0 is not a valid number64") do
34+
imap.setquota "INBOX", 512.0
35+
end
36+
assert_raise_with_message(Net::IMAP::DataFormatError,
37+
'"512 620" is not a valid number64') do
38+
imap.setquota "INBOX", "512 620"
39+
end
3140
end
3241
end
3342
end

0 commit comments

Comments
 (0)