Fix for emails deleted via MacOS Email app still visible on other devices


The Mail.app on MacOS doesn’t delete emails immediately. It marks them with the deleted flag instead while keeping them in the folder until they are expunged – which happens for example when you quit Mail.app. This is standard way according to the IMAP RFC’s. It’s just that some other email clients do/show things differently (but almost always allow user to configure it).

One troubled case can happen if you use both IMAP via Mail.app on MacOS and Exchange (via ActiveSync) on mobile device. It would be better to use Exchange on MacOS but it’s not possible if you’re using for example Horde (which provides ActiveSync only). (ActiveSync is intended for mobile devices and isn’t allowed to be used on MacOS.)

So when I delete email via IMAP in the Mail.app and don’t quit the app, the deleted email is still visible without any indication of deletion in mobile Exchange client (Nine on Android in my case).

… there *is* no such thing as a message marked for deletion in AS.  A message is either in the mailbox or it is not. The /deleted flag is not a supported flag in the protocol …

As explained by the core developer of Horde in a related issue, it’s because of major differences between IMAP and ActiveSync protocols.

Unfortunately the only solution is to get rid of all the emails marked for deletion via a script. Following line can be put in a crontab to perform deletion of emails across all folders of a selected user every minute.

* * * * * root for folder in `doveadm mailbox list -u user@example.com`; do doveadm expunge -u user@example.com Mailbox $folder DELETED; done

There’s a chance for better solution using the autoexpunge and autoexpunge_max_mails options but they are not available in the Dovecot version 2.2.10 provided in CentOS 7.