Last active
March 24, 2023 22:06
-
-
Save LuisCardenasSolis/59fa941b173250161148fc1b4721e136 to your computer and use it in GitHub Desktop.
Delete messages from zimbra accounts by from address and subject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "========== ELIMINANDO CORREOS ==========" | |
ACC=$(/opt/zimbra/bin/zmprov -l gaa | grep -E -v '(^admin@|^spam\..*@|^ham\..*@|^virus-quarantine.*@|^galsync.*@)'|sort) | |
addr="$1" | |
subject="$2" | |
# El asunto puede ser completo o una parte (igual al filtro web) | |
[ -z "$addr" ] && echo "Falta el correo de filtro de busqueda" && exit 1 | |
if [ -n "$subject" ];then | |
FILTER_MAILBOX="from:$addr subject:\"$subject\"" | |
else | |
FILTER_MAILBOX="from:$addr" | |
fi | |
for acct in $ACC ; do | |
echo -e "\n|=> $acct > Filtrando correos de : $addr" | |
for msg in `/opt/zimbra/bin/zmmailbox -z -m "$acct" s -l 999 -t message "${FILTER_MAILBOX}"| awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'` | |
do | |
echo " |> Eliminando $msg" | |
/opt/zimbra/bin/zmmailbox -z -m $acct dm $msg | |
done | |
echo -e "\n--------------------------------------------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment