/** * Send the email to the users * * @param \GO\Base\Model\User $user * @param eventAndTaskPdf $pdf * @return Boolean */ private function _sendEmail(\GO\Base\Model\User $user, $pdf) { $filename = \GO\Base\Fs\File::stripInvalidChars($user->name) . '.pdf'; //Set the PDF filename $filename = str_replace(',', '', $filename); $mailSubject = \GO::t('cronEventAndTaskReportMailerSubject', 'calendar'); $body = \GO::t('cronEventAndTaskReportMailerContent', 'calendar'); $message = \GO\Base\Mail\Message::newInstance($mailSubject)->setFrom(\GO::config()->webmaster_email, \GO::config()->title)->addTo($user->email); $message->setHtmlAlternateBody(nl2br($body)); $message->attach(\Swift_Attachment::newInstance($pdf, $filename, 'application/pdf')); \GO::debug('CRON SEND MAIL TO: ' . $user->email); return \GO\Base\Mail\Mailer::newGoInstance()->send($message); }
/** * Export the contact model to a .csv, including the company. * * @param array $params */ public function export($params) { GO::$disableModelCache = true; GO::setMaxExecutionTime(420); // Load the data from the session. $findParams = \GO::session()->values['contact']['findParams']; $findParams->getCriteria()->recreateTemporaryTables(); $model = \GO::getModel(\GO::session()->values['contact']['model']); // Include the companies $findParams->joinRelation('company', 'LEFT'); // Let the export handle all found records without a limit $findParams->limit(0); // Create the statement $stmt = $model->find($findParams); // Create the csv file $csvFile = new \GO\Base\Fs\CsvFile(\GO\Base\Fs\File::stripInvalidChars('export.csv')); // Output the download headers \GO\Base\Util\Http::outputDownloadHeaders($csvFile, false); $csvWriter = new \GO\Base\Csv\Writer('php://output'); $headerPrinted = false; $attrs = array(); $compAttrs = array(); foreach ($stmt as $m) { $iterationStartUnix = time(); if (!$headerPrinted) { $attrs = $m->getAttributes(); $compAttrs = $m->company->getAttributes(); } $header = array(); $record = array(); foreach ($attrs as $attr => $val) { if (!$headerPrinted) { $header[$attr] = $m->getAttributeLabel($attr); } $record[$attr] = $m->{$attr}; } foreach ($compAttrs as $cattr => $cval) { if (!$headerPrinted) { $header[GO::t('company', 'addressbook') . $cattr] = GO::t('company', 'addressbook') . ':' . $m->company->getAttributeLabel($cattr); } $record[GO::t('company', 'addressbook') . $cattr] = $m->company->{$cattr}; } if (!$headerPrinted) { $csvWriter->putRecord($header); $headerPrinted = true; } $csvWriter->putRecord($record); } }
public function createTempFile() { if (!$this->hasTempFile()) { $tmpFile = new \GO\Base\Fs\File($this->getTempDir() . \GO\Base\Fs\File::stripInvalidChars($this->name)); // This fix for duplicate filenames in forwards caused screwed up attachment names! // A possible new fix should be made in ImapMessage->getAttachments() // // $file = new \GO\Base\Fs\File($this->name); // $tmpFile = new \GO\Base\Fs\File($this->getTempDir().uniqid(time()).'.'.$file->extension()); if (!$tmpFile->exists()) { $imap = $this->account->openImapConnection($this->mailbox); $imap->save_to_file($this->uid, $tmpFile->path(), $this->number, $this->encoding, true); } $this->setTempFile($tmpFile); } return $this->getTempFile(); }
protected function actionCreateFile($params) { $filename = \GO\Base\Fs\File::stripInvalidChars($params['filename']); if (empty($filename)) { throw new \Exception("Filename can not be empty"); } $template = \GO\Files\Model\Template::model()->findByPk($params['template_id']); $folder = \GO\Files\Model\Folder::model()->findByPk($params['folder_id']); $path = \GO::config()->file_storage_path . $folder->path . '/' . $filename; if (!empty($template->extension)) { $path .= '.' . $template->extension; } $fsFile = new \GO\Base\Fs\File($path); $fsFile->putContents($template->content); $fileModel = \GO\Files\Model\File::importFromFilesystem($fsFile); if (!$fileModel) { throw new Exception("Could not create file"); } return array('id' => $fileModel->id, 'success' => true); }
public function setParams($response, $view = false) { if (!$view) { $responses = array($response); } else { $responses = $response['results']; } $headers = true; foreach ($responses as $r) { $this->_view = $view; $this->_start_time = $r['start_time']; $this->_end_time = $r['end_time']; $this->_title = !empty($this->_view) ? \GO\Base\Fs\File::stripInvalidChars($this->_view->name) . ': ' . \GO\Base\Fs\File::stripInvalidChars($r['title']) : \GO\Base\Fs\File::stripInvalidChars($r['title']); $this->_days = ceil(($this->_end_time - $this->_start_time) / 86400); $this->_date_range_text = $this->_days > 1 ? date(\GO::user()->completeDateFormat, $this->_start_time) . ' - ' . date(\GO::user()->completeDateFormat, $this->_end_time) : date(\GO::user()->completeDateFormat, $this->_start_time); $this->_results = $r['results']; $this->_loadCurrentCalendar($r['calendar_id']); $this->_processEvents(!$view, $headers, $view ? $r['view_calendar_name'] : ''); $headers = false; } }
protected function beforeSubmit(&$response, &$model, &$params) { if (isset($params['name'])) { $params['name'] = \GO\Base\Fs\File::stripInvalidChars($params['name']); // Strip invalid chars $params['name'] .= '.' . $model->fsFile->extension(); } if (isset($params['lock'])) { //GOTA sends lock parameter It does not know the user ID. $model->locked_user_id = empty($params['lock']) ? 0 : \GO::user()->id; } $fh = \GO\Files\Model\FileHandler::model()->findByPk(array('extension' => strtolower($model->extension), 'user_id' => \GO::user()->id)); if (!$fh) { $fh = new \GO\Files\Model\FileHandler(); } $fh->extension = strtolower($model->extension); if (isset($params['handlerCls'])) { $fh->cls = $params['handlerCls']; } if (empty($params['handlerCls'])) { $fh->delete(); } else { $fh->save(); } return parent::beforeSubmit($response, $model, $params); }
protected function actionSource($params) { $account = Account::model()->findByPk($params['account_id']); $imap = $account->openImapConnection($params['mailbox']); //$filename = empty($params['download']) ? "message.txt" :"message.eml"; $message = \GO\Email\Model\ImapMessage::model()->findByUid($account, $params['mailbox'], $params['uid']); $filename = GO\Base\Fs\File::stripInvalidChars($message->subject . ' - ' . \GO\Base\Util\Date::get_timestamp($message->udate)); $filename .= empty($params['download']) ? ".txt" : ".eml"; \GO\Base\Util\Http::outputDownloadHeaders(new \GO\Base\Fs\File($filename), empty($params['download'])); /* * Somehow fetching a message with an empty message part which should fetch it * all doesn't work. (http://tools.ietf.org/html/rfc3501#section-6.4.5) * * That's why I first fetch the header and then the text. */ $header = $imap->get_message_part($params['uid'], 'HEADER', true) . "\r\n\r\n"; $size = $imap->get_message_part_start($params['uid'], 'TEXT', true); header('Content-Length: ' . (strlen($header) + $size)); echo $header; while ($line = $imap->get_message_part_line()) { echo $line; } }
public static function handleUpload() { $tmpFolder = new \GO\Base\Fs\Folder(\GO::config()->tmpdir . 'uploadqueue'); //$tmpFolder->delete(); $tmpFolder->create(); // $files = \GO\Base\Fs\File::moveUploadedFiles($_FILES['attachments'], $tmpFolder); // \GO::session()->values['files']['uploadqueue'] = array(); // foreach ($files as $file) { // \GO::session()->values['files']['uploadqueue'][] = $file->path(); // } if (!isset(\GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'] = array(); } $targetDir = $tmpFolder->path(); // Get parameters $chunk = isset($_POST["chunk"]) ? $_POST["chunk"] : 0; $chunks = isset($_POST["chunks"]) ? $_POST["chunks"] : 0; $fileName = isset($_POST["name"]) ? $_POST["name"] : ''; // Clean the fileName for security reasons $fileName = \GO\Base\Fs\File::stripInvalidChars($fileName); // Make sure the fileName is unique but only if chunking is disabled // if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) { // $ext = strrpos($fileName, '.'); // $fileName_a = substr($fileName, 0, $ext); // $fileName_b = substr($fileName, $ext); // // $count = 1; // while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) // $count++; // // $fileName = $fileName_a . '_' . $count . $fileName_b; // } // Look for the content type header if (isset($_SERVER["HTTP_CONTENT_TYPE"])) { $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; } if (isset($_SERVER["CONTENT_TYPE"])) { $contentType = $_SERVER["CONTENT_TYPE"]; } if (!in_array($targetDir . DIRECTORY_SEPARATOR . $fileName, \GO::session()->values['files']['uploadqueue'])) { \GO::session()->values['files']['uploadqueue'][] = $targetDir . DIRECTORY_SEPARATOR . $fileName; } $file = new \GO\Base\Fs\File($targetDir . DIRECTORY_SEPARATOR . $fileName); if ($file->exists() && $file->size() > \GO::config()->max_file_size) { throw new \Exception("File too large"); } // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, "multipart") !== false) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($_FILES['file']['tmp_name'], "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); @unlink($_FILES['file']['tmp_name']); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } } else { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } fclose($in); fclose($out); } else { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } } // Return JSON-RPC response die('{"jsonrpc" : "2.0", "result": null, "success":true, "id" : "id"}'); }
/** * * @return ImapMessageAttachment [] */ public function &getAttachments() { if (!$this->_imapAttachmentsLoaded) { $this->_imapAttachmentsLoaded = true; $imap = $this->getImapConnection(); $this->_loadBodyParts(); $parts = $imap->find_message_attachments($this->_getStruct(), $this->_bodyPartNumbers); $uniqueNames = array(); foreach ($parts as $part) { //ignore applefile's // Don't ignore it as it seems to be a valid attachment in some mails. // if($part['subtype']=='applefile') // continue; $a = new ImapMessageAttachment(); $a->setImapParams($this->account, $this->mailbox, $this->uid); if (empty($part['name']) || $part['name'] == 'false') { if (!empty($part['subject'])) { $a->name = \GO\Base\Fs\File::stripInvalidChars(\GO\Base\Mail\Utils::mimeHeaderDecode($part['subject'])) . '.eml'; } elseif ($part['type'] == 'message') { $a->name = isset($part['description']) ? \GO\Base\Fs\File::stripInvalidChars($part['description']) . '.eml' : 'message.eml'; } elseif ($part['subtype'] == 'calendar') { $a->name = \GO::t('event', 'email') . '.ics'; } else { if ($part['type'] == 'text') { $a->name = $part['subtype'] . '.txt'; } else { $a->name = $part['type'] . '-' . $part['subtype']; } } } else { $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['name']); $extension = \GO\Base\Fs\File::getExtension($a->name); if (!empty($part['filename']) && empty($extension)) { $a->name = \GO\Base\Mail\Utils::mimeHeaderDecode($part['filename']); } } $i = 1; $a->name = !empty($a->name) ? $a->name : \GO::t('noname', 'email'); $file = new \GO\Base\Fs\File($a->name); while (in_array($a->name, $uniqueNames)) { $a->name = $file->nameWithoutExtension() . ' (' . $i . ').' . $file->extension(); $i++; } $uniqueNames[] = $a->name; $a->disposition = isset($part['disposition']) ? strtolower($part['disposition']) : ''; $a->number = $part['number']; $a->content_id = ''; if (!empty($part["id"])) { //when an image has an id it belongs somewhere in the text we gathered above so replace the //source id with the correct link to display the image. $tmp_id = $part["id"]; if (strpos($tmp_id, '>')) { $tmp_id = substr($part["id"], 1, -1); } $id = $tmp_id; $a->content_id = $id; } $a->mime = $part['type'] . '/' . $part['subtype']; $a->index = count($this->attachments); $a->size = intval($part['size']); $a->encoding = $part['encoding']; $a->charset = !empty($part['charset']) ? $part['charset'] : $this->charset; $this->addAttachment($a); } } return $this->attachments; }
/** * Sends a meeting request to all participants. If the participant is not a Group-Office user * or the organizer has no permissions to schedule an event it will include an * icalendar attachment so the calendar software can schedule it. * * @return boolean * @throws Exception */ public function sendMeetingRequest($newParticipantsOnly = false, $update = false) { if (!$this->is_organizer) { throw new \Exception("Meeting request can only be send from the organizer's event"); } $stmt = $this->participants; //handle missing user if (!$this->user) { $this->user_id = 1; $this->save(true); } while ($participant = $stmt->fetch()) { if (!$newParticipantsOnly || isset(\GO::session()->values['new_participant_ids']) && in_array($participant->user_id, \GO::session()->values['new_participant_ids'])) { //don't invite organizer if ($participant->is_organizer) { continue; } // Set the language of the email to the language of the participant. $language = false; if (!empty($participant->user_id)) { $user = \GO\Base\Model\User::model()->findByPk($participant->user_id); if ($user) { \GO::language()->setLanguage($user->language); } } //if participant status is pending then send a new inviation subject. Otherwise send it as update if (!$update) { $subject = \GO::t('invitation', 'calendar') . ': ' . $this->name; $bodyLine = \GO::t('invited', 'calendar'); } else { $subject = \GO::t('invitation_update', 'calendar') . ': ' . $this->name; $bodyLine = \GO::t('eventUpdated', 'calendar'); } //create e-mail message $message = \GO\Base\Mail\Message::newInstance($subject)->setFrom($this->user->email, $this->user->name)->addTo($participant->email, $participant->name); //check if we have a Group-Office event. If so, we can handle accepting //and declining in Group-Office. Otherwise we'll use ICS calendar objects by mail $participantEvent = $participant->getParticipantEvent(); $body = '<p>' . $bodyLine . ': </p>' . $this->toHtml(); // if(!$participantEvent){ //build message for external program $acceptUrl = \GO::url("calendar/event/invitation", array("id" => $this->id, 'accept' => 1, 'email' => $participant->email, 'participantToken' => $participant->getSecurityToken()), false); $declineUrl = \GO::url("calendar/event/invitation", array("id" => $this->id, 'accept' => 0, 'email' => $participant->email, 'participantToken' => $participant->getSecurityToken()), false); // if($participantEvent){ //hide confusing buttons if user has a GO event. $body .= '<div class="go-hidden">'; // } $body .= '<p><br /><b>' . \GO::t('linkIfCalendarNotSupported', 'calendar') . '</b></p>' . '<p>' . \GO::t('acccept_question', 'calendar') . '</p>' . '<a href="' . $acceptUrl . '">' . \GO::t('accept', 'calendar') . '</a>' . ' | ' . '<a href="' . $declineUrl . '">' . \GO::t('decline', 'calendar') . '</a>'; // if($participantEvent){ $body .= '</div>'; // } $ics = $this->toICS("REQUEST"); $a = \Swift_Attachment::newInstance($ics, \GO\Base\Fs\File::stripInvalidChars($this->name) . '.ics', 'text/calendar; METHOD="REQUEST"'); $a->setEncoder(new Swift_Mime_ContentEncoder_PlainContentEncoder("8bit")); $a->setDisposition("inline"); $message->attach($a); //for outlook 2003 compatibility $a2 = \Swift_Attachment::newInstance($ics, 'invite.ics', 'application/ics'); $a2->setEncoder(new Swift_Mime_ContentEncoder_PlainContentEncoder("8bit")); $message->attach($a2); if ($participantEvent) { $url = \GO::createExternalUrl('calendar', 'openCalendar', array('unixtime' => $this->start_time)); $body .= '<br /><a href="' . $url . '">' . \GO::t('openCalendar', 'calendar') . '</a>'; } $message->setHtmlAlternateBody($body); // Set back the original language if ($language !== false) { \GO::language()->setLanguage($language); } \GO\Base\Mail\Mailer::newGoInstance()->send($message); } } unset(\GO::session()->values['new_participant_ids']); return true; }
/** * Create a PDF file from the response that is also send to the view. * * @param array $response */ private function _createPdf($response, $view = false) { $pdf = new \GO\Calendar\Views\Pdf\CalendarPdf('L', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false); $pdf->setParams($response, $view); $pdf->Output(\GO\Base\Fs\File::stripInvalidChars($response['title']) . '.pdf'); }
/** * Delete a value from the cache * * @param string $key */ public function delete($key) { $key = \GO\Base\Fs\File::stripInvalidChars($key, '-'); unset($this->_ttls[$key]); $this->_ttlsDirty = true; @unlink($this->_dir . $key); }