I ran into this bug today with Apple mail and Dovecot/Imap.
I was trying to delete a lot of email and it would go away and then a few seconds come right back. Sometimes it would stick, most times it would come back.
Digging deep into this, I discovered that dovecot creates a mail/.imap cache directory. Looking in the mail logs I noticed that there was a an error about index corruption on the cache.
The simple solution is to stop dovecot, deleted the entire .imap directory and restart dovecot.
This will require the client to re-sync the cache (so it might take awhile if you have a lot of mail or folders).
In my case, this appears to have resolved the problem.