-
Notifications
You must be signed in to change notification settings - Fork 34
✨ Add basic ESearch support #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
Author
|
FWIW: I discovered in testing that Yahoo does not return ESEARCH results when |
59137e9 to
7dc2006
Compare
nevans
added a commit
to nevans/net-imap
that referenced
this pull request
Nov 8, 2024
This affects `#search`, `#uid_search`, `#sort`, `#uid_sort`, `#thread`,
and `#uid_thread`.
Prior to this, sending a parenthesized list in the search criteria for
any of these commands required the use of strings, which are converted
to `RawData`, which has security implications with untrusted inputs.
With this change, arrays will only be converted into SequenceSet when
_every_ element in the array is a valid SequenceSet input. Otherwise,
the array will be left alone, which allows us to send parenthesized
lists without using strings and RawData.
For example, some searches this change enables:
* Combining criteria to pass into `OR`, `NOT`, `FUZZY`, etc.
* `search(["not", %w(flagged unread)])`
converts to: `SEARCH not (flagged unread)`
* Adding return options (we should also add a return kwarg).
* `uid_search(["RETURN", ["PARTIAL", 1..50], "UID", 12345..67890])`
converts to: `UID SEARCH RETURN (PARTIAL 1:50) UID 12345:67890`
* Note that `PARTIAL` supports negative ranges, which can't be coerced
to SequenceSet. They'll need to be sent as strings, for now.
* Note that searches with return options should return ESEARCH
results, which are currently unsupported. See ruby#333.
This _should_ be backward compatible: previously these inputs would
raise an exception.
d86e849 to
efd2760
Compare
efd2760 to
0587646
Compare
fd7b0f9 to
a535b1f
Compare
acdb6f8 to
d38357b
Compare
f4cabfa to
b486078
Compare
Parses +ESEARCH+ into ESearchResult, with support for generic RFC4466 syntax and RFC4731 `ESEARCH` return data. For compatibility, `ESearchResult#to_a` returns an array of integers (sequence numbers or UIDs) whenever any `ALL` result is available.
b486078 to
35ab834
Compare
If the server returns both `ESEARCH` and `SEARCH`, both are cleared from the responses hash, but only the `ESEARCH` is returned. When the server doesn't send any search responses: If return options are passed, return an empty ESearchResult. It will have the appropriate `tag` and `uid` values, but no `data`. Otherwise return an empty `SearchResult`.
b1d8cc2 to
e11afcc
Compare
This also extracts the `return` kwarg out of the `criteria` array, so it can be processed differently.
This looks like a bug in prism: ``` $ rbenv shell 3.4.0-rc1 $ ruby -e 'pp ([["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]])' false $ ruby --parser=parse.y -e 'pp ([["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]])' true ```
e11afcc to
e088eb1
Compare
This was referenced Jan 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #115.
Parse
ESEARCHintoESearchResult, with support for generic RFC4466 syntax and RFC4731ESEARCHreturn data. For compatibility,ESearchResult#to_areturns an array of integers (sequence numbers or UIDs) whenever anyALLresult is available.Gather ESEARCH response to #search/#uid_search. If the server returns both
ESEARCHandSEARCH, both are cleared from the responses hash, but only theESEARCHis returned.When the server doesn't send any search responses and return options are passed, return an empty ESearchResult. This empty result will have the appropriate
taganduidvalues, but nodata. Otherwise return an emptySearchResult.Add keyword param for search return options, and process it differently from
criteria. Also extract areturnargument out of thecriteriaarray, and process it like thereturnkwarg. (FYI: I discovered https://bugs.ruby-lang.org/issues/20956 while working on this).TODO list
ESearchResponse < Data.define(:tag, :uid, :data)#datais a generic Array of[name, value]pairs. Not usingHashbecause some names can be repeated, and the order is significant even between different names.data.assoc(name)can be used for quick lookup.ExtensionDatawill be used for unknown return dataSearchResult:#to_areturns numbers from#all,#partial, or an empty array#modseqESEARCHreturn data:#min,#max,#all,#countESEARCH+CONDSEQ:#modseqESEARCHintoESearchResponseExtensionData.new(tagged_ext_value)ESEARCHandCONDSTORE(MIN,MAX,ALL,COUNT,MODSEQ): parse as Integer or SequenceSet#searchand#uid_searchreturnkwarg: must be an Array, and process differently thancriteria.returnfrom arraycriteriaand process differently thancriteriaESearchResponserather than an emptySearchResponse.ESEARCHresponses in addition toSEARCHresponses. If server sends both, prefer to return theESEARCHresponses.charsetkwarg to#search,#uid_searchTODO: Remove the following from this PR (make new PRs for them):
ESearchResponsemethods and data classes#to_areturning numbers from#partial#partialESearchResponse::PartialResult#updates#relevancyPARTIAL,ADDTO,REMOVEFROM,RELEVANCYas genericExtensionDataRelated future PRs:
PARTIALextension (RFC9394) #367CONTEXT=*(RFC5267)SequenceSet?ESORT(RFC5267)SEARCH=FUZZY(RFC6203)#relevancyscores with numbers from#allor#partial#to_a,#all,#partial#numbers#prepend- like#appendbut adds to the beginning#insert(index, value)#remove(index_or_range)#[],#at,#slice#zipwith array of numbers (forRELEVANCY)#zipwith another SequenceSet (forCOPYUID)