How to delete old mails by date

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
vuducanha2
Posts: 4
Joined: Wed Nov 07, 2018 9:18 am

How to delete old mails by date

Postby vuducanha2 » Wed Nov 07, 2018 10:06 am

Hi everybody !
We are using Zimbra 8.0.9 ,
We look forward to having a feature that can help remove or move old emails to the trash !
Ex : Move to trash emails from "mmm/ddd/yyy" to "mmm/ddd/yyy"
What can I do ?
Thank you very much,
Best regards,
Vuducanha2


User avatar
DualBoot
Outstanding Member
Outstanding Member
Posts: 803
Joined: Mon Apr 18, 2016 8:18 pm
Location: Earth
ZCS/ZD Version: ZCS FLOSS - 8.7.11 Mutli servers

Re: How to delete old mails by date

Postby DualBoot » Fri Nov 09, 2018 1:43 pm

Hello,

you can use filter or upgrade to 8.6 to get advantage of retention policy.

See you
pup_seba
Outstanding Member
Outstanding Member
Posts: 503
Joined: Sat Sep 13, 2014 2:43 am
Location: Tarragona - Spain

Re: How to delete old mails by date

Postby pup_seba » Fri Nov 09, 2018 8:32 pm

Hi,

You could always try to script it. The one below would work for items in dumpster. Consider that the maximum amount of items per search result is limited to 1.000. You could try to adapt the script to scan all folders on each account (i guess you would have to nest another for loop this time with a "gaf (get all folders)" maybe?. It will be quite a slow script to execute btw...

Regarding retention policy, what DualBoot suggests makes a lot of sense. I don't have access to a 8.0.9 right now, but I could swear that the option is available there. Could you check it?

"
#!/bin/bash

AGE=30d


for account in `zmprov -l gaa`;
do
echo "$account"
zmmailbox -z -m $account s --dumpster -l 1000 --types message before:-$AGE | sed '/^$/d' | awk 'FNR>3 {print "dumpsterDeleteItem " $2}' > /tmp/$account.$$
if [ -f /tmp/$account.$$ ] & [ -s /tmp/$account.$$ ] ; then
COUNT=`wc -l /tmp/$account.$$ | awk '{print $1}'`
echo "$account: deleting $COUNT emails from dumpster"
zmmailbox -z -m $account -A < /tmp/$account.$$;
else
echo "$account: no emails found"
fi
rm -f /tmp/$account_msgs.$$
done
"

Please, don't go wild with this script...test it carefully in a test enviroment as it will remove things from users mailboxes.

Regards,
Sebastián Greco
Infrastructure Developer @https://www.essiprojects.com/
vuducanha2
Posts: 4
Joined: Wed Nov 07, 2018 9:18 am

Re: How to delete old mails by date

Postby vuducanha2 » Tue Nov 13, 2018 8:07 am

pup_seba wrote:Hi,

You could always try to script it. The one below would work for items in dumpster. Consider that the maximum amount of items per search result is limited to 1.000. You could try to adapt the script to scan all folders on each account (i guess you would have to nest another for loop this time with a "gaf (get all folders)" maybe?. It will be quite a slow script to execute btw...

Regarding retention policy, what DualBoot suggests makes a lot of sense. I don't have access to a 8.0.9 right now, but I could swear that the option is available there. Could you check it?

"
#!/bin/bash

AGE=30d


for account in `zmprov -l gaa`;
do
echo "$account"
zmmailbox -z -m $account s --dumpster -l 1000 --types message before:-$AGE | sed '/^$/d' | awk 'FNR>3 {print "dumpsterDeleteItem " $2}' > /tmp/$account.$$
if [ -f /tmp/$account.$$ ] & [ -s /tmp/$account.$$ ] ; then
COUNT=`wc -l /tmp/$account.$$ | awk '{print $1}'`
echo "$account: deleting $COUNT emails from dumpster"
zmmailbox -z -m $account -A < /tmp/$account.$$;
else
echo "$account: no emails found"
fi
rm -f /tmp/$account_msgs.$$
done
"

Please, don't go wild with this script...test it carefully in a test enviroment as it will remove things from users mailboxes.

Regards,

Thanks Bro :)
I want to create an event when clicking on the button will have a popup menu, but I am making an error here (stop process in line 60) can you point me to the error,
vuducanha2
Posts: 4
Joined: Wed Nov 07, 2018 9:18 am

Re: How to delete old mails by date

Postby vuducanha2 » Tue Nov 13, 2018 8:10 am

Image
vuducanha2
Posts: 4
Joined: Wed Nov 07, 2018 9:18 am

Re: How to delete old mails by date

Postby vuducanha2 » Tue Nov 13, 2018 8:11 am

<blockquote class="imgur-embed-pub" lang="en" data-id="a/QeTHHLN"><a href="//imgur.com/QeTHHLN"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

Code stop in line 60 :(

Return to “Administrators”

Who is online

Users browsing this forum: No registered users and 29 guests