File: sync.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 (42 lines) | stat: -rwxr-xr-x 1,205 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
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# basic system and folder level synchronization

# usage: ./sync.py (change USER to username)

import time
import kopano

USER = 'user1'

class Importer:
    def update(self, item, flags):
        print('update', item.store.user, item.received, item.subject, item.sender.email, [r.email for r in item.recipients()])

    def delete(self, item, flags): # only item.sourcekey is available here!
        pass

server = kopano.Server()
folder = server.user(USER).store.folder('Inbox')

folder_state = folder.state
print('current folder state:', folder_state)

print('initial sync..')
syncstate = folder.sync(Importer()) # from the beginning of time
print('incremental sync..')
for x in range(5):
    newstate = folder.sync(Importer(), folder_state) # from last known state
    if newstate != folder_state:
        print('new state:', newstate)
        folder_state = newstate
    time.sleep(1)

system_state = server.state
print('current system state:', system_state)

print('incremental system sync..') # initial sync currently not possible system-wide
for x in range(5):
    system_state = server.sync(Importer(), system_state)
    time.sleep(1)