Zarafa Question: Clean all items from recycle bins that are older than x days

Hello everybody.

We have a question that I would have asked in the zarafa forum, but I just realizied it is closed and I was redirected to this forum. I hope there is anyone here that can help us.

We are using groupware/zarafa in version 7.2.4-29 and we would like to automatically delete all items that are older than e.g. 5 days from all recycle bins. Is there a way to do this server-sided?

Thanks in advance!

Marcel Schmitz,
Ing.-Büro Dr. Plesnik GmbH

You can cron-run a server-side python-script for this purpose:
E.g. delete_olditems.py taken from python-zarafa:

#!/usr/bin/env python

import zarafa
from datetime import datetime, timedelta
import time
import sys


def opt_args():
    parser = zarafa.parser('skpcufm')
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='enable verbose mode')
    return parser.parse_args()


def  main():
    options, args = opt_args()

    assert args, 'You must specify the amount of days!'

    try:
        val = int(args[0])
    except ValueError:
        return sys.exit("Days not specified as a number!")

    for user in zarafa.Server(options=options).users(parse=True):
        print 'Running for user: ', user.name
        try:
            for folder in user.store.folders(parse=True):
                print 'Folder: ' , folder.name
                for item in folder.items():
                    if not item.received:
                        continue
                    if item.received < datetime.today() - timedelta(days=int(args[0])):
                        if options.verbose:
                            print 'Item: ', item.subject, 'Received: ', datetime.today() - item.received
                        else:
                            print 'Item: ', item.subject

                        if options.modify:
                            folder.delete([item])
        except:
            continue;

if __name__ == '__main__':
    main()

++umgfoin

Hi Marcel,

This should do the trick:
https://github.com/zarafagroupware/zarafa-tools/blob/master/mailstore/cleanupscripts/cleanup.py

python cleanup.py --user <user>  --wastebasket --days <days>

See --help for more options

And for kopano it should be this script
https://stash.kopano.io/projects/KSC/repos/core-tools/browse/kopano-cleanup.py

Regards,

Robin

@robing Thank you for that answer.
I tried running the script and it does delete some items, but it doesn´t touch the Recycle Bin my Thunderbird shows…

@IngBueroPlesnik said in Zarafa Question: Clean all items from recycle bins that are older than x days:

I tried running the script and it does delete some items, but it doesn´t touch the Recycle Bin my Thunderbird shows…

The script (as above) processes items in the default wastebasket-folder, usually named “Deleted Items” (or “Gelöschte Objekte” with German localization).

Make sure, thunderbird moves deleted items into this folder and not to another location (e.g. a local folder named ***“trash”***). Depending on your thunderbird-version this might be non-trivial.

The script I copied above, scan’s for items in the entire folder-tree.
Anyway, both scripts might be easily modified to fit other needs, too.

++umgfoin.

@umgfoin said in Zarafa Question: Clean all items from recycle bins that are older than x days:

The script (as above) processes items in the default wastebasket-folder, usually named “Deleted Items” (or “Gelöschte Objekte” with German localization).
Make sure, thunderbird moves deleted items into this folder and not to another location (e.g. a local folder named “trash”). Depending on your thunderbird-version this might be non-trivial.
The script I copied above, scan’s for items in the entire folder-tree.
Anyway, both scripts might be easily modified to fit other needs, too.

Is it hard to modify the script, so that it can clear the “Papierkorb” (Path: imap://example.company.local/Trash).
Because all our companies thunderbirds are configured to move deleted items to those paths in all of our inboxes.

Is it hard to modify the script, so that it can clear the “Papierkorb” (Path: imap://example.company.local/Trash).

No,

  1. python delete_olditems.py --help
  2. python delete_olditems.py --folder="Papierkorb" --modify 5
    python delete_olditems.py --folder="Trash" --modify 5

@umgfoin
Thank you very much!
I´m running the script for the first time right now and I´ll post again when it´s done and I´ve checked the results.