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
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.
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
21 class Sabre_CalDAV_Schedule_IMip {
24 * Email address used in From: header.
28 protected $senderEmail;
31 * Creates the email handler.
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
38 public function __construct($senderEmail) {
40 $this->senderEmail = $senderEmail;
45 * Sends one or more iTip messages through email.
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
53 public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
55 foreach($recipients as $recipient) {
58 $replyTo = $originator;
59 $subject = 'SabreDAV iTIP message';
61 switch(strtoupper($vObject->METHOD)) {
63 $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
66 $subject = 'Invitation for: ' .$vObject->VEVENT->SUMMARY;
69 $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
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;
81 $vcalBody = $vObject->serialize();
83 $this->mail($to, $subject, $vcalBody, $headers);
90 * This function is reponsible for sending the actual email.
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
98 protected function mail($to, $subject, $body, array $headers) {
100 mail($to, $subject, $body, implode("\r\n", $headers));