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