Closed nevans closed 1 month ago
Any thoughts? Would you like me to add some tests to simulate the potential return values?
net-imap
)net-imap
<= 0.3
)net-imap
, >= 0.4.8, <= 0.4.9
, and maybe >= 0.6
or >= 0.7
)to_a
for backward-compatibility (IMAP4rev2 servers, net-imap
>= 0.5
)Looks mergeable to me 👍🏻
Thanks for the extensive writeup!
The code had several issues with existing IMAP UID search:
nil
when the server returns nothing. (>= v0.4 returns an empty array when the server returns nothing.)SearchResult
.SearchResult
inherits fromArray
, but because it's frozen, mutating it withreverse!
results in an exception. See https://github.com/ruby/net-imap/issues/262. (v0.4.10 and above doesn't freeze SearchResult.)ESEARCH
results, but those will be returned as anESearchResult
struct (probably frozen).IMAP4rev1
servers shouldn't returnESEARCH
unless the client has activated that extension, butIMAP4rev2
servers will always returnESEARCH
.UID SEARCH
. Almost all servers do return sorted UIDs, most of the time. But it isn't 100% reliable.The fix is simple:
#to_a
to convert bothnil
andESearchResult
into an array of UIDs.#sort
to ensure the UIDs are sorted. This also returns a new array, without mutating the original (which may be frozen).