This may be an old thread, but I ran into this same problem today so I thought I'd share the script I used in case someone else stumbles across this thread via a search engine like I did.
I had a user who sent about 50mb of photographs to every one of the users in her address book. Multiple times if they were in multiple distribution lists. Since I have multiple remote sites that use my Zimbra server via a couple shared DSL lines, this clobbered all the remote locations.
I took examples from a couple of the sources linked earlier in the thread (bdial's psudocode and King0770's script), and combined them. It runs about 35 accounts per minute on my system, so it wouldn't scale too well for larger installations, but it is still way faster than doing it by hand.
The expected inputs are the from_username and subject. The script steps through each account on the server and deletes any messages it finds from the user provided and with the subject provided.
I ran:
./rm_mssg.sh Smart_User "(no subject)"
Smart_User isn't a big fan of filling in the subject when she sends emails so there
was some collateral damage, but I didn't care at that point.
Code:
#!/bin/bash
# rm_mssg.sh user subject
if [ -z "$2" ]; then
echo "usage: rm_message.sh <fromuser_name> <subject>"
echo " Rummages through all mail boxes looking for messages from <fromuser_name> with subject=<subject>"
echo " Example: ./rm_mssg.sh butthead_user rems "
echo " Put double-quotes around multi-word subjects"
exit 0
else
addr=$1
subject=$2
for usractnopac in `zmprov gaa`
do
echo "Searching $usractnopac for Subject: $subject From: $addr"
for msg in `zmmailbox -z -m "$usractnopac" s -l 999 -t message "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