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
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.
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
19 class Sabre_CalDAV_Schedule_IMip {
22 * Email address used in From: header.
26 protected $senderEmail;
29 * Creates the email handler.
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
36 public function __construct($senderEmail) {
38 $this->senderEmail = $senderEmail;
43 * Sends one or more iTip messages through email.
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
51 public function sendMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
53 foreach($recipients as $recipient) {
56 $replyTo = $originator;
57 $subject = 'SabreDAV iTIP message';
59 switch(strtoupper($vObject->METHOD)) {
61 $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
64 $subject = 'Invitation for: ' .$vObject->VEVENT->SUMMARY;
67 $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
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;
79 $vcalBody = $vObject->serialize();
81 $this->mail($to, $subject, $vcalBody, $headers);
88 * This function is reponsible for sending the actual email.
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
96 protected function mail($to, $subject, $body, array $headers) {
98 mail($to, $subject, $body, implode("\r\n", $headers));