Skip to content

Commit 6acb125

Browse files
committed
🥅 Work around missing server responses
By converting all of the internal `@responses.delete(type)` to `clear_responses(type)`, we get empty arrays and don't need nil-checks. Fixes #190.
1 parent c3f7e7c commit 6acb125

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/net/imap.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ def clear_cached_capabilities
10191019
def capability
10201020
synchronize do
10211021
send_command("CAPABILITY")
1022-
@capabilities = @responses.delete("CAPABILITY").last.freeze
1022+
@capabilities = clear_responses("CAPABILITY").last.freeze
10231023
end
10241024
end
10251025

@@ -1048,7 +1048,7 @@ def capability
10481048
def id(client_id=nil)
10491049
synchronize do
10501050
send_command("ID", ClientID.new(client_id))
1051-
@responses.delete("ID")&.last
1051+
clear_responses("ID").last
10521052
end
10531053
end
10541054

@@ -1444,7 +1444,7 @@ def unsubscribe(mailbox)
14441444
def list(refname, mailbox)
14451445
synchronize do
14461446
send_command("LIST", refname, mailbox)
1447-
return @responses.delete("LIST")
1447+
clear_responses("LIST")
14481448
end
14491449
end
14501450

@@ -1501,7 +1501,7 @@ def list(refname, mailbox)
15011501
def namespace
15021502
synchronize do
15031503
send_command("NAMESPACE")
1504-
return @responses.delete("NAMESPACE")[-1]
1504+
clear_responses("NAMESPACE").last
15051505
end
15061506
end
15071507

@@ -1545,7 +1545,7 @@ def namespace
15451545
def xlist(refname, mailbox)
15461546
synchronize do
15471547
send_command("XLIST", refname, mailbox)
1548-
return @responses.delete("XLIST")
1548+
clear_responses("XLIST")
15491549
end
15501550
end
15511551

@@ -1564,8 +1564,8 @@ def getquotaroot(mailbox)
15641564
synchronize do
15651565
send_command("GETQUOTAROOT", mailbox)
15661566
result = []
1567-
result.concat(@responses.delete("QUOTAROOT"))
1568-
result.concat(@responses.delete("QUOTA"))
1567+
result.concat(clear_responses("QUOTAROOT"))
1568+
result.concat(clear_responses("QUOTA"))
15691569
return result
15701570
end
15711571
end
@@ -1584,7 +1584,7 @@ def getquotaroot(mailbox)
15841584
def getquota(mailbox)
15851585
synchronize do
15861586
send_command("GETQUOTA", mailbox)
1587-
return @responses.delete("QUOTA")
1587+
clear_responses("QUOTA")
15881588
end
15891589
end
15901590

@@ -1640,7 +1640,7 @@ def setacl(mailbox, user, rights)
16401640
def getacl(mailbox)
16411641
synchronize do
16421642
send_command("GETACL", mailbox)
1643-
return @responses.delete("ACL")[-1]
1643+
clear_responses("ACL").last
16441644
end
16451645
end
16461646

@@ -1655,7 +1655,7 @@ def getacl(mailbox)
16551655
def lsub(refname, mailbox)
16561656
synchronize do
16571657
send_command("LSUB", refname, mailbox)
1658-
return @responses.delete("LSUB")
1658+
clear_responses("LSUB")
16591659
end
16601660
end
16611661

@@ -1679,7 +1679,7 @@ def lsub(refname, mailbox)
16791679
def status(mailbox, attr)
16801680
synchronize do
16811681
send_command("STATUS", mailbox, attr)
1682-
return @responses.delete("STATUS")[-1].attr
1682+
clear_responses("STATUS").last&.attr
16831683
end
16841684
end
16851685

@@ -1768,7 +1768,7 @@ def unselect
17681768
def expunge
17691769
synchronize do
17701770
send_command("EXPUNGE")
1771-
return @responses.delete("EXPUNGE")
1771+
clear_responses("EXPUNGE")
17721772
end
17731773
end
17741774

@@ -1800,7 +1800,7 @@ def expunge
18001800
def uid_expunge(uid_set)
18011801
synchronize do
18021802
send_command("UID EXPUNGE", MessageSet.new(uid_set))
1803-
return @responses.delete("EXPUNGE")
1803+
clear_responses("EXPUNGE")
18041804
end
18051805
end
18061806

@@ -2188,7 +2188,7 @@ def enable(*capabilities)
21882188
.join(' ')
21892189
synchronize do
21902190
send_command("ENABLE #{capabilities}")
2191-
result = @responses.delete("ENABLED")[-1]
2191+
result = clear_responses("ENABLED").last
21922192
@utf8_strings ||= result.include? "UTF8=ACCEPT"
21932193
@utf8_strings ||= result.include? "IMAP4REV2"
21942194
result
@@ -2641,7 +2641,7 @@ def search_internal(cmd, keys, charset)
26412641
else
26422642
send_command(cmd, *keys)
26432643
end
2644-
return @responses.delete("SEARCH")[-1]
2644+
clear_responses("SEARCH").last
26452645
end
26462646
end
26472647

@@ -2656,13 +2656,13 @@ def fetch_internal(cmd, set, attr, mod = nil)
26562656
end
26572657

26582658
synchronize do
2659-
@responses.delete("FETCH")
2659+
clear_responses("FETCH")
26602660
if mod
26612661
send_command(cmd, MessageSet.new(set), attr, mod)
26622662
else
26632663
send_command(cmd, MessageSet.new(set), attr)
26642664
end
2665-
return @responses.delete("FETCH")
2665+
clear_responses("FETCH")
26662666
end
26672667
end
26682668

@@ -2671,9 +2671,9 @@ def store_internal(cmd, set, attr, flags)
26712671
attr = RawData.new(attr)
26722672
end
26732673
synchronize do
2674-
@responses.delete("FETCH")
2674+
clear_responses("FETCH")
26752675
send_command(cmd, MessageSet.new(set), attr, flags)
2676-
return @responses.delete("FETCH")
2676+
clear_responses("FETCH")
26772677
end
26782678
end
26792679

@@ -2690,7 +2690,7 @@ def sort_internal(cmd, sort_keys, search_keys, charset)
26902690
normalize_searching_criteria(search_keys)
26912691
synchronize do
26922692
send_command(cmd, sort_keys, charset, *search_keys)
2693-
return @responses.delete("SORT")[-1]
2693+
clear_responses("SORT").last
26942694
end
26952695
end
26962696

@@ -2703,7 +2703,7 @@ def thread_internal(cmd, algorithm, search_keys, charset)
27032703
normalize_searching_criteria(search_keys)
27042704
synchronize do
27052705
send_command(cmd, algorithm, charset, *search_keys)
2706-
@responses.delete("THREAD")[-1]
2706+
clear_responses("THREAD").last
27072707
end
27082708
end
27092709

0 commit comments

Comments
 (0)