Using Dovecot, I ran into quite a disturbing problem when it comes to inboxes purge. Here's my setup :

  • Dovecot stores its users/mailboxes on a MySQL backend.
  • Postfix handles email transmissions, and relies on Dovecot for authentication.
  • Inboxes are stored in /var/mail/domain/user.

Quite the basic setup. Now imagine the following scenario :

  1. I create a user in my database (let's say johndoe@mydomain.tld), and start sending and receiving emails. No problems, everything goes fine.
  2. I don't need my user anymore, I just delete it from the database, no more user.

But here's the problem... At this moment, /var/mail/mydomain.tld/johndoe) still exists. Now imagine :

  • Another John Doe appears, and he wants an inbox. I add johndoe@mydomain.tld to the database, great, it works!

Now here's the funny thing : previous John Doe didn't delete his emails before leaving, and new John Doe has gained access to the previous mailbox contents (as addresses are the same, he was given the same inbox location). Let's hope John Doe number 1 hasn't let credentials, credit card information or something similar in his inbox...

So here's my question : is there a proper way to delete actual inboxes when deleting a Dovecot user ? In my example, I'd like /var/mail/mydomain.tld/johndoe to be deleted when first John Doe disappears (step 2, on service restart maybe?). Now, I could do this programmatically using my frontend application (a PHP application which fills the MySQL backend), but that would create a mess with permissions (allow the web user to access mailboxes, no thanks!)

up vote 2 down vote accepted

In our setup we use postgres as backend to store user information. We set the account_status to DELETED in DB and have a cron that takes a backup of the entire account and removes them from the file system. This issue is discussed in dovecot mailinglists also and the solution suggested was to use rm

rm -rf `doveadm user -f home $username`
  • I like the flag idea. It would require some arrangements in our particular setup, but I can figure something similar out. Thank you for your help, and for the link (I think I already came across these mails, just not sure) – John WH Smith Mar 9 '14 at 11:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.