import time
import zarafa

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 = zarafa.Server()
folder = server.user('user1').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)
