Since 2.2.34/2.3.1 dovecot has a feature that indicates whether email has an attachment or not via keywords. These keywords could be used by IMAP clients. These keywords will likely become standardized - for now the latest information is in https://www.ietf.org/mail-archive/web/imapext/current/msg05858.html
To enable this feature, you can set mail_attachment_detection_options.
It supports following options
- add-flags-on-save - Enables the feature, attachments are detected and marked during save
- content-type=type|!type - Include or exclude given content type. Including will only negate an exclusion (e.g. content-type=!foo/* content-type=foo/bar).
- exclude-inlined - Do not consider any attachment with disposition inlined.
Once enabled, mails that are saved, are marked with $HasAttachment or $HasNoAttachment keyword. These keywords can be cleared, and are not protected. Since v2.3.3 it is possible to post-process attachments with doveadm rebuild attachments command.