Skip to content

Commit 022048e

Browse files
committed
🐛 Fix broken QUOTA/QUOTAROOT response parsing
This has been broken since #203. There was no test coverage over the QUOTA response parser, so I copied the example responses from RFC9208. All but one of the examples can be parsed without any further updates to the parser.
1 parent cc19514 commit 022048e

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

lib/net/imap/response_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ def mailbox_list
13701370
MailboxList.new(attr, delim, name)
13711371
end
13721372

1373-
def getquota_response
1373+
def quota_response
13741374
# If quota never established, get back
13751375
# `NO Quota root does not exist'.
13761376
# If quota removed, get `()' after the
@@ -1403,7 +1403,7 @@ def getquota_response
14031403
end
14041404
end
14051405

1406-
def getquotaroot_response
1406+
def quotaroot_response
14071407
# Similar to getquota, but only admin can use getquota.
14081408
token = match(T_ATOM)
14091409
name = token.value.upcase
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
:tests:
3+
4+
rfc9208_4.1.1_example:
5+
:response: "* QUOTA \"!partition/sda4\" (STORAGE 104 10923847)\r\n"
6+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
7+
name: QUOTA
8+
data: !ruby/struct:Net::IMAP::MailboxQuota
9+
mailbox: "!partition/sda4"
10+
usage: '104'
11+
quota: '10923847'
12+
raw_data: "* QUOTA \"!partition/sda4\" (STORAGE 104 10923847)\r\n"
13+
14+
rfc9208_4.1.2_example_1:
15+
:response: "* QUOTAROOT INBOX \"#user/alice\" \"!partition/sda4\"\r\n"
16+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
17+
name: QUOTAROOT
18+
data: !ruby/struct:Net::IMAP::MailboxQuotaRoot
19+
mailbox: INBOX
20+
quotaroots:
21+
- "#user/alice"
22+
- "!partition/sda4"
23+
raw_data: "* QUOTAROOT INBOX \"#user/alice\" \"!partition/sda4\"\r\n"
24+
25+
rfc9208_4.1.2_example_2:
26+
:response: "* QUOTA \"#user/alice\" (MESSAGE 42 1000)\r\n"
27+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
28+
name: QUOTA
29+
data: !ruby/struct:Net::IMAP::MailboxQuota
30+
mailbox: "#user/alice"
31+
usage: '42'
32+
quota: '1000'
33+
raw_data: "* QUOTA \"#user/alice\" (MESSAGE 42 1000)\r\n"
34+
35+
# rfc9208_4.1.3_example_1:
36+
# :response: "* QUOTA \"#user/alice\" (STORAGE 54 111 MESSAGE 42 1000)\r\n"
37+
38+
rfc9208_4.1.4_example:
39+
:response: "* STATUS INBOX (MESSAGES 12 DELETED 4 DELETED-STORAGE 8)\r\n"
40+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
41+
name: STATUS
42+
data: !ruby/struct:Net::IMAP::StatusData
43+
mailbox: INBOX
44+
attr:
45+
MESSAGES: 12
46+
DELETED: 4
47+
DELETED-STORAGE: 8
48+
raw_data: "* STATUS INBOX (MESSAGES 12 DELETED 4 DELETED-STORAGE 8)\r\n"
49+
50+
rfc9208_4.2.1_example:
51+
:response: "* QUOTA \"\" (STORAGE 10 512)\r\n"
52+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
53+
name: QUOTA
54+
data: !ruby/struct:Net::IMAP::MailboxQuota
55+
mailbox: ''
56+
usage: '10'
57+
quota: '512'
58+
raw_data: "* QUOTA \"\" (STORAGE 10 512)\r\n"
59+
60+
rfc9208_4.2.2_example_1:
61+
:response: "* QUOTAROOT INBOX \"\"\r\n"
62+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
63+
name: QUOTAROOT
64+
data: !ruby/struct:Net::IMAP::MailboxQuotaRoot
65+
mailbox: INBOX
66+
quotaroots:
67+
- ''
68+
raw_data: "* QUOTAROOT INBOX \"\"\r\n"
69+
70+
rfc9208_4.2.2_example_2:
71+
:response: "* QUOTAROOT comp.mail.mime\r\n"
72+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
73+
name: QUOTAROOT
74+
data: !ruby/struct:Net::IMAP::MailboxQuotaRoot
75+
mailbox: comp.mail.mime
76+
quotaroots: []
77+
raw_data: "* QUOTAROOT comp.mail.mime\r\n"
78+
79+
rfc9208_4.3.1_example_1:
80+
:response: "A003 NO [OVERQUOTA] APPEND Failed\r\n"
81+
:expected: !ruby/struct:Net::IMAP::TaggedResponse
82+
tag: A003
83+
name: 'NO'
84+
data: !ruby/struct:Net::IMAP::ResponseText
85+
code: !ruby/struct:Net::IMAP::ResponseCode
86+
name: OVERQUOTA
87+
data:
88+
text: APPEND Failed
89+
raw_data: "A003 NO [OVERQUOTA] APPEND Failed\r\n"
90+
91+
rfc9208_4.3.1_example_2:
92+
:response: "* NO [OVERQUOTA] Soft quota has been exceeded\r\n"
93+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
94+
name: 'NO'
95+
data: !ruby/struct:Net::IMAP::ResponseText
96+
code: !ruby/struct:Net::IMAP::ResponseCode
97+
name: OVERQUOTA
98+
data:
99+
text: Soft quota has been exceeded
100+
raw_data: "* NO [OVERQUOTA] Soft quota has been exceeded\r\n"

test/net/imap/test_imap_response_parser.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def teardown
9393
# RFC 8474: OBJECTID responses
9494
generate_tests_from fixture_file: "rfc8474_objectid_responses.yml"
9595

96+
# RFC 9208: QUOTA extension
97+
generate_tests_from fixture_file: "rfc9208_quota_responses.yml"
98+
9699
############################################################################
97100
# Workarounds or unspecified extensions:
98101
generate_tests_from fixture_file: "quirky_behaviors.yml"

0 commit comments

Comments
 (0)