Hi,
is it possible to delete all mail from a specific user before a specific date?
now i have to go into the users mails, use find and then delete per 100 mails
I need this because the migration went wrong and I have to redo this. If I don't delete the old mails first i got doubles.
[SOLVED] delete mails via cli based on date
[SOLVED] delete mails via cli based on date
A co-worker made a script that I then modified it to ask for variables like the account name, folder, etc.
It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.
I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.
Remember to su to zimbra.
Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it. :)
Here it is:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT > /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done
It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.
I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.
Remember to su to zimbra.
Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it. :)
Here it is:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT > /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done
[SOLVED] delete mails via cli based on date
thx this works!
[SOLVED] delete mails via cli based on date
OK! That's great! It's work very well
-
- Outstanding Member
- Posts: 217
- Joined: Fri Sep 12, 2014 11:16 pm
[SOLVED] delete mails via cli based on date
[quote user="brumdo"]A co-worker made a script that I then modified it to ask for variables like the account name, folder, etc.
It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.
I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.
Remember to su to zimbra.
Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it. :)
Here it is:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT > /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done[/QUOTE]
IT works , in My Case it gives me 1000 message a time.Lookslike some parameter that limits it give 1000 or 2500 message at a time to be searched at a time.
It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.
I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.
Remember to su to zimbra.
Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it. :)
Here it is:
#!/bin/bash
#version .1
#
ZIMBRA_BIN=/opt/zimbra/bin
echo "Enter the username.:"
read THEACCOUNT
echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
read THEDATE
echo "What folder would you like to delete these messages from?:"
read THEFOLDER
echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
echo "Do you want to continue? (y/N): "
read ADD
themagic ()
{
touch /tmp/deleteOldMessagesList.txt
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
do
if [[ $i =~ [-]{1} ]]
then
MESSAGEID=${i#-}
echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
else
echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
fi
done
$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT > /tmp/process.log
rm -f /tmp/deleteOldMessagesList.txt
echo "Completed. Run again for same user?"
read ADD
}
while expr "$ADD" : ' *[Yy].*'
do themagic
done[/QUOTE]
IT works , in My Case it gives me 1000 message a time.Lookslike some parameter that limits it give 1000 or 2500 message at a time to be searched at a time.
-
- Posts: 1
- Joined: Sat Sep 13, 2014 3:25 am
[SOLVED] delete mails via cli based on date
Hi Guys,
I tried same script but it's not working..
If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.
Please help................
I tried same script but it's not working..
If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.
Please help................
-
- Posts: 38
- Joined: Sat Sep 13, 2014 2:13 am
[SOLVED] delete mails via cli based on date
Hi there,
Happy new year to all of you guys.
Thank for this great script.
Unfortunately I do have an error as well.
ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)
Anyone can help me to fix this plese ? :)
Happy new year to all of you guys.
Thank for this great script.
Unfortunately I do have an error as well.
ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)
Anyone can help me to fix this plese ? :)
[SOLVED] delete mails via cli based on date
[quote user="16117Ranjithkumar"]Hi Guys,
I tried same script but it's not working..
If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.
Please help................[/QUOTE]
1. You mention command prompt, this is a *nix script. Not for Windows?
2. Did you su to zimbra?
[quote user="backpacker77"]
Hi there,
Happy new year to all of you guys.
Thank for this great script.
Unfortunately I do have an error as well.
ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)
Anyone can help me to fix this plese ?
[/QUOTE]
And for you I'm guessing the error is here, which means you need to change that 100k to 1k :)
I tried same script but it's not working..
If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.
Please help................[/QUOTE]
1. You mention command prompt, this is a *nix script. Not for Windows?
2. Did you su to zimbra?
[quote user="backpacker77"]
Hi there,
Happy new year to all of you guys.
Thank for this great script.
Unfortunately I do have an error as well.
ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)
Anyone can help me to fix this plese ?
[/QUOTE]
And for you I'm guessing the error is here, which means you need to change that 100k to 1k :)
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`
-
- Posts: 38
- Joined: Sat Sep 13, 2014 2:13 am
[SOLVED] delete mails via cli based on date
And for you I'm guessing the error is here, which means you need to change that 100k to 1k :)
Yes indeed. Thanks
for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^ss*//" | sed -e "s/ss*/ /g" | cut -d" " -f2`[/QUOTE]
Yes indeed. Thanks
Who is online
Users browsing this forum: No registered users and 15 guests