<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">​I managed to figure this out.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Just wanted to follow up if anyone in the future encounters the same issue.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I am using HAProxy along with dovecot replication. When an email comes in... it is round robin'd to each of the 2 dovecot/postfix servers. I have postfix running on each server and it uses the local dovecot LMTP service for storing the mails. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
We sometimes get surges of emails(hundreds or thousands in a couple of seconds). Each alternative request hits a different mail server and then should be replicated. The replication works and we don't encounter missing or duplicated emails.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
However, when I purge expunged emails, somehow this does not fully remove them when it's setup in this fashion. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I ran 2 tests:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
1) I send 1000 emails to the loadbalancer(round-robin), expunge on both servers & purge them on both servers, recreate the indexes... ~200 emails come back.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
2) I send 1000 emails to one of the mail servers, expunge & purge them, recreate the indexes... 0 emails come back.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
My fix is to remove the round robin load balancing and use sticky tables in HAproxy.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Zelic Bojan<br>
<b>Sent:</b> Thursday, August 20, 2020 1:42 PM<br>
<b>To:</b> dovecot@dovecot.org <dovecot@dovecot.org><br>
<b>Subject:</b> Expuning & Purging doesn't fully remove emails?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">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.<br>
<br>
I've had several instances now where some expunged emails show up again in a mailbox. I noticed this error:<br>
<br>
  doveadm: Error: Corrupted dbox file /var/mail/virtual/mailbox@domain.com/mdbox/storage/m.3228 (around offset=1988744): msg header has bad magic value<br>
<br>
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.
<br>
<br>
  lmtp(13910): Warning: fscking index file /var/mail/virtual/mailbox@domain/mdbox/storage/dovecot.map.index<br>
  lmtp(13910): Warning: fscking index file /var/mail/virtual/mailbox@domain/mdbox/storage/dovecot.map.index<br>
  lmtp(13910): Warning: mdbox /var/mail/virtual/mailbox@domain/mdbox/storage: rebuilding indexes<br>
<br>
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.<br>
<br>
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)<br>
<br>
  doveadm search -u email@domain all | wc -l<br>
  # output 22096<br>
<br>
  doveadm expunge -u email@domain mailbox '*' all<br>
  doveadm search -u email@domain all | wc -l<br>
  # output: 0<br>
<br>
  doveadm purge -u email@domain<br>
  doveadm dump /var/mail/virtual/email@domain/mdbox/storage/ | grep -c 'ref.*\b0\b'
<br>
  # output: 0<br>
<br>
  doveadm force-resync -u email@domain Inbox<br>
  # output:<br>
  # doveadm(email@domain): Warning: fscking index file /var/mail/virtual/email@domain/mdbox/storage/dovecot.map.index<br>
  # doveadm(email@domain): Warning: mdbox /var/mail/virtual/email@domain/mdbox/storage: rebuilding indexes<br>
  # doveadm(email@domain): Warning: fscking index file /var/mail/virtual/email@domain/mdbox/storage/dovecot.map.index<br>
<br>
  doveadm search -u email@domain all | wc -l<br>
  # output: 843<br>
<br>
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.
<br>
<br>
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.
<br>
<br>
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.
<br>
<br>
Bojan Zelic<br>
Sr. IT Infrastructure Engineer</div>
</span></font></div>
</body>
</html>