$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"); if (count($props) > 0) { $tzid = $props[0]->Value(); // printf("TZID %s\n", $props[0]->Value()); } // print_r(TimezoneUtil::GetFullTZFromTZName($tzid));
/** * Processes a response to a meeting request. * * @param string $requestid id of the object containing the request * @param string $folderid id of the parent folder of $requestid * @param string $response * * @access public * @return string id of the created/updated calendar obj * @throws StatusException */ public function MeetingResponse($requestid, $folderid, $response) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse('%s','%s','%s')", $requestid, $folderid, $response)); $folderImapid = $this->getImapIdFromFolderId($folderid); $this->imap_reopen_folder($folderImapid); $mail = @imap_fetchheader($this->mbox, $requestid, FT_UID) . @imap_body($this->mbox, $requestid, FT_PEEK | FT_UID); if (empty($mail)) { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, message not found, maybe was moved"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } $mobj = new Mail_mimeDecode($mail); unset($mail); $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8')); unset($mobj); $Mail_RFC822 = new Mail_RFC822(); $from_header = $this->getDefaultFromValue(); $fromaddr = $this->parseAddr($Mail_RFC822->parseAddressList($from_header)); $to_header = ""; if (isset($message->headers["from"])) { $to_header = $message->headers["from"]; } else { if (isset($message->headers["return-path"])) { $to_header = $message->headers["return-path"]; } else { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, no reply address"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } } $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($to_header)); if (isset($message->headers["subject"])) { $subject_header = $message->headers["subject"]; } else { $subject_header = ""; } $body_part = null; if (isset($message->parts)) { $mparts = $message->parts; for ($i = 0; $i < count($mparts); $i++) { $part = $mparts[$i]; //recursively add parts if (isset($part->ctype_primary) && $part->ctype_primary == "multipart" && (isset($part->ctype_secondary) && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related"))) { foreach ($part->parts as $spart) { $mparts[] = $spart; } continue; } if (is_calendar($part)) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - text/calendar part found, trying to reply")); $body_part = $this->replyMeetingCalendar($part, $response); } } unset($mparts); } unset($message); if ($body_part === null) { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, no calendar part modified"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - Creating response message")); $mail = new Mail_mimepart(); $headers = array("MIME-version" => "1.0", "From" => $mail->encodeHeader("from", $from_header, "UTF-8"), "To" => $mail->encodeHeader("to", $to_header, "UTF-8"), "Date" => gmdate("D, d M Y H:i:s", time()) . " GMT", "Subject" => $mail->encodeHeader("subject", $subject_header, "UTF-8"), "Content-class" => "urn:content-classes:calendarmessage", "Content-transfer-encoding" => "8BIT"); unset($mail); $mail = new Mail_mimepart($body_part, array("content_type" => "text/calendar; method=REPLY; charset=UTF-8", "headers" => $headers)); $encoded_mail = $mail->encode(); unset($mail); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - Response message")); foreach ($encoded_mail["headers"] as $k => $v) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s: %s", $k, $v)); } ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s", $encoded_mail["body"])); $send = $this->sendMessage($fromaddr, $toaddr, $encoded_mail["headers"], $encoded_mail["body"]); if ($send) { $this->saveSentMessage($encoded_mail["headers"], $encoded_mail["body"]); } unset($encoded_mail); return $send; }