1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
4
|
|
|
* SPDX-FileCopyrightText: Copyright 2016 - 2018 Kopano b.v. |
5
|
|
|
* SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH |
6
|
|
|
* |
7
|
|
|
* Checks Free/Busy information of requested recipients. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace grommunio\DAV; |
11
|
|
|
|
12
|
|
|
use Sabre\CalDAV\Schedule\Plugin; |
13
|
|
|
use Sabre\VObject\Component; |
14
|
|
|
use Sabre\VObject\Reader; |
15
|
|
|
|
16
|
|
|
class GrommunioSchedulePlugin extends Plugin { |
17
|
|
|
private $logger; |
18
|
|
|
protected $gDavBackend; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor. |
22
|
|
|
*/ |
23
|
|
|
public function __construct(GrommunioDavBackend $gDavBackend, GLogger $glogger) { |
24
|
|
|
$this->gDavBackend = $gDavBackend; |
25
|
|
|
$this->logger = $glogger; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get the Free/Busy information for a recipient. |
30
|
|
|
* |
31
|
|
|
* Given email, start and end time the function will return |
32
|
|
|
* the freebusy blocks. |
33
|
|
|
* |
34
|
|
|
* @param string $email |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
protected function getFreeBusyForEmail($email, \DateTimeInterface $start, \DateTimeInterface $end, Component $request) { |
39
|
|
|
$this->logger->trace("email: %s - start: %d - end: %d", $email, $start->getTimestamp(), $end->getTimestamp()); |
40
|
|
|
|
41
|
|
|
$addrbook = $this->gDavBackend->GetAddressBook(); |
42
|
|
|
$email = preg_replace('!^mailto:!i', '', $email); |
43
|
|
|
$search = [[PR_DISPLAY_NAME => $email]]; |
|
|
|
|
44
|
|
|
$userarr = mapi_ab_resolvename($addrbook, $search, EMS_AB_ADDRESS_LOOKUP); |
|
|
|
|
45
|
|
|
if (!empty($userarr)) { |
46
|
|
|
$result = mapi_getuserfreebusyical($this->gDavBackend->GetSession(), $userarr[0][PR_ENTRYID], $start->getTimestamp(), $end->getTimestamp()); |
|
|
|
|
47
|
|
|
if ($result) { |
48
|
|
|
$vcalendar = Reader::read($result, Reader::OPTION_FORGIVING); |
49
|
|
|
|
50
|
|
|
return [ |
51
|
|
|
'calendar-data' => $vcalendar, |
52
|
|
|
'request-status' => '2.0;Success', |
53
|
|
|
'href' => 'mailto:' . $email, |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return [ |
59
|
|
|
'request-status' => '3.7;Could not find principal', |
60
|
|
|
'href' => 'mailto:' . $email, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|