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
This deletes much more!!!
ReplyDeleteIf you use it for conversations all Mails concerning a conversation are also deleted.
Вот это работать не будет
ReplyDeletesearch -l 100000
там лимит до 1000, а вот как искать более старые письма не понятно, щас сам бъюсь над этим.