function testing_get_method($filename)
{
    $body = file_get_contents($filename);
    $ical = new iCalComponent();
    $ical->ParseFrom($body);
    $props = $ical->GetPropertiesByPath("VCALENDAR/METHOD");
    if (count($props) > 0) {
        printf("METHOD %s\n", $props[0]->Value());
    }
}
<?php

require_once 'vendor/autoload.php';
$body = file_get_contents('testing/samples/meeting_request.txt');
$ical = new iCalComponent();
$ical->ParseFrom($body);
$props = $ical->GetPropertiesByPath('!VTIMEZONE/ATTENDEE');
if (count($props) == 1) {
    if (isset($props[0]->Parameters()["PARTSTAT"])) {
        printf("DOES THIS CAUSE ERROR? %s\n", $props[0]->Parameters()["PARTSTAT"]);
    }
}
// MODIFICATIONS
// METHOD
$ical->SetPValue("METHOD", "REPLY");
//ATTENDEE
$ical->SetCPParameterValue("VEVENT", "ATTENDEE", "PARTSTAT", "ACCEPTED");
printf("%s\n", $ical->Render());
$mail = new Mail_mimepart();
$headers = array("MIME-version" => "1.0", "From" => $mail->encodeHeader("from", "Pedro Picapiedra <*****@*****.**>", "UTF-8"), "To" => $mail->encodeHeader("to", "Pablo Marmol <*****@*****.**>", "UTF-8"), "Date" => gmdate("D, d M Y H:i:s", time()) . " GMT", "Subject" => $mail->encodeHeader("subject", "This is a subject", "UTF-8"), "Content-class" => "urn:content-classes:calendarmessage", "Content-transfer-encoding" => "8BIT");
$mail = new Mail_mimepart($ical->Render(), array("content_type" => "text/calendar; method=REPLY; charset=UTF-8", "headers" => $headers));
$message = "";
$encoded_mail = $mail->encode();
foreach ($encoded_mail["headers"] as $k => $v) {
    $message .= $k . ": " . $v . "\r\n";
}
$message .= "\r\n" . $encoded_mail["body"] . "\r\n";
printf("%s\n", $message);
define('LOGLEVEL', LOGLEVEL_DEBUG);
define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
$props = $ical->GetPropertiesByPath("VTIMEZONE/TZID");
Exemplo n.º 3
0
/**
 * Modify a text/calendar part to transform it in a reply
 *
 * @access private
 * @param $part             MIME part
 * @param $response         Response numeric value
 * @param $condition_value  string
 * @return string MIME text/calendar
 */
function reply_meeting_calendar($part, $response, $username)
{
    $status_attendee = "ACCEPTED";
    // 1 or default is ACCEPTED
    $status_event = "CONFIRMED";
    switch ($response) {
        case 1:
            $status_attendee = "ACCEPTED";
            $status_event = "CONFIRMED";
            break;
        case 2:
            $status_attendee = $status_event = "TENTATIVE";
            break;
        case 3:
            // We won't hit this case ever, because we won't create an event if we are rejecting it
            $status_attendee = "DECLINED";
            $status_event = "CANCELLED";
            break;
    }
    $ical = new iCalComponent();
    $ical->ParseFrom($part->body);
    $ical->SetPValue("METHOD", "REPLY");
    $ical->SetCPParameterValue("VEVENT", "STATUS", $status_event, null);
    // Update my information as attendee, but only mine
    $ical->SetCPParameterValue("VEVENT", "ATTENDEE", "PARTSTAT", $status_attendee, sprintf("MAILTO:%s", $username));
    $ical->SetCPParameterValue("VEVENT", "ATTENDEE", "RSVP", null, sprintf("MAILTO:%s", $username));
    return $ical->Render();
}
Exemplo n.º 4
0
 /**
  * Converts a text/calendar part into SyncMeetingRequest
  *
  * @access private
  * @param $part    MIME part
  * @param $output  SyncMail object
  */
 private function parseMeetingCalendar($part, &$output)
 {
     $ical = new iCalComponent();
     $ical->ParseFrom($part->body);
     if (isset($part->ctype_parameters["method"])) {
         switch (strtolower($part->ctype_parameters["method"])) {
             case "cancel":
                 $output->messageclass = "IPM.Schedule.Meeting.Canceled";
                 break;
             case "counter":
                 $output->messageclass = "IPM.Schedule.Meeting.Resp.Tent";
                 break;
             case "reply":
                 $props = $ical->GetPropertiesByPath('!VTIMEZONE/ATTENDEE');
                 if (count($props) == 1) {
                     $props_params = $props[0]->Parameters();
                     if (isset($props_params["PARTSTAT"])) {
                         switch (strtolower($props_params["PARTSTAT"])) {
                             case "accepted":
                                 $output->messageclass = "IPM.Schedule.Meeting.Resp.Pos";
                                 break;
                             case "needs-action":
                             case "tentative":
                                 $output->messageclass = "IPM.Schedule.Meeting.Resp.Tent";
                                 break;
                             case "declined":
                                 $output->messageclass = "IPM.Schedule.Meeting.Resp.Neg";
                                 break;
                             default:
                                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - Unknown reply status %s", strtolower($props_params["PARTSTAT"])));
                                 $output->messageclass = "IPM.Appointment";
                                 break;
                         }
                     } else {
                         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - No reply status found"));
                         $output->messageclass = "IPM.Appointment";
                     }
                 } else {
                     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - There are not attendees"));
                     $output->messageclass = "IPM.Appointment";
                 }
                 break;
             case "request":
                 $output->messageclass = "IPM.Schedule.Meeting.Request";
                 break;
             default:
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - Unknown method %s", strtolower($part->headers["method"])));
                 $output->messageclass = "IPM.Appointment";
                 break;
         }
     } else {
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - No method header"));
         $output->messageclass = "IPM.Appointment";
     }
     $props = $ical->GetPropertiesByPath('VEVENT/DTSTAMP');
     if (count($props) == 1) {
         $output->meetingrequest->dtstamp = Utils::MakeUTCDate($props[0]->Value());
     }
     $props = $ical->GetPropertiesByPath('VEVENT/UID');
     if (count($props) == 1) {
         $output->meetingrequest->globalobjid = $props[0]->Value();
     }
     $props = $ical->GetPropertiesByPath('VEVENT/DTSTART');
     if (count($props) == 1) {
         $output->meetingrequest->starttime = Utils::MakeUTCDate($props[0]->Value());
         if (strlen($props[0]->Value()) == 8) {
             $output->meetingrequest->alldayevent = 1;
         }
     }
     $props = $ical->GetPropertiesByPath('VEVENT/DTEND');
     if (count($props) == 1) {
         $output->meetingrequest->endtime = Utils::MakeUTCDate($props[0]->Value());
         if (strlen($props[0]->Value()) == 8) {
             $output->meetingrequest->alldayevent = 1;
         }
     }
     $props = $ical->GetPropertiesByPath('VEVENT/ORGANIZER');
     if (count($props) == 1) {
         $output->meetingrequest->organizer = str_ireplace("MAILTO:", "", $props[0]->Value());
     }
     $props = $ical->GetPropertiesByPath('VEVENT/LOCATION');
     if (count($props) == 1) {
         $output->meetingrequest->location = $props[0]->Value();
     }
     $props = $ical->GetPropertiesByPath('VEVENT/CLASS');
     if (count($props) == 1) {
         switch ($props[0]->Value()) {
             case "PUBLIC":
                 $output->meetingrequest->sensitivity = "0";
                 break;
             case "PRIVATE":
                 $output->meetingrequest->sensitivity = "2";
                 break;
             case "CONFIDENTIAL":
                 $output->meetingrequest->sensitivity = "3";
                 break;
             default:
                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->parseMeetingCalendar() - No sensitivity class. Using 2"));
                 $output->meetingrequest->sensitivity = "2";
                 break;
         }
     }
     // Get $tz from first timezone
     $props = $ical->GetPropertiesByPath("VTIMEZONE/TZID");
     if (count($props) > 0) {
         // TimeZones shouldn't have dots
         $tzname = str_replace(".", "", $props[0]->Value());
         $tz = TimezoneUtil::GetFullTZFromTZName($tzname);
     } else {
         $tz = TimezoneUtil::GetFullTZ();
     }
     $output->meetingrequest->timezone = base64_encode(TimezoneUtil::getSyncBlobFromTZ($tz));
     // Fixed values
     $output->meetingrequest->instancetype = 0;
     $output->meetingrequest->responserequested = 1;
     $output->meetingrequest->busystatus = 2;
     // TODO: reminder
     $output->meetingrequest->reminder = "";
 }