searchfolder_cleaning.py 719 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python
  2. import datetime
  3. import kopano
  4. for u in kopano.users():
  5. print('User: %s' % u.name)
  6. findroot = u.findroot
  7. if not findroot:
  8. print('No findroot for user "%s"' % u.name)
  9. continue
  10. # Saved searchfolder list
  11. saved_sf = list(u.store.searches())
  12. # If the search folder is a permanent search folder, we keep it.
  13. # If it's a normal search folder that's older than 7 days, remove it for performance improvement.
  14. for sf in findroot.folders():
  15. if sf not in saved_sf:
  16. if sf.created < datetime.datetime.now() - datetime.timedelta(days=7):
  17. print('Removing searchfolder "%s"' % sf.name)
  18. findroot.delete(sf)