/usr/lib/python2.7/dist-packages/kopano/freebusy.py is in python-kopano 8.5.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | """
Part of the high-level python bindings for Kopano
Copyright 2017 - Kopano and its licensors (see LICENSE file for details)
"""
import datetime
import time
try:
import libfreebusy
except ImportError:
pass
from MAPI.Tags import (
PR_MAILBOX_OWNER_ENTRYID, PR_ENTRYID
)
from MAPI.Time import (
FileTime,
)
import MAPI.Struct
from .compat import (
unhex as _unhex, repr as _repr
)
# XXX to utils.py?
NANOSECS_BETWEEN_EPOCH = 116444736000000000
def datetime_to_filetime(d):
return FileTime(int(time.mktime(d.timetuple())) * 10000000 + NANOSECS_BETWEEN_EPOCH)
def datetime_to_rtime(d):
return datetime_to_filetime(d).filetime / 600000000
def rtime_to_datetime(r):
return datetime.datetime.fromtimestamp(FileTime(r * 600000000).unixtime)
CODE_STATUS = {
0: 'free',
1: 'tentative',
2: 'busy',
3: 'outofoffice',
}
class FreeBusyBlock(object):
"""FreeBusyBlock class"""
def __init__(self, block):
self.status = CODE_STATUS[block.status]
self.start = rtime_to_datetime(block.start)
self.end = rtime_to_datetime(block.end)
def __unicode__(self):
return u'FreeBusyBlock()'
def __repr__(self):
return _repr(self)
class FreeBusy(object):
"""FreeBusy class"""
def __init__(self, store):
self.store = store
def blocks(self, start=None, end=None):
""" Freebusy blocks
:param start: start of period
:param end: end of period
"""
eid = _unhex(self.store.user.userid)
if start:
ftstart = datetime_to_filetime(start)
else:
ftstart = FileTime(0)
if end:
ftend = datetime_to_filetime(end)
else:
ftend = FileTime(0xFFFFFFFFFFFFFFFF)
fb = libfreebusy.IFreeBusySupport()
fb.Open(self.store.server.mapisession, self.store.mapiobj, False)
fbdata = fb.LoadFreeBusyData([eid], None)
if fbdata in (0, 1): # XXX what?
return
data, status = fbdata
fb.Close()
enum = data.EnumBlocks(ftstart, ftend)
while True:
blocks = enum.Next(100)
if blocks:
for block in blocks:
yield FreeBusyBlock(block)
else:
break
def publish(self, start=None, end=None):
""" Publish freebusy data
:param start: start of period
:param end: end of period
"""
eid = _unhex(self.store.user.userid) # XXX merge with blocks
ftstart, ftend = datetime_to_filetime(start), datetime_to_filetime(end) # XXX tz?
fb = libfreebusy.IFreeBusySupport()
fb.Open(self.store.server.mapisession, self.store.mapiobj, False)
update, status = fb.LoadFreeBusyUpdate([eid], None)
blocks = []
for occ in self.store.calendar.occurrences(start, end):
start = datetime_to_rtime(occ.start)
end = datetime_to_rtime(occ.end)
blocks.append(MAPI.Struct.FreeBusyBlock(start, end, 2))
update.PublishFreeBusy(blocks)
update.SaveChanges(ftstart, ftend)
fb.Close()
def __iter__(self):
return self.blocks()
def __unicode__(self):
return u'FreeBusy()'
def __repr__(self):
return _repr(self)
|