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 03-24-2008, 07:35 AM
Senior Member
 
Posts: 50
Default Delete un-read email older the X days

I'm looking to delete emails from my users mailboxes that are unread and over X number of days old. Any thoughts on how I might do this? I
Reply With Quote
  #2 (permalink)  
Old 03-24-2008, 07:37 AM
Zimbra Consultant & Moderator
 
Posts: 20,312
Default

delete messages massively
__________________
Regards


Bill
Reply With Quote
  #3 (permalink)  
Old 03-24-2008, 08:10 AM
Senior Member
 
Posts: 50
Default

Is the query a SQL search into the MySQL DB? Is there a easy way to get a list of the valid fields?
Reply With Quote
  #4 (permalink)  
Old 03-24-2008, 08:28 AM
Zimbra Consultant & Moderator
 
Posts: 20,312
Default

If you run 'zmmailbox help' it will give you a list of help sections that describe the fields you can use to search.
__________________
Regards


Bill

Last edited by phoenix; 02-18-2009 at 05:56 AM..
Reply With Quote
  #5 (permalink)  
Old 03-24-2008, 08:37 AM
Zimbra Employee
 
Posts: 1,434
Default

Another (probably better) option is to set zimbraPrefInboxUnreadLifetime on the account.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #6 (permalink)  
Old 03-24-2008, 09:07 AM
Senior Member
 
Posts: 50
Default

zimbraPrefInboxUnreadLifetime would be an awesome/easy way to do this, but I need to script something that will fit within our business rules.

Is there anymore docs on the search rather then zmmailbox help search?
Reply With Quote
  #7 (permalink)  
Old 04-29-2008, 06:43 AM
Senior Member
 
Posts: 50
Default

zmmailbox help search doesn't really give any details on how to search for messages within a date range. What I'm doing to find the messages I want to delete is:

1. zmprov getMailboxInfo userid@domain.
2. Get the mboxgrooup#
3. Logging into mysql using a query to find the messages.
4. Then zmmailbox -z -m userid@domain deleteItem #-#

My question is what format is the date field? I see it is a unsigned int.
Reply With Quote
  #8 (permalink)  
Old 04-30-2008, 08:22 AM
Senior Member
 
Posts: 50
Default

Can anybody decipher date: 1209569274
Reply With Quote
  #9 (permalink)  
Old 04-30-2008, 01:04 PM
Partner (VAR/HSP)
 
Posts: 67
Default

Quote:
Originally Posted by drhughes View Post
Can anybody decipher date: 1209569274
That is a UNIX time stamp.

1209569274 = Wed, 30 Apr 2008 15:27:54 GMT

Used Epoch Converter - Unix Timestamp Converter to convert it to human readable format.

Hope that helps!
Dusty
__________________
CoSentry - www.cosentry.com - Co-Location & Business Resiliency Solutions
Reply With Quote
  #10 (permalink)  
Old 06-03-2008, 07:48 AM
Senior Member
 
Posts: 50
Default Delete messages older then x number of days

Below is some code I have been playing with in a test environment. It will move unread email that is older then x number of days to the users /Trash folder for the system to clean up later.

I use three mailbox servers so I have designed the code to run on all three machines.

I strongly suggest making a backup before running. Use the following code at your own risk. I take no responsibility. You have been warned.

Code:
#!/bin/bash
#Move unread mail older then givendate from users mailboxes to /Trash
#Make a backup before running.  
#
#USE AT YOUR OWN RISK!
#

emaildomain="enter_email_domain_here"

days=$(date -d $1' days ago' '+%D')
hn=`hostname`"."`dnsdomainname`

who=`whoami`
if [ "$who" != "zimbra" ]
then
 echo
 echo "Please su to the zimbra user before running this script"
 echo
 exit
fi

if [ -z "$1" ]; then
 echo
        echo -e "\nUsage: deletemail <number of days ago>"
        echo
        exit
fi

echo "Deleting messages older then $days"

echo "Building user list for $hn"
zmprov gqu $hn | grep $emaildomain |cut -f 1 -d' '> /tmp/del-$hn.tmp

echo "Moving mail to /Trash"
for x in $(tail -1 /tmp/del-$hn.tmp)
do
 echo "Currently working on: $x"
 for y in $(zmmailbox -z -m $x search -t message -l 9999 "(before:$days)(is:unread)"|awk {'print $2'}|grep [0-9]|grep -v ,)
 do
  zmmailbox -z -m $x mm $y "/Trash"
  zmmailbox -z -m $x fm $y 1
 done
done
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.