Dovecot mail user deletion requires more actions prior to deleting user
If one has single instance storage enabled in dovecot, in particular a separate attachments dir, then if users mail isn't purged appropriately prior to deleting a mail user, their attachments will wind up orphaned in the attachments store.
A side discussion on this on the dovecot users lists can be found here: https://dovecot.org/list/dovecot/2015-February/099655.html
What it boils down to is simply running the following 2 commands prior to doing any mail user deletion:
doveadm expunge -d -u johndoe mailbox '*' all
doveadm -v purge -u johndoe
The single instance storage is a wonderful feature and very simple to enable/utilize - all I did in my dovecot configuration was add in:
mail_attachment_dir = /var/vmail/attachments
mail_attachment_min_size = 128k
mail_attachment_fs = sis posix
mail_attachment_hash = %{sha256}
I am using mdbox for the rest of the mail storage format.
I have tested the expunge & purge commands above and they do work as advertised, mail and attachments were cleaned up & storage space returned.
I believe that, to implement a fix for this feature appropriately, the deletion portion of user_update would need to be fixed to incorporate this as well.
As an aside - if I were to hack the appropriate commands in locally (in 3.1.14p1 with p2 patch), I presume I might add them near the top of function user_delete in server/plugins-available/mail_plugin.inc.php? I am about to test with inserted lines 452 + 453:
exec("su -c 'doveadm expunge -d -u \"".$data["old"]["email"]."\" \'*\' all'");
exec("su -c 'doveadm -v purge -u \"".$data["old"]["email"]."\" '");
(This didn't work on my first test... I've added debug logging statements after each exec and those did show, so I have more testing to do...)