JMAP Email/query: punctuation characters (№, #) break full-text searches

Issue Description

Full-text searches containing punctuation characters such as № or # fail to find matching emails when the query is not enclosed in quotation marks.

However, the same search without these characters works correctly. Quoted phrases also work, even when the punctuation character is present in the original query.

Expected Behavior

Punctuation characters that are not indexed as searchable tokens should not cause an otherwise valid multi-term search to return zero results.

If punctuation is ignored during indexing, it should be handled consistently during query processing.

Actual Behavior

Adding № or # to an otherwise successful unquoted search causes the matching email to disappear from search results.

Reproduction Steps

Create an email containing the following text in its body:
Bill # ER-4613

Execute these searches:
Search query Result
ER-4613 Found
“Bill # ER-4613” Found
“Bill ER-4613” Found
Bill # ER-4613 Not found

Not found

“#” Not found

The № character exhibits the same problem.

Stalwart Version

v1.x

Installation Method

Binary (Linux)

Database Backend

PostgreSQL

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

MAP request

Bulwark sends the search text unchanged to the server:

{
“accountId”: “c”,
“filter”: {
“operator”: “AND”,
“conditions”: [
{“text”: “#”},
{“inMailboxOtherThan”: [“b”, “c”]}
]
},
“sort”: [
{“property”: “receivedAt”, “isAscending”: false}
],
“limit”: 50,
“position”: 0,
“calculateTotal”: true
}

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

Path prefix likely includes “server/”.

In v1.0, the server splits an unquoted text query on whitespace. Each piece must match somewhere in the email (From, To, Cc, Bcc, Subject, Body or Attachment), and all pieces are ANDed together. In Bill # ER-4613, the piece # produces no indexed tokens, because punctuation isn’t indexed. Nothing can match it, so the whole AND fails and returns zero results. This is why ER-4613 and Bill ER-4613 work and Bill # ER-4613 doesn’t. I couldn’t confirm this against the internal index’s tokenizer, only from the query-building code.

A quoted query is passed through as one phrase and not split per word. That is why "Bill # ER-4613" is found. A query of only # or "#" has no indexable token, so it can’t match anything.

I found no documented option to make punctuation-only terms be ignored. The only workarounds are to quote the whole phrase or to drop the punctuation from the query. Dropping such terms before ANDing would be a change to the server’s query handling, so a staff member will need to confirm whether that is intended. I didn’t check whether № is handled differently, since you report the same result.

The relevant source is crates/jmap/src/email/query/text.rs. For background on the built-in index, see Search store | Stalwart

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Hi Jan,

This was a bug in how the server splits an unquoted text filter. Each word becomes its own condition and all of them must match, but a word made only of punctuation like # or № has nothing to look up in the index, so its condition matched no messages and took the whole search down with it. Quoted phrases go through a different path that just drops the punctuation, which is why "Bill # ER-4613" worked.

The fix skips those punctuation-only words when there are other words to search for, so Bill # ER-4613 now finds your message. It will ship in the next weekly Stalwart release. Until you upgrade, quoting the phrase or leaving the # out gets the same results.

Searching for # or № on its own will still return nothing after the fix. Punctuation is not indexed at all, so there is nothing for a search on that character alone to match.