Skip to content

Commit d2b2360

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 381f539 commit d2b2360

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
@@ -1811,7 +1811,11 @@ def getquota(quota_root)
18111811
# Sends a {SETQUOTA command [RFC2087 §4.1]}[https://www.rfc-editor.org/rfc/rfc2087#section-4.1]
18121812
# along with the specified +quota_root+ and +storage_limit+. If
18131813
# +storage_limit+ is +nil+, resource limits are unset for that quota root.
1814-
# Otherwise, it sets the +STORAGE+ resource limit.
1814+
# If +storage_limit+ is a number, it sets the +STORAGE+ resource limit.
1815+
#
1816+
# imap.setquota "#user/alice", 100
1817+
# imap.getquota "#user/alice"
1818+
# # => [#<struct Net::IMAP::MailboxQuota mailbox="#user/alice" usage=54 quota=100>]
18151819
#
18161820
# Typically one needs to be logged in as a server admin for this to work.
18171821
#
@@ -1827,11 +1831,11 @@ def getquota(quota_root)
18271831
# for each supported resource type.
18281832
def setquota(quota_root, storage_limit)
18291833
if storage_limit.nil?
1830-
list = '()'
1834+
list = []
18311835
else
1832-
list = '(STORAGE ' + storage_limit.to_s + ')'
1836+
list = ["STORAGE", Integer(storage_limit)]
18331837
end
1834-
send_command("SETQUOTA", quota_root, RawData.new(list))
1838+
send_command("SETQUOTA", quota_root, list)
18351839
end
18361840

18371841
# 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
@@ -43,6 +43,10 @@ def teardown
4343
rcvd_cmd = server.commands.pop
4444
assert_equal "SETQUOTA", rcvd_cmd.name
4545
assert_equal '"" ()', rcvd_cmd.args
46+
47+
assert_raise_with_message(ArgumentError, /invalid value for Integer/) do
48+
imap.setquota "INBOX", "512 620"
49+
end
4650
end
4751
end
4852
end

0 commit comments

Comments
Ā (0)