Why do I see incorrect results in Webmail or IMAP mail searches?

This page is showing a generic answer.
To see a more detailed answer customized for you, type your e-mail address here:

We've occasionally heard of problems where webmail (or any other IMAP mail program) shows incorrect search results or other glitches, especially if you have tens of thousands of messages in a folder. For example, it might only show the most recent few results.

First of all, if you see this problem in a mail program rather than webmail, try the same search in webmail. If it works in webmail, the problem is likely to be in the mail program, and the rest of this page does not apply.

If it fails in webmail, too, though, the IMAP message “cache” on the server may contain incorrect information. You can contact us to fix this, or, if you’re comfortable with the SSH shell, login and type:

imap-cache-reset address@example.com

This will completely delete all IMAP caches and indexes on the server. Then you can try your search again.

(Doing this is safe, and doesn’t delete any useful data. It merely makes the next IMAP connection somewhat slower as the individual messages are inspected to rebuild the cache files.)

Is there any way technically advanced users can test the mail indexes to see if this is the problem?

Technically advanced users can mimic an IMAP search from the command-line shell. This can help show whether this is the problem or not. Some examples will describe the syntax:

doveadm fetch 'hdr.subject date.sent' -u address@example.com mailbox INBOX FROM address@example.com
doveadm fetch 'hdr.subject date.sent' -u address@example.com mailbox INBOX.Sent SUBJECT searchword
doveadm fetch 'hdr.subject date.sent' -u address@example.com mailbox INBOX.Trash TEXT searchword

The doveadm-search-query manual page shows more details.