/usr/share/php/sabre21/Sabre/CalDAV/Schedule/IMipPlugin.php is in php-sabre-dav-2.1 2.1.10-1ubuntu1.
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | <?php
namespace Sabre\CalDAV\Schedule;
use Sabre\DAV;
use Sabre\VObject;
use Sabre\VObject\ITip;
/**
* iMIP handler.
*
* This class is responsible for sending out iMIP messages. iMIP is the
* email-based transport for iTIP. iTIP deals with scheduling operations for
* iCalendar objects.
*
* If you want to customize the email that gets sent out, you can do so by
* extending this class and overriding the sendMessage method.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class IMipPlugin extends DAV\ServerPlugin {
/**
* Email address used in From: header.
*
* @var string
*/
protected $senderEmail;
/**
* Server class
*
* @var DAV\Server
*/
protected $server;
/**
* ITipMessage
*
* @var ITip\Message
*/
protected $itipMessage;
/**
* Creates the email handler.
*
* @param string $senderEmail. The 'senderEmail' is the email that shows up
* in the 'From:' address. This should
* generally be some kind of no-reply email
* address you own.
*/
function __construct($senderEmail) {
$this->senderEmail = $senderEmail;
}
/*
* This initializes the plugin.
*
* This function is called by Sabre\DAV\Server, after
* addPlugin is called.
*
* This method should set up the required event subscriptions.
*
* @param Server $server
* @return void
*/
function initialize(DAV\Server $server) {
$server->on('schedule', [$this, 'schedule'], 120);
}
/**
* Returns a plugin name.
*
* Using this name other plugins will be able to access other plugins
* using \Sabre\DAV\Server::getPlugin
*
* @return string
*/
function getPluginName() {
return 'imip';
}
/**
* Event handler for the 'schedule' event.
*
* @param ITip\Message $iTipMessage
* @return void
*/
function schedule(ITip\Message $iTipMessage) {
// Not sending any emails if the system considers the update
// insignificant.
if (!$iTipMessage->significantChange) {
if (!$iTipMessage->scheduleStatus) {
$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
}
return;
}
$summary = $iTipMessage->message->VEVENT->SUMMARY;
if (parse_url($iTipMessage->sender, PHP_URL_SCHEME)!=='mailto')
return;
if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME)!=='mailto')
return;
$sender = substr($iTipMessage->sender,7);
$recipient = substr($iTipMessage->recipient,7);
if ($iTipMessage->senderName) {
$sender = $iTipMessage->senderName . ' <' . $sender . '>';
}
if ($iTipMessage->recipientName) {
$recipient = $iTipMessage->recipientName . ' <' . $recipient . '>';
}
$subject = 'SabreDAV iTIP message';
switch(strtoupper($iTipMessage->method)) {
case 'REPLY' :
$subject = 'Re: ' . $summary;
break;
case 'REQUEST' :
$subject = $summary;
break;
case 'CANCEL' :
$subject = 'Cancelled: ' . $summary;
break;
}
$headers = [
'Reply-To: ' . $sender,
'From: ' . $this->senderEmail,
'Content-Type: text/calendar; charset=UTF-8; method=' . $iTipMessage->method,
];
if (DAV\Server::$exposeVersion) {
$headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION;
}
$this->mail(
$recipient,
$subject,
$iTipMessage->message->serialize(),
$headers
);
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
}
// @codeCoverageIgnoreStart
// This is deemed untestable in a reasonable manner
/**
* This function is reponsible for sending the actual email.
*
* @param string $to Recipient email address
* @param string $subject Subject of the email
* @param string $body iCalendar body
* @param array $headers List of headers
* @return void
*/
protected function mail($to, $subject, $body, array $headers) {
mail($to, $subject, $body, implode("\r\n", $headers));
}
// @codeCoverageIgnoreEnd
}
|