From 25aee1d3e9e8f78ecd5b3273c16d65d722f0d41b Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Mon, 6 Apr 2026 13:39:47 +0300 Subject: [PATCH] fix(mailserver): delete all e2e-probe emails, not just current marker Previously only searched for the current run's specific marker subject. If IMAP deletion failed, old emails accumulated. Now searches for all emails with "e2e-probe" in subject and deletes them, cleaning up any leftovers from prior failed runs. --- stacks/mailserver/modules/mailserver/main.tf | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/stacks/mailserver/modules/mailserver/main.tf b/stacks/mailserver/modules/mailserver/main.tf index 59b889ea..60f136eb 100644 --- a/stacks/mailserver/modules/mailserver/main.tf +++ b/stacks/mailserver/modules/mailserver/main.tf @@ -610,12 +610,16 @@ try: if msg_ids[0]: found = True print(f"Found test email after {attempt+1} attempts") - # Delete the test email + # Delete ALL e2e probe emails (current + any leftovers from previous runs) + if found: try: - for mid in msg_ids[0].split(): - imap.store(mid, "+FLAGS", "\\Deleted") - imap.expunge() - print("Deleted test email") + _, all_e2e = imap.search(None, "SUBJECT", "e2e-probe") + if all_e2e[0]: + e2e_ids = all_e2e[0].split() + for mid in e2e_ids: + imap.store(mid, "+FLAGS", "(\\Deleted)") + imap.expunge() + print(f"Deleted {len(e2e_ids)} e2e probe email(s)") except Exception as de: print(f"Delete failed (non-critical): {de}") imap.logout()