ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
IMipPlugin.php
Go to the documentation of this file.
1<?php
2
4
5use Sabre\DAV;
7
23
29 protected $senderEmail;
30
36 protected $itipMessage;
37
47
48 $this->senderEmail = $senderEmail;
49
50 }
51
52 /*
53 * This initializes the plugin.
54 *
55 * This function is called by Sabre\DAV\Server, after
56 * addPlugin is called.
57 *
58 * This method should set up the required event subscriptions.
59 *
60 * @param DAV\Server $server
61 * @return void
62 */
63 function initialize(DAV\Server $server) {
64
65 $server->on('schedule', [$this, 'schedule'], 120);
66
67 }
68
77 function getPluginName() {
78
79 return 'imip';
80
81 }
82
89 function schedule(ITip\Message $iTipMessage) {
90
91 // Not sending any emails if the system considers the update
92 // insignificant.
93 if (!$iTipMessage->significantChange) {
94 if (!$iTipMessage->scheduleStatus) {
95 $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
96 }
97 return;
98 }
99
100 $summary = $iTipMessage->message->VEVENT->SUMMARY;
101
102 if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto')
103 return;
104
105 if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto')
106 return;
107
108 $sender = substr($iTipMessage->sender, 7);
109 $recipient = substr($iTipMessage->recipient, 7);
110
111 if ($iTipMessage->senderName) {
112 $sender = $iTipMessage->senderName . ' <' . $sender . '>';
113 }
114 if ($iTipMessage->recipientName) {
115 $recipient = $iTipMessage->recipientName . ' <' . $recipient . '>';
116 }
117
118 $subject = 'SabreDAV iTIP message';
119 switch (strtoupper($iTipMessage->method)) {
120 case 'REPLY' :
121 $subject = 'Re: ' . $summary;
122 break;
123 case 'REQUEST' :
124 $subject = $summary;
125 break;
126 case 'CANCEL' :
127 $subject = 'Cancelled: ' . $summary;
128 break;
129 }
130
131 $headers = [
132 'Reply-To: ' . $sender,
133 'From: ' . $this->senderEmail,
134 'Content-Type: text/calendar; charset=UTF-8; method=' . $iTipMessage->method,
135 ];
136 if (DAV\Server::$exposeVersion) {
137 $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION;
138 }
139 $this->mail(
140 $recipient,
141 $subject,
142 $iTipMessage->message->serialize(),
143 $headers
144 );
145 $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
146
147 }
148
149 // @codeCoverageIgnoreStart
150 // This is deemed untestable in a reasonable manner
151
161 protected function mail($to, $subject, $body, array $headers) {
162
163 mail($to, $subject, $body, implode("\r\n", $headers));
164
165 }
166
167 // @codeCoverageIgnoreEnd
168
180 function getPluginInfo() {
181
182 return [
183 'name' => $this->getPluginName(),
184 'description' => 'Email delivery (rfc6047) for CalDAV scheduling',
185 'link' => 'http://sabre.io/dav/scheduling/',
186 ];
187
188 }
189
190}
An exception for terminatinating execution or to throw for unit testing.
__construct($senderEmail)
Creates the email handler.
Definition: IMipPlugin.php:46
getPluginInfo()
Returns a bunch of meta-data about the plugin.
Definition: IMipPlugin.php:180
getPluginName()
Returns a plugin name.
Definition: IMipPlugin.php:77
schedule(ITip\Message $iTipMessage)
Event handler for the 'schedule' event.
Definition: IMipPlugin.php:89
mail($to, $subject, $body, array $headers)
This function is responsible for sending the actual email.
Definition: IMipPlugin.php:161
initialize(DAV\Server $server)
Definition: IMipPlugin.php:63
The baseclass for all server plugins.
Main DAV server class.
Definition: Server.php:23
static $exposeVersion
Definition: Server.php:184
const VERSION
Full version number.
Definition: Version.php:17
This is the abstract base class for both the Request and Response objects.
Definition: Message.php:14
$summary
Definition: cron.php:24
$server
Definition: sabredav.php:48