Hi folks,

the SEARCH=FUZZY capability is never advertised after login, even
with an FTS backend that supports fuzzy search. FUZZY search keys
themselves keep working; only the capability is missing.


Version
-------

Dovecot 2.4.5 (0cbb641), official dovecot/dovecot:2.4.5 container
image, running rootless.


Symptom
-------

With SEARCH=FUZZY switched on in imap_capability and an FTS backend
that sets FTS_BACKEND_FLAG_FUZZY_SEARCH, the capability is listed in
imap-login's greeting, but missing from the [CAPABILITY ...] code of
the login reply and from the answer to a CAPABILITY command.

I saw this with an out-of-tree backend that sets the flag: in the
same session, SEARCH ... FUZZY TEXT "..." goes through the backend
and returns its results. And the same with fts_solr: identical
capabilities, and the FUZZY search in that session goes to Solr.


Cause
-----

imap creates the user without namespaces
(MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES in src/imap/main.c), so
that the login reply goes out quickly. The namespaces come later,
from mail_namespaces_init() in client_create_finish(), after the
login reply was sent.

But client_create() in src/imap/imap-client.c decides about the
capability before that:

/* Enable FUZZY capability only when it actually has a chance of working */
   if (!user->fuzzy_search)
           imap_unset_capability(set_instance, "SEARCH=FUZZY");

and builds client->capability_string from the modified settings
right after. user->fuzzy_search is only set by the fts plugin, in
fts_init_namespace() (src/plugins/fts/fts-storage.c), which runs
from the mail_namespaces_added hook. So at this point it is always
FALSE.

The same code is on core main (checked at 7b28a75, 2026-11-19).


Suggested fix
-------------

As the login reply is deliberately sent before the namespaces exist,
moving the check behind mail_namespaces_init() alone can't fix the
login reply. Some ideas, none of them tried:

- Drop the check. SEARCH=FUZZY isn't in the default imap_capability
  list in 2.4, so it is only advertised where the admin switched it
  on.

- Decide without the namespaces, e.g. in the fts plugin when the user
  is created, from the flags of the configured fts_driver's
  registered backend. That doesn't cover backends that only know
  their flags after init.

- Rebuild client->capability_string after mail_namespaces_init() in
  client_create_finish(). That fixes the CAPABILITY command, but not
  the login reply.


Reproduction
------------

Configuration:

   mail_plugins {
     fts = yes
     fts_solr = yes
   }
   imap_capability {
     "SEARCH=FUZZY" = yes
   }
   fts solr {
     fts_solr_url = http://solr.example.com:8983/solr/dovecot/
   }

Then:

   * OK [CAPABILITY ... SEARCH=FUZZY ...] Dovecot ready.
   a LOGIN wanda secret
   a OK [CAPABILITY ...] Logged in      <- no SEARCH=FUZZY
   b CAPABILITY
   * CAPABILITY ...                     <- no SEARCH=FUZZY


Impact and workaround
---------------------

Clients that check the capability before using FUZZY never use it.
Clients that send FUZZY anyway get fuzzy results.


The cause above comes from Claude Code reading the source; the
symptom was checked in test containers.

Regards,
Manuel
_______________________________________________
dovecot mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to