File: rule.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 (32 lines) | stat: -rwxr-xr-x 821 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
25
26
27
28
29
30
31
32
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# client-side rule, which moves incoming mails with 'spam' in the subject to the junk folder

# usage: ./rule.py -U username -P password

import kopano
import time

class importer:
    def __init__(self, folder, target):
        self.folder = folder
        self.target = target

    def update(self, item, flags):
        if 'spam' in item.subject:
            print('trashing..', item)
            self.folder.move(item, self.target)

    def delete(self, item, flags):
        pass

server = kopano.Server()

store = server.user(server.options.auth_user).store # auth_user checks -U/--auth-user command-line option
inbox, junk = store.inbox, store.junk

state = inbox.state
while True:
    state = inbox.sync(importer(inbox, junk), state)
    time.sleep(1)