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
|
|
|
* Sends meeting invitations. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace grommunio\DAV; |
11
|
|
|
|
12
|
|
|
use Sabre\CalDAV\Schedule\IMipPlugin; |
13
|
|
|
use Sabre\VObject\ITip\Message; |
14
|
|
|
|
15
|
|
|
class GrommunioIMipPlugin extends IMipPlugin { |
16
|
|
|
private $logger; |
17
|
|
|
protected $gDavBackend; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Constructor. |
21
|
|
|
*/ |
22
|
|
|
public function __construct(GrommunioDavBackend $gDavBackend, GLogger $glogger) { |
23
|
|
|
$this->gDavBackend = $gDavBackend; |
24
|
|
|
$this->logger = $glogger; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Sends out meeting invitation. |
29
|
|
|
* |
30
|
|
|
* Using the information in iTipMessage to send out a meeting |
31
|
|
|
* invitation. |
32
|
|
|
*/ |
33
|
|
|
public function schedule(Message $iTipMessage) { |
34
|
|
|
$this->logger->trace("method: %s - recipient: %s - significantChange: %d - scheduleStatus: %s - message: %s", $iTipMessage->method, $iTipMessage->recipient, $iTipMessage->significantChange, $iTipMessage->scheduleStatus, $iTipMessage->message->serialize()); |
35
|
|
|
|
36
|
|
|
if (!$iTipMessage->significantChange) { |
37
|
|
|
if (!$iTipMessage->scheduleStatus) { |
38
|
|
|
$iTipMessage->scheduleStatus = "1.0;We got the message, but it's not significant enough to warrant an email"; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$recipient = preg_replace('!^mailto:!i', '', $iTipMessage->recipient); |
45
|
|
|
$session = $this->gDavBackend->GetSession(); |
46
|
|
|
$addrbook = $this->gDavBackend->GetAddressBook(); |
47
|
|
|
$store = $this->gDavBackend->GetStore($this->gDavBackend->GetUser()); |
48
|
|
|
$storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]); |
|
|
|
|
49
|
|
|
if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID]) || !isset($storeprops[PR_IPM_SENTMAIL_ENTRYID])) { |
50
|
|
|
/* handle error */ |
51
|
|
|
$this->logger->error("no outbox found aborting user: %s", $this->gDavBackend->GetUser()); |
52
|
|
|
|
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/* create message and convert */ |
57
|
|
|
$outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]); |
58
|
|
|
$newmessage = mapi_folder_createmessage($outbox); |
59
|
|
|
mapi_icaltomapi($session, $store, $addrbook, $newmessage, $iTipMessage->message->serialize(), false); |
|
|
|
|
60
|
|
|
mapi_setprops($newmessage, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_DELETE_AFTER_SUBMIT => false]); |
|
|
|
|
61
|
|
|
|
62
|
|
|
/* clean the recipients (needed since mapi_icaltomapi does not take IC2M_NO_ORGANIZER) */ |
63
|
|
|
$recipientTable = mapi_message_getrecipienttable($newmessage); |
64
|
|
|
$recipientRows = mapi_table_queryallrows($recipientTable, [PR_SMTP_ADDRESS, PR_ROWID]); |
|
|
|
|
65
|
|
|
$removeRecipients = []; |
66
|
|
|
foreach ($recipientRows as $key => $recip) { |
67
|
|
|
if (!isset($recip[PR_SMTP_ADDRESS])) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
if (strcasecmp($recip[PR_SMTP_ADDRESS], $recipient) != 0) { |
71
|
|
|
$removeRecipients[] = $recip; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
if (count($removeRecipients) == count($recipientRows)) { |
75
|
|
|
$this->logger->error("message will have no recipients. List to remove: %s - recipientRows: %s", $removeRecipients, $recipientRows); |
76
|
|
|
|
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
if (count($removeRecipients) > 0) { |
80
|
|
|
mapi_message_modifyrecipients($newmessage, MODRECIP_REMOVE, $removeRecipients); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/* save message and send */ |
84
|
|
|
mapi_savechanges($newmessage); |
85
|
|
|
mapi_message_submitmessage($newmessage); |
86
|
|
|
$this->logger->info("email sent, recipient: %s", $recipient); |
87
|
|
|
$iTipMessage->scheduleStatus = '1.1;Scheduling message sent via iMip'; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|