Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
@jigzstar

This comment has been minimized.

Show comment Hide comment
@jigzstar

jigzstar Sep 10, 2013

Updated a script found on the zimbra wiki for task, think it's a handy thing to have.

Owner

jigzstar commented Sep 10, 2013

Updated a script found on the zimbra wiki for task, think it's a handy thing to have.

@developplus

This comment has been minimized.

Show comment Hide comment
@developplus

developplus Sep 11, 2015

!/bin/bash

rm_message.sh user@domain.com subject

"get message subject :" zmmailbox -z -m user@domain.com s -t message -l 50 "in:inbox date:mm/dd/yyyy"

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 "
exit 0
else
addr=$1
subject=$2
for acct in cat /tmp/temp_email ; do
echo "Searching $acct for Subject: $subject"
for msg in zmmailbox -z -m "$acct" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'
do
echo "Removing "$msg" from "$acct""
zmmailbox -z -m $acct dm $msg
done
done
fi

!/bin/bash

rm_message.sh user@domain.com subject

"get message subject :" zmmailbox -z -m user@domain.com s -t message -l 50 "in:inbox date:mm/dd/yyyy"

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 "
exit 0
else
addr=$1
subject=$2
for acct in cat /tmp/temp_email ; do
echo "Searching $acct for Subject: $subject"
for msg in zmmailbox -z -m "$acct" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'
do
echo "Removing "$msg" from "$acct""
zmmailbox -z -m $acct dm $msg
done
done
fi

@fokker1984

This comment has been minimized.

Show comment Hide comment
@fokker1984

fokker1984 May 3, 2017

This is what working for my zimbra Release 8.5.0.GA.3042

/opt/zimbra/bin/zmmailbox -z -m "bima@yourdomail.com" s -l 999 -t message "from:$addr "|awk '{ if (NR!=1) {print}}'|grep -v -e Id -e " -----" -e "^$" | awk '{ print $2 }'

fokker1984 commented May 3, 2017

This is what working for my zimbra Release 8.5.0.GA.3042

/opt/zimbra/bin/zmmailbox -z -m "bima@yourdomail.com" s -l 999 -t message "from:$addr "|awk '{ if (NR!=1) {print}}'|grep -v -e Id -e " -----" -e "^$" | awk '{ print $2 }'

@romale

This comment has been minimized.

Show comment Hide comment
@romale

romale Feb 5, 2018

Works on 8.7

#!/bin/bash
# rm_message.sh user@domain.com subject
# or
# rm_message.sh user@domain.com


if [ -z "$2" ]; then
addr=$1
for acct in `zmprov -l gaa | grep -E -v '(^admin@|^spam\..*@|^ham\..*@|^virus-quarantine.*@|^galsync.*@)'|sort` ; do
    echo "Searching $acct"
    for msg in `/opt/zimbra/bin/zmmailbox -z -m "$acct" s -l 999 -t message "from:$addr"|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
	echo "Moving "$msg" from "$acct" to Trash"
	/opt/zimbra/bin/zmmailbox -z -m $acct mm $msg /Trash
    done
done
else
addr=$1
subject=$2
for acct in `zmprov -l gaa | grep -E -v '(^admin@|^spam\..*@|^ham\..*@|^virus-quarantine.*@|^galsync.*@)'|sort` ; 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
      echo "Moving "$msg" from "$acct" to Trash"
      /opt/zimbra/bin/zmmailbox -z -m $acct mm $msg /Trash
    done
done
fi

romale commented Feb 5, 2018

Works on 8.7

#!/bin/bash
# rm_message.sh user@domain.com subject
# or
# rm_message.sh user@domain.com


if [ -z "$2" ]; then
addr=$1
for acct in `zmprov -l gaa | grep -E -v '(^admin@|^spam\..*@|^ham\..*@|^virus-quarantine.*@|^galsync.*@)'|sort` ; do
    echo "Searching $acct"
    for msg in `/opt/zimbra/bin/zmmailbox -z -m "$acct" s -l 999 -t message "from:$addr"|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
	echo "Moving "$msg" from "$acct" to Trash"
	/opt/zimbra/bin/zmmailbox -z -m $acct mm $msg /Trash
    done
done
else
addr=$1
subject=$2
for acct in `zmprov -l gaa | grep -E -v '(^admin@|^spam\..*@|^ham\..*@|^virus-quarantine.*@|^galsync.*@)'|sort` ; 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
      echo "Moving "$msg" from "$acct" to Trash"
      /opt/zimbra/bin/zmmailbox -z -m $acct mm $msg /Trash
    done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment