Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-2009, 06:52 AM
Trained Alumni
 
Posts: 11
Default [SOLVED] delete mails via cli based on date

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.
Reply With Quote
  #2 (permalink)  
Old 11-03-2009, 09:27 AM
Trained Alumni
 
Posts: 8
Default

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
Reply With Quote
  #3 (permalink)  
Old 11-05-2009, 02:37 AM
Trained Alumni
 
Posts: 11
Default

thx this works!
Reply With Quote
  #4 (permalink)  
Old 01-04-2010, 04:37 AM
Starter Member
 
Posts: 1
Default

OK! That's great! It's work very well
Reply With Quote
  #5 (permalink)  
Old 03-09-2010, 09:03 AM
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
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.