Issue Description
When an IMAP SEARCH asks for MIN and/or MAX together with ALL, the ALL part of the ESEARCH response contains only the min and max message numbers instead of every match. COUNT is correct, so the response contradicts itself.
The cause is in map_search_results (crates/imap/src/op/search.rs, around line 734). When MIN or MAX is requested, only the min and max are collected, whether or not ALL was also requested. The saved search result (SAVE, $) is affected the same way.
Stalwart’s own test expects the wrong output: tests/src/imap/search.rs line 32 asserts COUNT 10 MIN 1 MAX 10 ALL 1,10 for a 10-message mailbox.
Real-world impact: Libredesk (helpdesk software) sends SEARCH RETURN (MIN MAX ALL COUNT) SINCE NOT DELETED and fetches what ALL lists. Since Libredesk commit 080318a, it imports only the oldest and newest message on each poll. Mail in between is delayed by up to two days.
A failing test is on my fork: IMAP: ESEARCH ALL with MIN/MAX returns only min and max - Pull Request #1 - mewejo/stalwart - GitHub (found and tested with AI assistance).
Expected Behavior
ALL lists every matching message, whatever other result options are requested (RFC 4731 §3.1).
With SAVE, $ holds only MIN/MAX when those are the only other options. When ALL or COUNT is also requested, $ holds every match (RFC 5182 §2.4).
For 6 matching messages:
- ESEARCH (TAG “A1”) COUNT 6 MIN 1 MAX 6 ALL 1:6
Actual Behavior
- ESEARCH (TAG “A1”) COUNT 6 MIN 1 MAX 6 ALL 1,6
COUNT says 6, but ALL lists only messages 1 and 6. Without MIN/MAX it’s correct:
- ESEARCH (TAG “A2”) COUNT 6 ALL 1:6
Reproduction Steps
- Have a mailbox with 3 or more messages.
- openssl s_client -connect :993 -quiet
- A0 LOGIN
- A0 SELECT INBOX
- A1 SEARCH RETURN (MIN MAX COUNT ALL) ALL, which returns ALL with only the first and last message.
- A2 SEARCH RETURN (COUNT ALL) ALL, which returns every message.
Relevant Log Output
C: A1 SEARCH RETURN (MIN MAX COUNT ALL) SINCE 11-Oct-2026
S: * ESEARCH (TAG “A1”) COUNT 6 MIN 1 MAX 6 ALL 1,6
C: A2 SEARCH RETURN (ALL COUNT) SINCE 11-Oct-2026
S: * ESEARCH (TAG “A2”) COUNT 6 ALL 1:6
No errors are logged; the server returns a successful but incomplete response.
Stalwart Version
v0.16.x
Installation Method
Docker
Database Backend
PostgreSQL
Blob Storage
S3-compatible
Search Engine
Internal
Directory Backend
Internal
Additional Context
The bug is also on current main)
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on