View Single Post
  #5 (permalink)  
Old 03-09-2010, 08:03 AM
Himanshu Himanshu is offline
Special Member
 
Posts: 139
Default

Quote:
Originally Posted by brumdo View Post
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/^\s\s*//" | sed -e "s/\s\s*/ /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/deleteOldMessagesList.txt >> /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 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.
Reply With Quote