
batch delete emails from zimbra mailboxes
If you wish to delete a specific email from all mailboxes in your Zimbra server there is a script which can search mailboxes one by one, starting alphabetically i.e. usernames with numbers first, for this email based on sender’s email address and the subject line. The script runs at speed of about 30-40 mailboxes per minute.
Remember you need to su – zimbra before you run this script.
The code in script is:
#!/bin/bash
# rm_msg.sh user subject
if [ -z "$2" ]; then
echo "usage: rm_msg.sh "
echo " Rummages through all mail boxes looking for messages from with subject="
echo " Example: ./rm_msg.sh butthead_user rems "
echo " Put double-quotes around multi-word subjects"
exit 0
else
addr=$1
subject=$2
for usractnopac in `zmprov -l gaa`
do
echo "Searching $usractnopac for Subject: $subject From: $addr"
for msg in `zmmailbox -z -m "$usractnopac" s -l 999 -t message "is:anywhere from:$addr subject:$subject"|awk '{ if (NR!=1) {print}}' |
grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'`
do
echo "Removing "$msg""
zmmailbox -z -m $usractnopac dm $msg
done
done
fi
Taken from Zimbra Support Forums