]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CalDAV/Schedule/IMip.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CalDAV / Schedule / IMip.php
1 <?php
2
3 /**
4  * iMIP handler.
5  *
6  * This class is responsible for sending out iMIP messages. iMIP is the
7  * email-based transport for iTIP. iTIP deals with scheduling operations for
8  * iCalendar objects.
9  *
10  * If you want to customize the email that gets sent out, you can do so by
11  * extending this class and overriding the sendMessage method.
12  *
13  * @package Sabre
14  * @subpackage CalDAV
15  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
16  * @author Evert Pot (http://www.rooftopsolutions.nl/)
17  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
18  */
19 class Sabre_CalDAV_Schedule_IMip {
20
21     /**
22      * Email address used in From: header.
23      *
24      * @var string
25      */
26     protected $senderEmail;
27
28     /**
29      * Creates the email handler.
30      *
31      * @param string $senderEmail. The 'senderEmail' is the email that shows up
32      *                             in the 'From:' address. This should
33      *                             generally be some kind of no-reply email
34      *                             address you own.
35      */
36     public function __construct($senderEmail) {
37
38         $this->senderEmail = $senderEmail;
39
40     }
41
42     /**
43      * Sends one or more iTip messages through email.
44      *
45      * @param string $originator Originator Email
46      * @param array $recipients Array of email addresses
47      * @param Sabre_VObject_Component $vObject
48      * @param string $principal Principal Url of the originator
49      * @return void
50      */
51     public function sendMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
52
53         foreach($recipients as $recipient) {
54
55             $to = $recipient;
56             $replyTo = $originator;
57             $subject = 'SabreDAV iTIP message';
58
59             switch(strtoupper($vObject->METHOD)) {
60                 case 'REPLY' :
61                     $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
62                     break;
63                 case 'REQUEST' :
64                     $subject = 'Invitation for: ' .$vObject->VEVENT->SUMMARY;
65                     break;
66                 case 'CANCEL' :
67                     $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
68                     break;
69             }
70
71             $headers = array();
72             $headers[] = 'Reply-To: ' . $replyTo;
73             $headers[] = 'From: ' . $this->senderEmail;
74             $headers[] = 'Content-Type: text/calendar; method=' . (string)$vObject->method . '; charset=utf-8';
75             if (Sabre_DAV_Server::$exposeVersion) {
76                 $headers[] = 'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY;
77             }
78
79             $vcalBody = $vObject->serialize();
80
81             $this->mail($to, $subject, $vcalBody, $headers);
82
83         }
84
85     }
86
87     /**
88      * This function is reponsible for sending the actual email.
89      *
90      * @param string $to Recipient email address
91      * @param string $subject Subject of the email
92      * @param string $body iCalendar body
93      * @param array $headers List of headers
94      * @return void
95      */
96     protected function mail($to, $subject, $body, array $headers) {
97
98         mail($to, $subject, $body, implode("\r\n", $headers));
99
100     }
101
102
103 }