File: searchfolder_cleaning.py

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (24 lines) | stat: -rw-r--r-- 761 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-or-later

import datetime

import kopano

for u in kopano.users():
    print('User: %s' % u.name)
    findroot = u.findroot
    if not findroot:
        print('No findroot for user "%s"' % u.name)
        continue  
  
    # Saved searchfolder list
    saved_sf = list(u.store.searches())

    # If the search folder is a permanent search folder, we keep it.
    # If it's a normal search folder that's older than 7 days, remove it for performance improvement.
    for sf in findroot.folders():
        if sf not in saved_sf:
            if sf.created < datetime.datetime.now() - datetime.timedelta(days=7):
                print('Removing searchfolder "%s"' % sf.name)
                findroot.delete(sf)