/** * Validation of given Mail Params * * @param \In2code\Powermail\Domain\Model\Mail $mail * @return bool */ public function isValid($mail) { foreach ($mail->getAnswers() as $answer) { if ($answer->getValueType() === 3) { if (!is_array($answer->getValue())) { continue; } foreach ($answer->getValue() as $value) { if (!BasicFileUtility::checkExtension($value, $this->settings['misc.']['file.']['extension'])) { $this->setErrorAndMessage($answer->getField(), 'upload_extension'); continue; } if (!BasicFileUtility::checkFilesize($value, $this->settings)) { $this->setErrorAndMessage($answer->getField(), 'upload_size'); continue; } } } } return $this->isValidState(); }
/** * Add attachments from upload fields * * @param MailMessage $message * @return MailMessage */ protected function addAttachmentsFromUploads(MailMessage $message) { if (empty($this->settings[$this->type]['attachment']) || empty($this->settings['misc']['file']['folder'])) { return $message; } /** @var Answer $answer */ foreach ($this->mail->getAnswers() as $answer) { $values = $answer->getValue(); if ($answer->getValueType() === 3 && is_array($values) && !empty($values)) { foreach ($values as $value) { $file = GeneralUtility::getFileAbsFileName(BasicFileUtility::addTrailingSlash($this->settings['misc']['file']['folder']) . $value); if (file_exists($file)) { $message->attach(\Swift_Attachment::fromPath($file)); } else { GeneralUtility::devLog('Error: File to attach does not exist', 'powermail', 2, $file); } } } } return $message; }
/** * addTrailingSlash Test * * @param string $string * @param string $expectedResult * @dataProvider addTrailingSlashReturnStringDataProvider * @return void * @test */ public function addTrailingSlashReturnString($string, $expectedResult) { $this->assertSame($expectedResult, BasicFileUtility::addTrailingSlash($string)); }
/** * Show Confirmation message after submit (if view is activated) * * @param Mail $mail * @validate $mail In2code\Powermail\Domain\Validator\UploadValidator * @validate $mail In2code\Powermail\Domain\Validator\InputValidator * @validate $mail In2code\Powermail\Domain\Validator\PasswordValidator * @validate $mail In2code\Powermail\Domain\Validator\CaptchaValidator * @validate $mail In2code\Powermail\Domain\Validator\SpamShieldValidator * @validate $mail In2code\Powermail\Domain\Validator\UniqueValidator * @validate $mail In2code\Powermail\Domain\Validator\ForeignValidator * @validate $mail In2code\Powermail\Domain\Validator\CustomValidator * @required $mail * @return void */ public function confirmationAction(Mail $mail) { BasicFileUtility::fileUpload($this->settings['misc']['file']['folder'], $mail, $this->settings['misc']['file']['extension']); $this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', [$mail, $this]); $this->prepareOutput($mail); }
/** * Reformat array for createAction * * @return void */ protected function reformatParamsForAction() { BasicFileUtility::rewriteFilesArrayToPreventDuplicatFilenames(); $arguments = $this->request->getArguments(); if (!isset($arguments['field'])) { return; } $newArguments = ['mail' => $arguments['mail']]; // allow subvalues in new property mapper $mailMvcArgument = $this->arguments->getArgument('mail'); $propertyMappingConfiguration = $mailMvcArgument->getPropertyMappingConfiguration(); $propertyMappingConfiguration->allowProperties('answers'); $propertyMappingConfiguration->allowCreationForSubProperty('answers'); $propertyMappingConfiguration->allowModificationForSubProperty('answers'); $propertyMappingConfiguration->allowProperties('form'); $propertyMappingConfiguration->allowCreationForSubProperty('form'); $propertyMappingConfiguration->allowModificationForSubProperty('form'); // allow creation of new objects (for validation) $propertyMappingConfiguration->setTypeConverterOptions('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\PersistentObjectConverter', [PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true, PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => true]); $i = 0; foreach ((array) $arguments['field'] as $marker => $value) { // ignore internal fields (honeypod) if (substr($marker, 0, 2) === '__') { continue; } $fieldUid = $this->fieldRepository->getFieldUidFromMarker($marker, $arguments['mail']['form']); // Skip fields without Uid (secondary password, upload) if ($fieldUid === 0) { continue; } // allow subvalues in new property mapper $propertyMappingConfiguration->forProperty('answers')->allowProperties($i); $propertyMappingConfiguration->forProperty('answers.' . $i)->allowAllProperties(); $propertyMappingConfiguration->allowCreationForSubProperty('answers.' . $i); $propertyMappingConfiguration->allowModificationForSubProperty('answers.' . $i); /** @var Field $field */ $field = $this->fieldRepository->findByUid($fieldUid); $valueType = $field->dataTypeFromFieldType($this->fieldRepository->getFieldTypeFromMarker($marker, $arguments['mail']['form'])); if ($valueType === 3 && is_array($value)) { $value = BasicFileUtility::getUniqueNamesForFileUploads($value, $this->settings, false); } if (is_array($value)) { if (empty($value)) { $value = ''; } else { $value = json_encode($value); } } $newArguments['mail']['answers'][$i] = ['field' => strval($fieldUid), 'value' => $value, 'valueType' => $valueType]; // edit form: add answer id if (!empty($arguments['field']['__identity'])) { $answer = $this->answerRepository->findByFieldAndMail($fieldUid, $arguments['field']['__identity']); if ($answer !== null) { $newArguments['mail']['answers'][$i]['__identity'] = $answer->getUid(); } } $i++; } // edit form: add mail id if (!empty($arguments['field']['__identity'])) { $newArguments['mail']['__identity'] = $arguments['field']['__identity']; } $this->request->setArguments($newArguments); $this->request->setArgument('field', null); }
/** * Remove unused uploaded Files with a scheduler task * * This task can clean up unused uploaded files * with powermail from your server * * @param string $uploadPath Define the upload Path * @return void */ public function cleanUnusedUploadsCommand($uploadPath = 'uploads/tx_powermail/') { $usedUploads = $this->getUsedUploads(); $allUploads = BasicFileUtility::getFilesFromRelativePath($uploadPath); $removeCounter = 0; foreach ($allUploads as $upload) { if (!in_array($upload, $usedUploads)) { $absoluteFilePath = GeneralUtility::getFileAbsFileName($uploadPath . $upload); if (filemtime($absoluteFilePath) < time() - $this->delta) { unlink($absoluteFilePath); $removeCounter++; } } } $this->outputLine('Overall Files: ' . count($allUploads)); $this->outputLine('Removed Files: ' . $removeCounter); }
/** * Create an export file * * @return bool if file operation could done successfully */ protected function createExportFile() { BasicFileUtility::createFolderIfNotExists($this->getStorageFolder(true)); return GeneralUtility::writeFile($this->getAbsolutePathAndFileName(), $this->getFileContent(), true); }
/** * Create an upload folder * * @return void */ public function fixUploadFolderAction() { BasicFileUtility::createFolderIfNotExists(GeneralUtility::getFileAbsFileName('uploads/tx_powermail/')); $this->redirect('checkBe'); }
/** * Render Link to Captcha Image * * @param Field $field * @return string|null * @throws \Exception */ public function render(Field $field) { if ($this->configurationExists()) { $this->setBackgroundImage($this->configuration['captcha.']['default.']['image'])->setFontPathAndFilename($this->configuration['captcha.']['default.']['font'])->setPathAndFilename($field); BasicFileUtility::createFolderIfNotExists($this->getImagePath(true)); $captchaValue = $this->getStringAndResultForCaptcha(); SessionUtility::setCaptchaSession($captchaValue['result'], $field->getUid()); return $this->createImage($captchaValue['string']); } return null; }
/** * Log Spam Notification * * @param Mail $mail * @return void */ protected function logSpamNotification(Mail $mail) { if (empty($this->settings['spamshield.']['logfileLocation'])) { return; } BasicFileUtility::createFolderIfNotExists(BasicFileUtility::getPathFromPathAndFilename($this->settings['spamshield.']['logfileLocation'])); $logMessage = $this->createSpamNotificationMessage($this->settings['spamshield.']['logTemplate'], $this->getVariablesForSpamNotification($mail)); BasicFileUtility::prependContentToFile($this->settings['spamshield.']['logfileLocation'], $logMessage); }