Expuning & Purging doesn't fully remove emails?

Zelic Bojan bojan.zelic at kudelskisecurity.com
Thu Aug 20 23:42:09 EEST 2020


Hello, I'm facing an issue where deleted emails keep re-appearing after my mailbox index gets recreated.  I'm running version 2.2.36 of dovecot, but I tested the same scenario under 2.3.10. I'm also using mdbox, autoexpunge, and using dovecot replication.

I've had several instances now where some expunged emails show up again in a mailbox. I noticed this error:

  doveadm: Error: Corrupted dbox file /var/mail/virtual/mailbox at domain.com/mdbox/storage/m.3228 (around offset=1988744): msg header has bad magic value

which caused the index to get rebuilt... however several times now, the indexes got rebuilt even though there doesnt seem like there was any error... so im not sure why that is. 

  lmtp(13910): Warning: fscking index file /var/mail/virtual/mailbox at domain/mdbox/storage/dovecot.map.index
  lmtp(13910): Warning: fscking index file /var/mail/virtual/mailbox at domain/mdbox/storage/dovecot.map.index
  lmtp(13910): Warning: mdbox /var/mail/virtual/mailbox at domain/mdbox/storage: rebuilding indexes

I'm not sure why these mails keep coming back though... or if there's anything that I can do to limit the number of emails that get restored.

I want to make sure expunged & purged emails stay expunged & purged. If I run a purge and then force index recreation... why would expunged emails come back? Shouldn't I expect them all to be deleted & purged? Does expunge not expunge all emails? (In production, I'm running autoexpunge but this test below shows what happens when I attempt to expunge everything)

  doveadm search -u email at domain all | wc -l
  # output 22096

  doveadm expunge -u email at domain mailbox '*' all
  doveadm search -u email at domain all | wc -l
  # output: 0

  doveadm purge -u email at domain
  doveadm dump /var/mail/virtual/email at domain/mdbox/storage/ | grep -c 'ref.*\b0\b' 
  # output: 0

  doveadm force-resync -u email at domain Inbox
  # output:
  # doveadm(email at domain): Warning: fscking index file /var/mail/virtual/email at domain/mdbox/storage/dovecot.map.index
  # doveadm(email at domain): Warning: mdbox /var/mail/virtual/email at domain/mdbox/storage: rebuilding indexes
  # doveadm(email at domain): Warning: fscking index file /var/mail/virtual/email at domain/mdbox/storage/dovecot.map.index

  doveadm search -u email at domain all | wc -l
  # output: 843

I would expect the output to be 0. Theoretically I deleted all emails and purged all emails. Nothing should be left on the disk? However... I can see there are still m.* files in mdbox/storage for the mailbox. 

Overall, I'm not sure why the index got recreated... but I'm trying to limit the impact of mailbox corruption so that deleted emails do not come back if the index is somehow recreated again. 

If I were to re-run expunge, purge, and force-resync a 2nd time... it does get emptied out, but I'm not looking to run force-resync intentially since it causes dataloss with mdbox, and re-running only expunge & purge doesn't seem to do anything. 

Bojan Zelic
Sr. IT Infrastructure Engineer


More information about the dovecot mailing list