/**
  * @param Address $address
  * @return bool
  */
 protected function isValid($address)
 {
     $result = true;
     $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'H2dmailsub', 'Pidmailsubscribe');
     $validationSettings = $settings['validation'];
     foreach ($validationSettings as $field => $validations) {
         $value = $address->{'get' . ucfirst($field)}();
         foreach ($validations as $validation => $validationSetting) {
             switch ($validation) {
                 case 'required':
                     if ($validationSetting === '1' && empty($value)) {
                         $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validation.required', 'h2dmailsub'), time());
                         $this->result->forProperty($field)->addError($error);
                         $result = false;
                     }
                     break;
                 case 'email':
                     if (!empty($value) && $validationSetting === '1' && !\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($value)) {
                         $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Validation\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('validation.email', 'h2dmailsub'), time());
                         $this->result->forProperty($field)->addError($error);
                         $result = false;
                     }
                     break;
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * This is the main-function for sending Mails
  *
  * @param array $mailTo
  * @param array $mailFrom
  * @param string $subject
  * @param string $emailBody
  *
  * @return integer the number of recipients who were accepted for delivery
  */
 public function send($mailTo, $mailFrom, $subject, $emailBody)
 {
     if (!($mailTo && is_array($mailTo) && GeneralUtility::validEmail(key($mailTo)))) {
         $this->log->error('Given mailto email address is invalid.', $mailTo);
         return FALSE;
     }
     if (!($mailFrom && is_array($mailFrom) && GeneralUtility::validEmail(key($mailFrom)))) {
         $mailFrom = MailUtility::getSystemFrom();
     }
     /* @var $message \TYPO3\CMS\Core\Mail\MailMessage */
     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setTo($mailTo)->setFrom($mailFrom)->setSubject($subject)->setCharset(\TYPO3\T3extblog\Utility\GeneralUtility::getTsFe()->metaCharset);
     // send text or html emails
     if (strip_tags($emailBody) === $emailBody) {
         $message->setBody($emailBody, 'text/plain');
     } else {
         $message->setBody($emailBody, 'text/html');
     }
     if (!$this->settings['debug']['disableEmailTransmission']) {
         $message->send();
     }
     $logData = array('mailTo' => $mailTo, 'mailFrom' => $mailFrom, 'subject' => $subject, 'emailBody' => $emailBody, 'isSent' => $message->isSent());
     $this->log->dev('Email sent.', $logData);
     return $logData['isSent'];
 }
Example #3
0
 /**
  * return true if the element is valide
  *
  * @param	string $value value to test
  * @return	bool true if the element is valide
  */
 public function isValid($value)
 {
     if ($value == '') {
         return true;
     }
     return GeneralUtility::validEmail($value);
 }
 /**
  * Validates the additional fields' values
  *
  * @param array $submittedData An array containing the data submitted by the add/edit task form
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
  * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
  */
 public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
 {
     $validInput = true;
     if (empty($submittedData[$this->fieldNames['time']])) {
         $schedulerModule->addMessage($GLOBALS['LANG']->sL($this->languageFile . 'error.empty'), FlashMessage::ERROR);
         $validInput = false;
     }
     try {
         $date = new \DateTime($submittedData[$this->fieldNames['time']]);
     } catch (\Exception $e) {
         $schedulerModule->addMessage($GLOBALS['LANG']->sL($this->languageFile . 'error.wrongFormat'), FlashMessage::ERROR);
         $validInput = false;
     }
     if (!empty($submittedData[$this->fieldNames['email']])) {
         $emails = GeneralUtility::trimExplode(';', $submittedData[$this->fieldNames['email']], true);
         foreach ($emails as $key => $email) {
             if (!GeneralUtility::validEmail($email)) {
                 $schedulerModule->addMessage($GLOBALS['LANG']->sL($this->languageFile . 'error.wrongEmail'), FlashMessage::ERROR);
                 $validInput = false;
                 break;
             }
         }
     }
     $validInput = $this->validateTestRunner($submittedData);
     return $validInput;
 }
 /**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to result.
  *
  * @param mixed $value
  * @return void
  */
 public function isValid($value)
 {
     if (empty($value) || !is_string($value)) {
         return;
     }
     if (!GeneralUtility::validEmail($value)) {
         $this->addError($this->renderMessage($this->options['errorMessage'][0], $this->options['errorMessage'][1], 'error'), 1442000235);
     }
 }
Example #6
0
 /**
  * Spam-Validation of given Params
  * 		see powermail/doc/SpamDetection for formula
  *
  * @param \In2code\Powermail\Domain\Model\Mail $mail
  * @return bool
  */
 public function isValid($mail)
 {
     if (!$this->settings['spamshield.']['_enable']) {
         return $this->getIsValid();
     }
     $spamFactor = $this->settings['spamshield.']['factor'] / 100;
     // Different checks to increase spam indicator
     $this->honeypodCheck($this->settings['spamshield.']['indicator.']['honeypod']);
     $this->linkCheck($mail, $this->settings['spamshield.']['indicator.']['link'], $this->settings['spamshield.']['indicator.']['linkLimit']);
     $this->nameCheck($mail, $this->settings['spamshield.']['indicator.']['name']);
     $this->sessionCheck($mail, $this->settings['spamshield.']['indicator.']['session']);
     $this->uniqueCheck($mail, $this->settings['spamshield.']['indicator.']['unique']);
     $this->blacklistStringCheck($mail, $this->settings['spamshield.']['indicator.']['blacklistString']);
     $this->blacklistIpCheck($this->settings['spamshield.']['indicator.']['blacklistIp']);
     // spam formula with asymptote 1 (100%)
     if ($this->spamIndicator > 0) {
         $thisSpamFactor = -1 / $this->spamIndicator + 1;
     } else {
         $thisSpamFactor = 0;
     }
     // Save Spam Factor in session for db storage
     $GLOBALS['TSFE']->fe_user->setKey('ses', 'powermail_spamfactor', $this->formatSpamFactor($thisSpamFactor));
     $GLOBALS['TSFE']->storeSessionData();
     // Spam debugging
     if ($this->settings['debug.']['spamshield']) {
         GeneralUtility::devLog('Spamshield (Spamfactor ' . $this->formatSpamFactor($thisSpamFactor) . ')', 'powermail', 0, $this->getMessages());
     }
     // if spam
     if ($thisSpamFactor >= $spamFactor) {
         $this->addError('spam_details', $this->formatSpamFactor($thisSpamFactor));
         $this->setIsValid(FALSE);
         // Send notification email to admin
         if (GeneralUtility::validEmail($this->settings['spamshield.']['email'])) {
             $subject = 'Spam in powermail form recognized';
             $message = 'Possible spam in powermail form on page with PID ' . $GLOBALS['TSFE']->id;
             $message .= "\n\n";
             $message .= 'Spamfactor of this mail: ' . $this->formatSpamFactor($thisSpamFactor) . "\n";
             $message .= "\n\n";
             $message .= 'Failed Spamchecks:' . "\n";
             $message .= Div::viewPlainArray($this->getMessages());
             $message .= "\n\n";
             $message .= 'Given Form variables:' . "\n";
             foreach ($mail->getAnswers() as $answer) {
                 $message .= $answer->getField()->getTitle();
                 $message .= ': ';
                 $message .= $answer->getValue();
                 $message .= "\n";
             }
             $header = 'MIME-Version: 1.0' . "\r\n";
             $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
             $header .= 'From: powermail@' . GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . "\r\n";
             GeneralUtility::plainMailEncoded($this->settings['spamshield.']['email'], $subject, $message, $header);
         }
     }
     return $this->getIsValid();
 }
Example #7
0
 /**
  * Server valuation
  *
  * @param \string $value The field value to be evaluated.
  * @param \string $isIn The "isIn" value of the field configuration from TCA
  * @param \bool $set defining if the value is written to the database or not.
  * @return \string
  */
 public function evaluateFieldValue($value, $isIn, &$set)
 {
     if (GeneralUtility::validEmail($value)) {
         $set = 1;
     } else {
         $set = 0;
         $value = '*****@*****.**';
     }
     return $value;
 }
Example #8
0
 /**
  * Returns TRUE if submitted value validates according to rule
  *
  * @return bool
  * @see \TYPO3\CMS\Form\Validation\ValidatorInterface::isValid()
  */
 public function isValid()
 {
     if ($this->requestHandler->has($this->fieldName)) {
         $value = $this->requestHandler->getByMethod($this->fieldName);
         if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($value)) {
             return FALSE;
         }
     }
     return TRUE;
 }
 public function check()
 {
     $checkFailed = '';
     if (isset($this->gp[$this->formFieldName]) && strlen(trim($this->gp[$this->formFieldName])) > 0) {
         $valid = \TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($this->gp[$this->formFieldName]);
         if (!$valid) {
             $checkFailed = $this->getCheckFailed();
         }
     }
     return $checkFailed;
 }
Example #10
0
 /**
  * Part of the typolink construction functionality, called by typoLink()
  * Used to resolve "legacy"-based typolinks.
  *
  * Tries to get the type of the link from the link parameter
  * could be
  *  - "mailto" an email address
  *  - "url" external URL
  *  - "file" a local file (checked AFTER getPublicUrl() is called)
  *  - "page" a page (integer or alias)
  *
  * Does NOT check if the page exists or the file exists.
  *
  * @param string $linkParameter could be "fileadmin/myfile.jpg", "*****@*****.**", "13" or "http://www.typo3.org"
  *
  * @return array
  */
 public function resolve(string $linkParameter) : array
 {
     $result = [];
     // Parse URL scheme
     $scheme = parse_url($linkParameter, PHP_URL_SCHEME);
     // Resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
     if (stripos($linkParameter, 'file:') === 0) {
         $result = $this->getFileOrFolderObjectFromMixedIdentifier(substr($linkParameter, 5));
     } elseif (GeneralUtility::validEmail($linkParameter)) {
         $result['type'] = LinkService::TYPE_EMAIL;
         $result['email'] = $linkParameter;
     } elseif (strpos($linkParameter, ':') !== false) {
         // Check for link-handler keyword
         list($linkHandlerKeyword, $linkHandlerValue) = explode(':', $linkParameter, 2);
         $result['type'] = strtolower(trim($linkHandlerKeyword));
         $result['url'] = $linkHandlerValue;
     } else {
         // special handling without a scheme
         $isLocalFile = 0;
         $fileChar = (int) strpos($linkParameter, '/');
         $urlChar = (int) strpos($linkParameter, '.');
         $containsSlash = false;
         if (!MathUtility::canBeInterpretedAsInteger($linkParameter)) {
             // Detects if a file is found in site-root and if so it will be treated like a normal file.
             list($rootFileDat) = explode('?', rawurldecode($linkParameter));
             $containsSlash = strpos($rootFileDat, '/') !== false;
             $pathInfo = pathinfo($rootFileDat);
             $fileExtension = strtolower($pathInfo['extension'] ?? '');
             if (!$containsSlash && trim($rootFileDat) && (@is_file(PATH_site . $rootFileDat) || $fileExtension === 'php' || $fileExtension === 'html' || $fileExtension === 'htm')) {
                 $isLocalFile = 1;
             } elseif ($containsSlash) {
                 // Adding this so realurl directories are linked right (non-existing).
                 $isLocalFile = 2;
             }
         }
         // url (external): If doubleSlash or if a '.' comes before a '/'.
         if ($isLocalFile !== 1 && $urlChar && (!$containsSlash || $urlChar < $fileChar)) {
             $result['type'] = LinkService::TYPE_URL;
             if (!$scheme) {
                 $result['url'] = 'http://' . $linkParameter;
             } else {
                 $result['url'] = $linkParameter;
             }
             // file (internal) or folder
         } elseif ($containsSlash || $isLocalFile) {
             $result = $this->getFileOrFolderObjectFromMixedIdentifier($linkParameter);
         } else {
             // Integer or alias (alias is without slashes or periods or commas, that is
             // 'nospace,alphanum_x,lower,unique' according to definition in $GLOBALS['TCA']!)
             $result = $this->resolvePageRelatedParameters($linkParameter);
         }
     }
     return $result;
 }
Example #11
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  *
  * @return bool true/false if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name)
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->mail->setFrom($sender, $name);
         $this->mail->setSubject($subject);
         $this->mail->setBody($body, 'text/html');
         $this->mail->setTo($recipient);
         $this->mail->send();
         return $this->mail->isSent();
     } else {
         return false;
     }
 }
Example #12
0
 /**
  * Read Emails from String
  *
  * @param int $uid fe_groups Uid
  * @return array Array with emails
  */
 protected static function getEmailsFromFeGroup($uid)
 {
     /** @var UserRepository $userRepository */
     $userRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(UserRepository::class);
     $users = $userRepository->findByUsergroup($uid);
     $array = [];
     foreach ($users as $user) {
         if (GeneralUtility::validEmail($user->getEmail())) {
             $array[] = $user->getEmail();
         }
     }
     return $array;
 }
 /**
  * Read Emails from String
  *
  * @param int $uid fe_groups Uid
  * @return array Array with emails
  */
 protected static function getEmailsFromFeGroup($uid)
 {
     /** @var UserRepository $userRepository */
     $userRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('In2code\\Powermail\\Domain\\Repository\\UserRepository');
     $users = $userRepository->findByUsergroup($uid);
     $array = array();
     foreach ($users as $user) {
         if (GeneralUtility::validEmail($user->getEmail())) {
             $array[] = $user->getEmail();
         }
     }
     return $array;
 }
Example #14
0
 function process(&$event, $email, $userId)
 {
     if ($email != '' && GeneralUtility::validEmail($email)) {
         $template = $this->conf['view.']['event.']['remind.'][$userId . '.']['template'];
         if (!$template) {
             $template = $this->conf['view.']['event.']['remind.']['all.']['template'];
         }
         $titleText = $this->conf['view.']['event.']['remind.'][$userId . '.']['emailTitle'];
         if (!$titleText) {
             $titleText = $this->conf['view.']['event.']['remind.']['all.']['emailTitle'];
         }
         $this->sendNotification($event, $email, $template, $titleText, '');
     }
 }
Example #15
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  * @param array $attachments Array of files (e.g. ['/absolute/path/doc.pdf'])
  *
  * @return bool TRUE/FALSE if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name = null, $attachments = [])
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->initialize();
         $this->mailer->setFrom($sender, $name);
         $this->mailer->setSubject($subject);
         $this->mailer->setBody($body, 'text/html');
         $this->mailer->setTo($recipient);
         $this->addAttachments($attachments);
         $this->mailer->send();
         return $this->mailer->isSent();
     } else {
         return false;
     }
 }
 /**
  * Validates the additional fields' values
  *
  * @param array $submittedData An array containing the data submitted by the add/edit task form
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
  * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
  */
 public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
 {
     $validInput = true;
     $notificationEmails = GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], true);
     foreach ($notificationEmails as $notificationEmail) {
         if (!GeneralUtility::validEmail($notificationEmail)) {
             $validInput = false;
             break;
         }
     }
     if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
         $schedulerModule->addMessage($this->getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTaskField_notificationEmails_invalid'), FlashMessage::ERROR);
         $validInput = false;
     }
     return $validInput;
 }
 /**
  * Validates the additional fields' values
  *
  * @param array $submittedData An array containing the data submitted by the add/edit task form
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
  * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
  */
 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule)
 {
     $validInput = TRUE;
     $notificationEmails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $submittedData[$this->fieldPrefix . 'NotificationEmail'], TRUE);
     foreach ($notificationEmails as $notificationEmail) {
         if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($notificationEmail)) {
             $validInput = FALSE;
             break;
         }
     }
     if (empty($submittedData[$this->fieldPrefix . 'NotificationEmail']) || !$validInput) {
         $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xlf:status_updateTaskField_notificationEmails_invalid'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $validInput = FALSE;
     }
     return $validInput;
 }
 /**
  * @param $notificationEmail
  * @param $disabledUser
  * @return bool
  * @throws Exception
  */
 public static function sendEmail($notificationEmail, $disabledUser)
 {
     $success = false;
     if (!GeneralUtility::validEmail($notificationEmail)) {
         return $success;
     }
     $mailBody = self::getMailBody($disabledUser);
     // Prepare mailer and send the mail
     try {
         $mailer = GeneralUtility::makeInstance(MailMessage::class);
         $mailer->setFrom($notificationEmail);
         $mailer->setSubject('SCHEDULER-Task DisableBeuser:'******'TYPO3_CONF_VARS']['SYS']['sitename']));
         $mailer->setBody($mailBody, 'text/html');
         $mailer->setTo($notificationEmail);
         $mailsSend = $mailer->send();
         $success = $mailsSend > 0;
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return $success;
 }
Example #19
0
 /**
  * check dynamic form fields
  *
  * @param array $fields fields
  * @param array $item item
  * @param array &$messages messages
  * @param array &$errors errors
  * @return void
  */
 public function checkFields($fields = [], $item = [], &$messages, &$errors)
 {
     // check fields
     foreach ($fields as $field) {
         $msgtitle = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'], $this->extensionName);
         // set fallback title
         if (!$msgtitle) {
             $msgtitle = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'], $field['extkey']);
         }
         // check required fields only
         if (!in_array($field['config']['type'], ["file"]) && ($field['config']['required'] || isset($field['config']['maxlength']) || isset($field['config']['minlength']) || isset($field['config']['limit-low']) || isset($field['config']['limit-high']) || !$field['config']['required'] && in_array($field['config']['validator'], ["email"]))) {
             // check if field has a value
             if ($field['config']['required'] && (trim($item[$field['key']]) == "" || $field['key'] == "gender" && trim($item[$field['key']]) == 0)) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.empty', $this->extensionName);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.empty', $field['extkey']);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.empty', $this->extensionName);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
                 // check if field value smaller than maxlength
             } elseif (trim($item[$field['key']]) != "" && isset($field['config']['maxlength']) && strlen(trim($item[$field['key']])) > $field['config']['maxlength']) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.too_long', $this->extensionName, [$field['config']['maxlength']]);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.too_long', $field['extkey'], [$field['config']['maxlength']]);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.too_long', $this->extensionName, [$field['config']['maxlength']]);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
                 // check if field value larger than minlength
             } elseif (trim($item[$field['key']]) != "" && isset($field['config']['minlength']) && strlen(trim($item[$field['key']])) < $field['config']['minlength']) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.too_short', $this->extensionName, [$field['config']['minlength']]);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.too_short', $field['extkey'], [$field['config']['minlength']]);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.too_short', $this->extensionName, [$field['config']['minlength']]);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
                 // check if field value greater than lowlimit
             } elseif (trim($item[$field['key']]) != "" && isset($field['config']['limit-low']) && trim($item[$field['key']]) < $field['config']['limit-low']) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.too_small', $this->extensionName, [$field['config']['limit-low']]);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.too_small', $field['extkey'], [$field['config']['limit-low']]);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.too_small', $this->extensionName, [$field['config']['limit-low']]);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
                 // check if field value smaller than highlimit
             } elseif (trim($item[$field['key']]) != "" && isset($field['config']['limit-high']) && trim($item[$field['key']]) > $field['config']['limit-high']) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.too_large', $this->extensionName, [$field['config']['limit-high']]);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.too_large', $field['extkey'], [$field['config']['limit-high']]);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.too_large', $this->extensionName, [$field['config']['limit-high']]);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
                 // check if email is valid
             } elseif (trim($item[$field['key']]) != "" && $field['config']['validator'] == "email" && !GeneralUtility::validEmail(trim($item[$field['key']]))) {
                 // prepare message
                 $message = LocalizationUtility::translate(self::LLPATH . 'form.' . $field['key'] . '.error.invalid', $this->extensionName);
                 // set fallback message
                 if (!$message) {
                     $message = LocalizationUtility::translate(str_replace("moox_comment", $field['extkey'], self::LLPATH) . 'form.' . $field['key'] . '.error.invalid', $field['extkey']);
                 }
                 if (!$message) {
                     $message = LocalizationUtility::translate(self::LLPATH . 'form.error.invalid', $this->extensionName);
                 }
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => $msgtitle, "text" => $message, "type" => FlashMessage::ERROR];
                 // set error
                 $errors[$field['key']] = true;
             }
         }
     }
 }
 /**
  * Start function
  * This class is able to generate a mail in formmail-style from the data in $V
  * Fields:
  *
  * [recipient]:			email-adress of the one to receive the mail. If array, then all values are expected to be recipients
  * [attachment]:		....
  *
  * [subject]:			The subject of the mail
  * [from_email]:		Sender email. If not set, [email] is used
  * [from_name]:			Sender name. If not set, [name] is used
  * [replyto_email]:		Reply-to email. If not set [from_email] is used
  * [replyto_name]:		Reply-to name. If not set [from_name] is used
  * [organisation]:		Organization (header)
  * [priority]:			Priority, 1-5, default 3
  * [html_enabled]:		If mail is sent as html
  * [use_base64]:		If set, base64 encoding will be used instead of quoted-printable
  *
  * @param array $valueList Contains values for the field names listed above (with slashes removed if from POST input)
  * @param boolean $base64 Whether to base64 encode the mail content
  * @return void
  * @todo Define visibility
  */
 public function start($valueList, $base64 = FALSE)
 {
     $this->mailMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     if ($GLOBALS['TSFE']->config['config']['formMailCharset']) {
         // Respect formMailCharset if it was set
         $this->characterSet = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
     } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) {
         // Use metaCharset for mail if different from renderCharset
         $this->characterSet = $GLOBALS['TSFE']->metaCharset;
     } else {
         // Otherwise use renderCharset as default
         $this->characterSet = $GLOBALS['TSFE']->renderCharset;
     }
     if ($base64 || $valueList['use_base64']) {
         $this->encoding = 'base64';
     }
     if (isset($valueList['recipient'])) {
         // Convert form data from renderCharset to mail charset
         $this->subject = $valueList['subject'] ? $valueList['subject'] : 'Formmail on ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
         $this->subject = $this->sanitizeHeaderString($this->subject);
         $this->fromName = $valueList['from_name'] ? $valueList['from_name'] : ($valueList['name'] ? $valueList['name'] : '');
         $this->fromName = $this->sanitizeHeaderString($this->fromName);
         $this->replyToName = $valueList['replyto_name'] ? $valueList['replyto_name'] : $this->fromName;
         $this->replyToName = $this->sanitizeHeaderString($this->replyToName);
         $this->organisation = $valueList['organisation'] ? $valueList['organisation'] : '';
         $this->organisation = $this->sanitizeHeaderString($this->organisation);
         $this->fromAddress = $valueList['from_email'] ? $valueList['from_email'] : ($valueList['email'] ? $valueList['email'] : '');
         if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($this->fromAddress)) {
             $this->fromAddress = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFromAddress();
             $this->fromName = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFromName();
         }
         $this->replyToAddress = $valueList['replyto_email'] ? $valueList['replyto_email'] : $this->fromAddress;
         $this->priority = $valueList['priority'] ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($valueList['priority'], 1, 5) : 3;
         // Auto responder
         $this->autoRespondMessage = trim($valueList['auto_respond_msg']) && $this->fromAddress ? trim($valueList['auto_respond_msg']) : '';
         if ($this->autoRespondMessage !== '') {
             // Check if the value of the auto responder message has been modified with evil intentions
             $autoRespondChecksum = $valueList['auto_respond_checksum'];
             $correctHmacChecksum = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($this->autoRespondMessage);
             if ($autoRespondChecksum !== $correctHmacChecksum) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible misuse of t3lib_formmail auto respond method. Subject: ' . $valueList['subject'], 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
                 return;
             } else {
                 $this->autoRespondMessage = $this->sanitizeHeaderString($this->autoRespondMessage);
             }
         }
         $plainTextContent = '';
         $htmlContent = '<table border="0" cellpadding="2" cellspacing="2">';
         // Runs through $V and generates the mail
         if (is_array($valueList)) {
             foreach ($valueList as $key => $val) {
                 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->reserved_names, $key)) {
                     $space = strlen($val) > 60 ? LF : '';
                     $val = is_array($val) ? implode($val, LF) : $val;
                     // Convert form data from renderCharset to mail charset (HTML may use entities)
                     $plainTextValue = $val;
                     $HtmlValue = htmlspecialchars($val);
                     $plainTextContent .= strtoupper($key) . ':  ' . $space . $plainTextValue . LF . $space;
                     $htmlContent .= '<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><strong>' . strtoupper($key) . '</strong></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">' . nl2br($HtmlValue) . '&nbsp;</font></td></tr>';
                 }
             }
         }
         $htmlContent .= '</table>';
         $this->plainContent = $plainTextContent;
         if ($valueList['html_enabled']) {
             $this->mailMessage->setBody($htmlContent, 'text/html', $this->characterSet);
             $this->mailMessage->addPart($plainTextContent, 'text/plain', $this->characterSet);
         } else {
             $this->mailMessage->setBody($plainTextContent, 'text/plain', $this->characterSet);
         }
         for ($a = 0; $a < 10; $a++) {
             $variableName = 'attachment' . ($a ? $a : '');
             if (!isset($_FILES[$variableName])) {
                 continue;
             }
             if (!is_uploaded_file($_FILES[$variableName]['tmp_name'])) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible abuse of t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name'] . '" ("' . $_FILES[$variableName]['name'] . '") was not an uploaded file.', 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
             if ($_FILES[$variableName]['tmp_name']['error'] !== UPLOAD_ERR_OK) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Error in uploaded file in t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name'] . '" ("' . $_FILES[$variableName]['name'] . '") Error code: ' . $_FILES[$variableName]['tmp_name']['error'], 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
             $theFile = \TYPO3\CMS\Core\Utility\GeneralUtility::upload_to_tempfile($_FILES[$variableName]['tmp_name']);
             $theName = $_FILES[$variableName]['name'];
             if ($theFile && file_exists($theFile)) {
                 if (filesize($theFile) < $GLOBALS['TYPO3_CONF_VARS']['FE']['formmailMaxAttachmentSize']) {
                     $this->mailMessage->attach(Swift_Attachment::fromPath($theFile)->setFilename($theName));
                 }
             }
             $this->temporaryFiles[] = $theFile;
         }
         $from = $this->fromName ? array($this->fromAddress => $this->fromName) : array($this->fromAddress);
         $this->recipient = $this->parseAddresses($valueList['recipient']);
         $this->mailMessage->setSubject($this->subject)->setFrom($from)->setTo($this->recipient)->setPriority($this->priority);
         $replyTo = $this->replyToName ? array($this->replyToAddress => $this->replyToName) : array($this->replyToAddress);
         $this->mailMessage->setReplyTo($replyTo);
         $this->mailMessage->getHeaders()->addTextHeader('Organization', $this->organisation);
         if ($valueList['recipient_copy']) {
             $this->mailMessage->setCc($this->parseAddresses($valueList['recipient_copy']));
         }
         $this->mailMessage->setCharset($this->characterSet);
         // Ignore target encoding. This is handled automatically by Swift Mailer and overriding the defaults
         // is not worth the trouble
         // Log dirty header lines
         if ($this->dirtyHeaders) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('t3lib_formmail: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::arrayToLogString($this->dirtyHeaders, '', 200), 'Core', 3);
             }
         }
     }
 }
 /**
  * @test
  * @dataProvider validEmailInvalidDataProvider
  */
 public function validEmailReturnsFalseForInvalidMailAddress($address)
 {
     $this->assertFalse(Utility\GeneralUtility::validEmail($address));
 }
 /**
  * Creates the URL, target and onclick values for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes
  * This function doesn't care about the url, because if we let the url be redirected, it will be logged in the stat!!!
  *
  * @param integer $key Pointer to a key in the $this->menuArr array where the value for that key represents the menu item we are linking to (page record)
  * @param string $altTarget Alternative target
  * @param integer $typeOverride Alternative type
  * @return array Returns an array with A-tag attributes as key/value pairs (HREF, TARGET and onClick)
  * @access private
  * @todo Define visibility
  */
 public function link($key, $altTarget = '', $typeOverride = '')
 {
     // Mount points:
     $MP_var = $this->getMPvar($key);
     $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : '';
     // Setting override ID
     if ($this->mconf['overrideId'] || $this->menuArr[$key]['overrideId']) {
         $overrideArray = array();
         // If a user script returned the value overrideId in the menu array we use that as page id
         $overrideArray['uid'] = $this->mconf['overrideId'] ?: $this->menuArr[$key]['overrideId'];
         $overrideArray['alias'] = '';
         // Clear MP parameters since ID was changed.
         $MP_params = '';
     } else {
         $overrideArray = '';
     }
     // Setting main target:
     if ($altTarget) {
         $mainTarget = $altTarget;
     } elseif ($this->mconf['target.']) {
         $mainTarget = $this->parent_cObj->stdWrap($this->mconf['target'], $this->mconf['target.']);
     } else {
         $mainTarget = $this->mconf['target'];
     }
     // Creating link:
     if ($this->mconf['collapse'] && $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key))) {
         $thePage = $this->sys_page->getPage($this->menuArr[$key]['pid']);
         $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', $overrideArray, $this->mconf['addParams'] . $MP_params . $this->menuArr[$key]['_ADD_GETVARS'], $typeOverride);
     } else {
         $LD = $this->menuTypoLink($this->menuArr[$key], $mainTarget, '', '', $overrideArray, $this->mconf['addParams'] . $MP_params . $this->I['val']['additionalParams'] . $this->menuArr[$key]['_ADD_GETVARS'], $typeOverride);
     }
     // Override URL if using "External URL" as doktype with a valid e-mail address:
     if ($this->menuArr[$key]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK && $this->menuArr[$key]['urltype'] == 3 && GeneralUtility::validEmail($this->menuArr[$key]['url'])) {
         // Create mailto-link using \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::typolink (concerning spamProtectEmailAddresses):
         $LD['totalURL'] = $this->parent_cObj->typoLink_URL(array('parameter' => $this->menuArr[$key]['url']));
         $LD['target'] = '';
     }
     // Override url if current page is a shortcut
     $shortcut = NULL;
     if ($this->menuArr[$key]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT && $this->menuArr[$key]['shortcut_mode'] != \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
         $menuItem = $this->determineOriginalShortcutPage($this->menuArr[$key]);
         try {
             $shortcut = $GLOBALS['TSFE']->getPageShortcut($menuItem['shortcut'], $menuItem['shortcut_mode'], $menuItem['uid'], 20, array(), TRUE);
         } catch (\Exception $ex) {
         }
         if (!is_array($shortcut)) {
             return array();
         }
         // Only setting url, not target
         $LD['totalURL'] = $this->parent_cObj->typoLink_URL(array('parameter' => $shortcut['uid'], 'additionalParams' => $this->mconf['addParams'] . $MP_params . $this->I['val']['additionalParams'] . $menuItem['_ADD_GETVARS'], 'linkAccessRestrictedPages' => $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE'));
     }
     if ($shortcut) {
         $pageData = $shortcut;
         $pageData['_SHORTCUT_PAGE_UID'] = $this->menuArr[$key]['uid'];
     } else {
         $pageData = $this->menuArr[$key];
     }
     // Manipulation in case of access restricted pages:
     $this->changeLinksForAccessRestrictedPages($LD, $pageData, $mainTarget, $typeOverride);
     // Overriding URL / Target if set to do so:
     if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
         $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
         if ($this->menuArr[$key]['_OVERRIDE_TARGET']) {
             $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
         }
     }
     // OnClick open in windows.
     $onClick = '';
     if ($this->mconf['JSWindow']) {
         $conf = $this->mconf['JSWindow.'];
         $url = $LD['totalURL'];
         $LD['totalURL'] = '#';
         $onClick = 'openPic(\'' . $GLOBALS['TSFE']->baseUrlWrap($url) . '\',\'' . ($conf['newWindow'] ? md5($url) : 'theNewPage') . '\',\'' . $conf['params'] . '\'); return false;';
         $GLOBALS['TSFE']->setJS('openPic');
     }
     // look for type and popup
     // following settings are valid in field target:
     // 230								will add type=230 to the link
     // 230 500x600						will add type=230 to the link and open in popup window with 500x600 pixels
     // 230 _blank						will add type=230 to the link and open with target "_blank"
     // 230x450:resizable=0,location=1	will open in popup window with 500x600 pixels with settings "resizable=0,location=1"
     $matches = array();
     $targetIsType = $LD['target'] && MathUtility::canBeInterpretedAsInteger($LD['target']) ? (int) $LD['target'] : FALSE;
     if (preg_match('/([0-9]+[\\s])?(([0-9]+)x([0-9]+))?(:.+)?/s', $LD['target'], $matches) || $targetIsType) {
         // has type?
         if ((int) $matches[1] || $targetIsType) {
             $LD['totalURL'] = $this->parent_cObj->URLqMark($LD['totalURL'], '&type=' . ($targetIsType ?: (int) $matches[1]));
             $LD['target'] = $targetIsType ? '' : trim(substr($LD['target'], strlen($matches[1]) + 1));
         }
         // Open in popup window?
         if ($matches[3] && $matches[4]) {
             $JSparamWH = 'width=' . $matches[3] . ',height=' . $matches[4] . ($matches[5] ? ',' . substr($matches[5], 1) : '');
             $onClick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue($GLOBALS['TSFE']->baseUrlWrap($LD['totalURL'])) . ',\'FEopenLink\',\'' . $JSparamWH . '\');vHWin.focus();return false;';
             $LD['target'] = '';
         }
     }
     // out:
     $list = array();
     // Added this check: What it does is to enter the baseUrl (if set, which it should for "realurl" based sites)
     // as URL if the calculated value is empty. The problem is that no link is generated with a blank URL
     // and blank URLs might appear when the realurl encoding is used and a link to the frontpage is generated.
     $list['HREF'] = strlen($LD['totalURL']) ? $LD['totalURL'] : $GLOBALS['TSFE']->baseUrl;
     $list['TARGET'] = $LD['target'];
     $list['onClick'] = $onClick;
     return $list;
 }
 /**
  * This method checks any additional data that is relevant to the specific task
  * If the task class is not relevant, the method is expected to return TRUE
  *
  * @param array $submittedData Reference to the array containing the data submitted by the user
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
  * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
  */
 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
 {
     $result = TRUE;
     $submittedData['pid'] = intval($submittedData['pid']);
     if ($submittedData['oauthAccessToken'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.oauth_access_token_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['oauthAccessTokenSecret'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.oauth_access_token_secret_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['consumerKey'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.consumer_key_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['consumerKeySecret'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.consumer_key_secret_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['screenName'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.screen_name_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['email'] != "" && !\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($submittedData['email'])) {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.email_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($result) {
         $config = array('consumer_key' => $submittedData['consumerKey'], 'consumer_secret' => $submittedData['consumerKeySecret'], 'oauth_access_token' => $submittedData['oauthAccessToken'], 'oauth_access_token_secret' => $submittedData['oauthAccessTokenSecret'], 'screenName' => $submittedData['screenName'], 'allowSignedRequest' => false);
         $twitter = new \TYPO3\MooxSocial\Twitter\TwitterAPIExchange($config);
         $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
         $requestMethod = "GET";
         $getfield = '?screen_name=' . $submittedData['screenName'];
         try {
             $rawFeed = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), $assoc = TRUE);
         } catch (\Exception $e) {
             $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_twittergettask.api_error') . " [" . $e->getMessage() . "]", \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
             $result = FALSE;
         }
     }
     return $result;
 }
 /**
  * This method checks any additional data that is relevant to the specific task
  * If the task class is not relevant, the method is expected to return TRUE
  *
  * @param array $submittedData Reference to the array containing the data submitted by the user
  * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
  * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
  */
 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
 {
     $result = TRUE;
     $submittedData['pid'] = intval($submittedData['pid']);
     if ($submittedData['pid'] < 0) {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.pid_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['clearCachePages'] != "") {
         $clearCachePages = explode(",", $submittedData['clearCachePages']);
         foreach ($clearCachePages as $clearCachePage) {
             if (!is_numeric($clearCachePage) || $clearCachePage == "") {
                 $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.clear_cache_pages_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
                 $result = FALSE;
             }
         }
     }
     if ($submittedData['appId'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.app_id_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['secret'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.secret_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['pageId'] == "") {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.page_id_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($submittedData['email'] != "" && !\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($submittedData['email'])) {
         $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.email_error'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
         $result = FALSE;
     }
     if ($result) {
         $config = array('appId' => $submittedData['appId'], 'secret' => $submittedData['secret'], 'pageid' => $submittedData['pageId'], 'allowSignedRequest' => false);
         $facebook = new \TYPO3\MooxSocial\Facebook\Facebook($config);
         $url = '/' . $submittedData['pageId'] . '/feed';
         try {
             $rawFeed = $facebook->api($url);
         } catch (\TYPO3\MooxSocial\Facebook\FacebookApiException $e) {
             $parentObject->addMessage($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_facebookgettask.api_error') . " [" . $e->getMessage() . "]", \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
             $result = FALSE;
         }
     }
     return $result;
 }
 /**
  * Build and send warning email when new broken links were found
  *
  * @param string $pageSections Content of page section
  * @param array $modTsConfig TSconfig array
  * @return bool TRUE if mail was sent, FALSE if or not
  * @throws \Exception if required modTsConfig settings are missing
  */
 protected function reportEmail($pageSections, array $modTsConfig)
 {
     $content = $this->templateService->substituteSubpart($this->templateMail, '###PAGE_SECTION###', $pageSections);
     /** @var array $markerArray */
     $markerArray = array();
     /** @var array $validEmailList */
     $validEmailList = array();
     /** @var bool $sendEmail */
     $sendEmail = true;
     $markerArray['totalBrokenLink'] = $this->totalBrokenLink;
     $markerArray['totalBrokenLink_old'] = $this->oldTotalBrokenLink;
     // Hook
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['reportEmailMarkers'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['reportEmailMarkers'] as $userFunc) {
             $params = array('pObj' => &$this, 'markerArray' => $markerArray);
             $newMarkers = GeneralUtility::callUserFunction($userFunc, $params, $this);
             if (is_array($newMarkers)) {
                 $markerArray = $newMarkers + $markerArray;
             }
             unset($params);
         }
     }
     $content = $this->templateService->substituteMarkerArray($content, $markerArray, '###|###', true, true);
     /** @var $mail MailMessage */
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     if (empty($modTsConfig['mail.']['fromemail'])) {
         $modTsConfig['mail.']['fromemail'] = MailUtility::getSystemFromAddress();
     }
     if (empty($modTsConfig['mail.']['fromname'])) {
         $modTsConfig['mail.']['fromname'] = MailUtility::getSystemFromName();
     }
     if (GeneralUtility::validEmail($modTsConfig['mail.']['fromemail'])) {
         $mail->setFrom(array($modTsConfig['mail.']['fromemail'] => $modTsConfig['mail.']['fromname']));
     } else {
         throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidFromEmail'), '1295476760');
     }
     if (GeneralUtility::validEmail($modTsConfig['mail.']['replytoemail'])) {
         $mail->setReplyTo(array($modTsConfig['mail.']['replytoemail'] => $modTsConfig['mail.']['replytoname']));
     }
     if (!empty($modTsConfig['mail.']['subject'])) {
         $mail->setSubject($modTsConfig['mail.']['subject']);
     } else {
         throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.noSubject'), '1295476808');
     }
     if (!empty($this->email)) {
         // Check if old input field value is still there and save the value a
         if (strpos($this->email, ',') !== false) {
             $emailList = GeneralUtility::trimExplode(',', $this->email, true);
             $this->email = implode(LF, $emailList);
             $this->save();
         } else {
             $emailList = GeneralUtility::trimExplode(LF, $this->email, true);
         }
         foreach ($emailList as $emailAdd) {
             if (!GeneralUtility::validEmail($emailAdd)) {
                 throw new \Exception($this->getLanguageService()->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidToEmail'), '1295476821');
             } else {
                 $validEmailList[] = $emailAdd;
             }
         }
     }
     if (is_array($validEmailList) && !empty($validEmailList)) {
         $mail->setTo($validEmailList);
     } else {
         $sendEmail = false;
     }
     if ($sendEmail) {
         $mail->setBody($content, 'text/html');
         $mail->send();
     }
     return $sendEmail;
 }
Example #26
0
 /**
  * Gets all assigned recipients of a particular stage.
  *
  * @param StageRecord|int $stageRecord
  * @return array
  */
 protected function getReceipientsOfStage($stageRecord)
 {
     if (!$stageRecord instanceof StageRecord) {
         $stageRecord = WorkspaceRecord::get($this->getCurrentWorkspace())->getStage($stageRecord);
     }
     $result = array();
     $allRecipients = $this->getStageService()->getResponsibleBeUser($stageRecord);
     $preselectedRecipients = $this->stageService->getPreselectedRecipients($stageRecord);
     $isPreselectionChangeable = $stageRecord->isPreselectionChangeable();
     foreach ($allRecipients as $backendUserId => $backendUser) {
         if (empty($backendUser['email']) || !GeneralUtility::validEmail($backendUser['email'])) {
             continue;
         }
         $name = !empty($backendUser['realName']) ? $backendUser['realName'] : $backendUser['username'];
         $checked = in_array($backendUserId, $preselectedRecipients);
         $disabled = $checked && !$isPreselectionChangeable;
         $result[] = array('boxLabel' => sprintf('%s (%s)', $name, $backendUser['email']), 'name' => 'receipients-' . $backendUserId, 'checked' => $checked, 'disabled' => $disabled);
     }
     return $result;
 }
Example #27
0
 /**
  * Test if a this is a valid email
  *
  * @param   string  email
  * @param   array   (optional) additional info, will be displayed as debug message, if a key "message" exists this will be appended to the error message
  * @throws  Tx_PtExtbase_Exception_Assertion   if assertion fails
  */
 public static function isValidEmail($email, array $info = array())
 {
     self::isString($email);
     return self::test(GeneralUtility::validEmail($email), true, $info);
 }
Example #28
0
 /**
  * Action to create a new BE user
  *
  * @param array $record sys_action record
  * @return string form to create a new user
  */
 protected function viewNewBackendUser($record)
 {
     $content = '';
     $beRec = BackendUtility::getRecord('be_users', (int) $record['t1_copy_of_user']);
     // A record is need which is used as copy for the new user
     if (!is_array($beRec)) {
         $this->addMessage($this->getLanguageService()->getLL('action_notReady'), $this->getLanguageService()->getLL('action_error'), FlashMessage::ERROR);
         $content .= $this->renderFlashMessages();
         return $content;
     }
     $vars = GeneralUtility::_POST('data');
     $key = 'NEW';
     if ($vars['sent'] == 1) {
         $errors = array();
         // Basic error checks
         if (!empty($vars['email']) && !GeneralUtility::validEmail($vars['email'])) {
             $errors[] = $this->getLanguageService()->getLL('error-wrong-email');
         }
         if (empty($vars['username'])) {
             $errors[] = $this->getLanguageService()->getLL('error-username-empty');
         }
         if ($vars['key'] === 'NEW' && empty($vars['password'])) {
             $errors[] = $this->getLanguageService()->getLL('error-password-empty');
         }
         if ($vars['key'] !== 'NEW' && !$this->isCreatedByUser($vars['key'], $record)) {
             $errors[] = $this->getLanguageService()->getLL('error-wrong-user');
         }
         foreach ($this->hookObjects as $hookObject) {
             if (method_exists($hookObject, 'viewNewBackendUser_Error')) {
                 $errors = $hookObject->viewNewBackendUser_Error($vars, $errors, $this);
             }
         }
         // Show errors if there are any
         if (!empty($errors)) {
             $this->addMessage(implode(LF, $errors), $this->getLanguageService()->getLL('action_error'), FlashMessage::ERROR);
         } else {
             // Save user
             $key = $this->saveNewBackendUser($record, $vars);
             // Success message
             $message = $vars['key'] === 'NEW' ? $this->getLanguageService()->getLL('success-user-created') : $this->getLanguageService()->getLL('success-user-updated');
             $this->addMessage($message, $this->getLanguageService()->getLL('success'));
         }
         $content .= $this->renderFlashMessages();
     }
     // Load BE user to edit
     if ((int) GeneralUtility::_GP('be_users_uid') > 0) {
         $tmpUserId = (int) GeneralUtility::_GP('be_users_uid');
         // Check if the selected user is created by the current user
         $rawRecord = $this->isCreatedByUser($tmpUserId, $record);
         if ($rawRecord) {
             // Delete user
             if (GeneralUtility::_GP('delete') == 1) {
                 $this->deleteUser($tmpUserId, $record['uid']);
             }
             $key = $tmpUserId;
             $vars = $rawRecord;
         }
     }
     $content .= '<form action="" class="panel panel-default" method="post" enctype="multipart/form-data">
                     <fieldset class="form-section">
                         <h4 class="form-section-headline">' . $this->getLanguageService()->getLL('action_t1_legend_generalFields') . '</h4>
                         <div class="form-group">
                             <label for="field_disable">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_general.xlf:LGL.disable') . '</label>
                             <input type="checkbox" id="field_disable" name="data[disable]" value="1" class="checkbox" ' . ($vars['disable'] == 1 ? ' checked="checked" ' : '') . ' />
                         </div>
                         <div class="form-group">
                             <label for="field_realname">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_general.xlf:LGL.name') . '</label>
                             <input type="text" id="field_realname" class="form-control" name="data[realName]" value="' . htmlspecialchars($vars['realName']) . '" />
                         </div>
                         <div class="form-group">
                             <label for="field_username">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.username') . '</label>
                             <input type="text" id="field_username" class="form-control" name="data[username]" value="' . htmlspecialchars($vars['username']) . '" />
                         </div>
                         <div class="form-group">
                             <label for="field_password">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.password') . '</label>
                             <input type="password" id="field_password" class="form-control" name="data[password]" value="" />
                         </div>
                         <div class="form-group">
                             <label for="field_email">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_general.xlf:LGL.email') . '</label>
                             <input type="text" id="field_email" class="form-control" name="data[email]" value="' . htmlspecialchars($vars['email']) . '" />
                         </div>
                     </fieldset>
                     <fieldset class="form-section">
                         <h4 class="form-section-headline">' . $this->getLanguageService()->getLL('action_t1_legend_configuration') . '</h4>
                         <div class="form-group">
                             <label for="field_usergroup">' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_tca.xlf:be_users.usergroup') . '</label>
                             <select id="field_usergroup" class="form-control" name="data[usergroup][]" multiple="multiple">
                                 ' . $this->getUsergroups($record, $vars) . '
                             </select>
                         </div>
                         <div class="form-group">
                             <input type="hidden" name="data[key]" value="' . $key . '" />
                             <input type="hidden" name="data[sent]" value="1" />
                             <input class="btn btn-default" type="submit" value="' . ($key === 'NEW' ? $this->getLanguageService()->getLL('action_Create') : $this->getLanguageService()->getLL('action_Update')) . '" />
                         </div>
                     </fieldset>
                 </form>';
     $content .= $this->getCreatedUsers($record, $key);
     return $content;
 }
Example #29
0
 /**
  * Extracts name/email parts from a header field (like 'To:' or 'From:' with name/email mixed up.
  *
  * @param string $str Value from a header field containing name/email values.
  * @return array Array with the name and email in. Email is validated, otherwise not set.
  */
 public function extractNameEmail($str)
 {
     $outArr = array();
     // Email:
     $reg = '';
     preg_match('/<([^>]*)>/', $str, $reg);
     if (GeneralUtility::validEmail($str)) {
         $outArr['email'] = $str;
     } elseif ($reg[1] && GeneralUtility::validEmail($reg[1])) {
         $outArr['email'] = $reg[1];
         // Find name:
         list($namePart) = explode($reg[0], $str);
         if (trim($namePart)) {
             $reg = '';
             preg_match('/"([^"]*)"/', $str, $reg);
             if (trim($reg[1])) {
                 $outArr['name'] = trim($reg[1]);
             } else {
                 $outArr['name'] = trim($namePart);
             }
         }
     }
     return $outArr;
 }
 /**
  * This is the main-function for sending Mails
  *
  * @param array $email Array with all needed mail information
  *        $email['receiverName'] = 'Name';
  *        $email['receiverEmail'] = '*****@*****.**';
  *        $email['senderName'] = 'Name';
  *        $email['senderEmail'] = '*****@*****.**';
  *        $email['subject'] = 'Subject line';
  *        $email['template'] = 'PathToTemplate/';
  *        $email['rteBody'] = 'This is the <b>content</b> of the RTE';
  *        $email['format'] = 'both'; // or plain or html
  * @param Mail &$mail
  * @param array $settings TypoScript Settings
  * @param string $type Email to "sender" or "receiver"
  * @return bool Mail successfully sent
  */
 public function sendEmailPreflight(array $email, Mail &$mail, $settings, $type = 'receiver')
 {
     $this->mail =& $mail;
     $this->settings = $settings;
     $this->configuration = $this->getConfigurationFromSettings($settings);
     $this->overwriteConfiguration = $this->configuration[$type . '.']['overwrite.'];
     $this->contentObject = $this->configurationManager->getContentObject();
     $this->contentObject->start($this->mailRepository->getVariablesWithMarkersFromMail($mail));
     $this->type = $type;
     $this->parseVariables($email, $mail);
     if ($settings['debug']['mail']) {
         GeneralUtility::devLog('Mail properties', 'powermail', 0, $email);
     }
     if (!GeneralUtility::validEmail($email['receiverEmail']) || !GeneralUtility::validEmail($email['senderEmail'])) {
         return false;
     }
     if (empty($email['subject'])) {
         // don't want an error flashmessage
         return true;
     }
     return $this->sendTemplateEmail($email);
 }