Example #1
0
 private function _handleInvitations(\GO\Email\Model\ImapMessage $imapMessage, $params, $response)
 {
     if (!GO::modules()->isInstalled('calendar')) {
         return $response;
     }
     $vcalendar = $imapMessage->getInvitationVcalendar();
     if ($vcalendar) {
         $vevent = $vcalendar->vevent[0];
         //is this an update for a specific recurrence?
         $recurrenceDate = isset($vevent->{"recurrence-id"}) ? $vevent->{"recurrence-id"}->getDateTime()->format('U') : 0;
         //find existing event
         $event = \GO\Calendar\Model\Event::model()->findByUuid((string) $vevent->uid, $imapMessage->account->user_id, $recurrenceDate);
         //			var_dump($event);
         $uuid = (string) $vevent->uid;
         $alreadyProcessed = false;
         if ($event) {
             //import to check if there are relevant updates
             $event->importVObject($vevent, array(), true);
             $alreadyProcessed = false;
             //!$event->isModified($event->getRelevantMeetingAttributes());
             //				throw new \Exception(\GO\Base\Util\Date::get_timestamp($vevent->{"last-modified"}->getDateTime()->format('U')).' < '.\GO\Base\Util\Date::get_timestamp($event->mtime));
             //				if($vevent->{"last-modified"}) {
             //					$alreadyProcessed=$vevent->{"last-modified"}->getDateTime()->format('U')<=$event->mtime && $event->is_organizer;
             //				}else
             //				{
             //					$alreadyProcessed=!$event->isModified($event->getRelevantMeetingAttributes());
             //				}
         }
         //			if(!$event || $event->is_organizer){
         switch ($vcalendar->method) {
             case 'CANCEL':
                 $response['iCalendar']['feedback'] = GO::t('iCalendar_event_cancelled', 'email');
                 break;
             case 'REPLY':
                 $response['iCalendar']['feedback'] = GO::t('iCalendar_update_available', 'email');
                 break;
             case 'REQUEST':
                 $response['iCalendar']['feedback'] = GO::t('iCalendar_event_invitation', 'email');
                 break;
         }
         if ($vcalendar->method != 'REQUEST' && $vcalendar->method != 'PUBLISH' && !$event) {
             $response['iCalendar']['feedback'] = GO::t('iCalendar_event_not_found', 'email');
         }
         $response['iCalendar']['invitation'] = array('uuid' => $uuid, 'email_sender' => $response['sender'], 'email' => $imapMessage->account->getDefaultAlias()->email, 'event_id' => $event ? $event->id : 0, 'is_organizer' => $event && $event->is_organizer, 'is_processed' => $alreadyProcessed, 'is_update' => !$alreadyProcessed && $vcalendar->method == 'REPLY', 'is_invitation' => !$alreadyProcessed && $vcalendar->method == 'REQUEST', 'is_cancellation' => $vcalendar->method == 'CANCEL');
         //			}elseif($event){
         //			if($event){
         //				$response['attendance_event_id']=$event->id;
         //			}
         //			$subject = (string) $vevent->summary;
         if (empty($uuid) || strpos($response['htmlbody'], $uuid) === false) {
             //if(!$event){
             $event = new \GO\Calendar\Model\Event();
             try {
                 $event->importVObject($vevent, array(), true);
                 //}
                 $response['htmlbody'] .= '<div style="border: 1px solid black;margin-top:10px">' . '<div style="font-weight:bold;margin:2px;">' . GO::t('attachedAppointmentInfo', 'email') . '</div>' . $event->toHtml() . '</div>';
             } catch (\Exception $e) {
                 //$response['htmlbody'].= '<div style="border: 1px solid black;margin-top:10px">Could not render event</div>';
             }
         }
     }
     return $response;
 }
Example #2
0
 private function _importSmarterMailXml($params, File $file)
 {
     $sXml = new SimpleXMLElement($file->getContents());
     $count = 0;
     $failed = array();
     foreach ($sXml->children() as $obj) {
         if ($obj->getName() == 'Event') {
             $event = new Event();
             try {
                 $data = (string) $obj->Data;
                 //					\GO::debug($data);
                 $vObject = \GO\Base\VObject\Reader::read($data);
                 $event->importVObject($vObject->vevent[0], array('calendar_id' => $params['calendar_id']));
                 $count++;
                 //					break;
             } catch (\Exception $e) {
                 $failed[] = $e->getMessage();
             }
         }
     }
     $response['feedback'] = sprintf(\GO::t('import_success', 'calendar'), $count);
     if (count($failed)) {
         $response['feedback'] .= "\n\n" . count($failed) . " events failed: " . implode("\n", $failed);
     }
     return $response;
 }