Skip to content

Instantly share code, notes, and snippets.

@hsntgm
Last active May 25, 2021 08:11
Show Gist options
  • Save hsntgm/62321c86a04421d4241551cb8e7817a9 to your computer and use it in GitHub Desktop.
Save hsntgm/62321c86a04421d4241551cb8e7817a9 to your computer and use it in GitHub Desktop.
Dovecot -- find and delete mails that sent by mistake if unseen yet.
#!/bin/bash
# >> LDA-Dovecot <<
# Find and delete mails which accidently sent to wrong mailbox if unseen yet.
# Works very fast in big mailboxes. Search for uniq_word in body.
mbox="INBOX"
mailbox="[email protected]"
date="2021-05-14"
str="uniq_word"
if ! [[ -z $(doveadm search -u $mailbox SAVEDON $date BODY "$str" \( NEW \)) ]]; then
echo "Your lucky day dear Admin! Bomb defused.."
doveadm expunge -u $mailbox mailbox "$mbox" SAVEDON $date BODY "$str" \( NEW \)
else
echo "No matter what happens dear Admin.Take a coffe!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment