Delete un-read email older the X days

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Mon Mar 24, 2008 9:35 am

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


phoenix
Ambassador
Ambassador
Posts: 26342
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

Delete un-read email older the X days

Postby phoenix » Mon Mar 24, 2008 9:37 am

Regards

Bill

Rspamd: A high performance spamassassin replacement

If you'd like to see this implemented in a future version of ZCS then please vote on Bugzilla entries 97706 & 108168
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Mon Mar 24, 2008 10:10 am

Is the query a SQL search into the MySQL DB? Is there a easy way to get a list of the valid fields?
phoenix
Ambassador
Ambassador
Posts: 26342
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

Delete un-read email older the X days

Postby phoenix » Mon Mar 24, 2008 10:28 am

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

Rspamd: A high performance spamassassin replacement

If you'd like to see this implemented in a future version of ZCS then please vote on Bugzilla entries 97706 & 108168
dkarp
Elite member
Elite member
Posts: 1410
Joined: Fri Sep 12, 2014 9:52 pm

Delete un-read email older the X days

Postby dkarp » Mon Mar 24, 2008 10:37 am

Another (probably better) option is to set zimbraPrefInboxUnreadLifetime on the account.
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Mon Mar 24, 2008 11:07 am

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?
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Tue Apr 29, 2008 8:43 am

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.
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Wed Apr 30, 2008 10:22 am

Can anybody decipher date: 1209569274
dustys
Advanced member
Advanced member
Posts: 67
Joined: Fri Sep 12, 2014 10:25 pm

Delete un-read email older the X days

Postby dustys » Wed Apr 30, 2008 3:04 pm

[quote user="drhughes"]Can anybody decipher date: 1209569274[/QUOTE]

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
drhughes
Advanced member
Advanced member
Posts: 50
Joined: Fri Sep 12, 2014 11:15 pm

Delete un-read email older the X days

Postby drhughes » Tue Jun 03, 2008 9:48 am

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.


#!/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 "
Usage: deletemail "

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


Return to “Administrators”

Who is online

Users browsing this forum: No registered users and 10 guests