djc / tokio-imap

Tokio-based IMAP implementation
Apache License 2.0
123 stars 42 forks source link

Don't choke on empty SEARCH response #34

Closed jonhoo closed 5 years ago

jonhoo commented 5 years ago
C: a3 SEARCH ALL
S: * SEARCH
thread 'inbox' panicked at 'called `Result::unwrap()` on an `Err` value: Parse(Invalid([42, 32, 83, 69, 65, 82, 67, 72, 32, 13, 10]))'

I think this response should be valid, but imap-proto seems to choke on it?

djc commented 5 years ago

That response is technically invalid per the RFC: the relevant mailbox-data variant is "SEARCH" *(SP nz-number), which implies that a space can only follow SEARCH if it's followed by an ID. In your test, SEARCH has a trailing space but no following IDs. If you got that in the wild, we should probably make the parser more lenient.

(There's already a test case for a valid empty SEARCH response.)

jonhoo commented 5 years ago

I got that using the GreenMail mail test server. Filed https://github.com/greenmail-mail-test/greenmail/issues/264.

djc commented 5 years ago

Going to close this for now, feel free to reopen if this behavior comes up somewhere else.