Skip to content

Instantly share code, notes, and snippets.

@addoull
Forked from jigzstar/rm_message.sh
Created December 19, 2017 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addoull/e1e20bad28f6d13bcf450bc3e310770f to your computer and use it in GitHub Desktop.
Save addoull/e1e20bad28f6d13bcf450bc3e310770f to your computer and use it in GitHub Desktop.
Zimbra - Delete a message by subject from all email accounts in a file
#!/bin/bash
# rm_message.sh user@domain.com subject
# create temp_file prior to calling this zmprov -l gaa | grep domain.com > /tmp/temp_email
if [ -z "$2" ]; then
echo "usage: rm_message.sh user@domain.com <subject>"
exit 0
else
addr=$1
subject=$2
for acct in `cat /tmp/temp_email` ; do
echo "Searching $acct for Subject: $subject"
for msg in `/opt/zimbra/bin/zmmailbox -z -m "$acct" 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" from "$acct""
/opt/zimbra/bin/zmmailbox -z -m $acct dm $msg
done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment