Last active
August 6, 2024 13:07
-
-
Save jigzstar/6511534 to your computer and use it in GitHub Desktop.
Zimbra - Delete a message by subject from all email accounts in a file
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 | |
# rm_message.sh [email protected] 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 [email protected] <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 |
the script seems not to be working on zimbra version 9
One tip, switch the grep and awk in zmprov command:
... | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'
... | awk '{ print $2 }' | grep -v -e Id -e "--" -e "^$" -e "Type"
This will firstly filter on msgId column (numbers only) then clear the output.
Doing this the subject can contain whatever and doesn't get filtered out by grep.
how if i want to delete by range of date ?
From Zimbra doc, you can use Zimbra command to filter messages:
zmmailbox -z -m [email protected] s -t message -l 50 "in:inbox date:01/01/2015"
Ref: https://wiki.zimbra.com/wiki/Deleting_messages_from_account_using_the_CLI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about removing an email only by subject without specifying the sender addr?