Skip to content

Commit 3116c7d

Browse files
committed
šŸ’ pick 0ec4fd3: šŸ„… Validate #setquota storage limit argument [backports #659]
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 bbe901a commit 3116c7d

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

ā€Žlib/net/imap.rbā€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,11 @@ def getquota(quota_root)
18971897
# Sends a {SETQUOTA command [RFC2087 §4.1]}[https://www.rfc-editor.org/rfc/rfc2087#section-4.1]
18981898
# along with the specified +quota_root+ and +storage_limit+. If
18991899
# +storage_limit+ is +nil+, resource limits are unset for that quota root.
1900-
# Otherwise, it sets the +STORAGE+ resource limit.
1900+
# If +storage_limit+ is a number, it sets the +STORAGE+ resource limit.
1901+
#
1902+
# imap.setquota "#user/alice", 100
1903+
# imap.getquota "#user/alice"
1904+
# # => [#<struct Net::IMAP::MailboxQuota mailbox="#user/alice" usage=54 quota=100>]
19011905
#
19021906
# Typically one needs to be logged in as a server admin for this to work.
19031907
#
@@ -1913,11 +1917,11 @@ def getquota(quota_root)
19131917
# resource type.
19141918
def setquota(quota_root, storage_limit)
19151919
if storage_limit.nil?
1916-
list = '()'
1920+
list = []
19171921
else
1918-
list = '(STORAGE ' + storage_limit.to_s + ')'
1922+
list = ["STORAGE", Integer(storage_limit)]
19191923
end
1920-
send_command("SETQUOTA", quota_root, RawData.new(list))
1924+
send_command("SETQUOTA", quota_root, list)
19211925
end
19221926

19231927
# 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ 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(ArgumentError, /invalid value for Integer/) do
33+
imap.setquota "INBOX", "512 620"
34+
end
3135
end
3236
end
3337
end

0 commit comments

Comments
Ā (0)