Issue Description
An Email/query whose filter is NOT of an AND returns no ids when the AND holds an OR, a NOT and at least one other condition, and no message matches that AND. Every message should match, since none matches the inner filter. When at least one message matches the inner filter, the result is correct.
Writing the same filter by hand with De Morgan’s laws, as OR(NOT(subject: qqa), NOT(OR(subject: qqb, subject: qqc)), subject: qqd), returns the correct result. The same happens with a from condition in place of the first subject one.
Impact: webmail clients that build an “everything not in these tabs” view as NOT(tab filters) show an empty folder whenever the folder holds no messages for those tabs.
Expected Behavior
The query returns every message in the account, since no message matches the inner AND (RFC 8621 §4.4.1, FilterOperator NOT: none of the conditions match).
Actual Behavior
The query returns no ids.
Shapes tested on an account holding one message with subject “Hello there” (every word matches nothing):
| Filter | Result | Expected |
|---|---|---|
| NOT(AND(subject: qqa, OR(subject: qqb, subject: qqc), NOT(subject: qqd))) | 0 | 1 |
| NOT(AND(subject: qqa, AND(OR(subject: qqb, subject: qqc), NOT(subject: qqd)))) | 0 | 1 |
| NOT(AND(subject: qqa, OR(subject: qqb, subject: qqc))) | 1 | 1 |
| NOT(AND(subject: qqa, subject: qqb, NOT(subject: qqd))) | 1 | 1 |
| NOT(AND(OR(subject: qqb, subject: qqc), NOT(subject: qqd))) | 1 | 1 |
After adding a second message with subject “qqa qqb”, which matches the inner AND, the first query correctly returns 1 of the 2 messages.
Reproduction Steps
- Use an account holding one message, with subject “Hello there”.
- Run this query:
["Email/query", {
"accountId": "<id>",
"filter": {"operator": "NOT", "conditions": [
{"operator": "AND", "conditions": [
{"subject": "qqa"},
{"operator": "OR", "conditions": [{"subject": "qqb"}, {"subject": "qqc"}]},
{"operator": "NOT", "conditions": [{"subject": "qqd"}]}
]}
]}
}, "0"]
- It returns
"ids": []instead of the one message.
Relevant Log Output
No errors are logged; the query succeeds with an empty result.
Stalwart Version
v0.16.x
Installation Method
Docker
Database Backend
RocksDB
Blob Storage
RocksDB
Search Engine
Internal
Directory Backend
OIDC
Additional Context
Seen on 0.16.26 (Docker image stalwartlabs/stalwart:v0.16). Reproduced on a fresh test account; it also shows on a production server with real mail.
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