File: delete_pattern.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 (23 lines) | stat: -rwxr-xr-x 778 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
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# delete items which contain character string in subject

# usage: ./delete_pattern.py -u username spam

import kopano

options, args = kopano.parser('cskpUPufm').parse_args()
assert args, 'please specify search pattern'

server = kopano.Server()

for user in server.users(): # checks -u/--user command-line option
    print("Running for user:", user.name)
    for folder in user.store.folders(): # checks -f/--folder command-line option
        print("Folder:", folder.name)
        for item in folder:
            if args[0].lower() in item.subject.lower():
                print("Deleting:", item)
                if options.modify: # checks -m/--modify command-line option
                    folder.delete(item)