From 62cfde259656641edcf7face89ae4aaab1375c6f Mon Sep 17 00:00:00 2001
From: Stefan Galinski <stefan@sgalinski.de>
Date: Sat, 24 Nov 2018 18:05:02 +0100
Subject: [PATCH] [BUGFIX] Another bunch of fixes. (default mail was never
 used, form mailing could crash)

---
 Classes/Finisher/Forms/FormsFinisher.php | 19 ++++++++-----------
 Classes/Service/MailTemplateService.php  |  2 +-
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/Classes/Finisher/Forms/FormsFinisher.php b/Classes/Finisher/Forms/FormsFinisher.php
index 0f9d6fc1..202d4921 100644
--- a/Classes/Finisher/Forms/FormsFinisher.php
+++ b/Classes/Finisher/Forms/FormsFinisher.php
@@ -46,12 +46,9 @@ class FormsFinisher extends AbstractFinisher {
 	];
 
 	/**
-	 *
 	 * Send email with the sgmail api to one or more recipients
 	 * overwrites the mail markers with custom identifiers if provided
 	 *
-	 * @see AbstractFinisher::execute()
-	 *
 	 * @throws \InvalidArgumentException
 	 * @throws \BadFunctionCallException
 	 * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
@@ -92,8 +89,8 @@ class FormsFinisher extends AbstractFinisher {
 			}
 		}
 
-		$templateName = trim($this->parseOption('template'));
-		if ($this->parseOption('template') === '') {
+		$templateName = trim((string) $this->parseOption('template'));
+		if ($templateName === '') {
 			$templateName = $formDefinition->getIdentifier();
 		}
 
@@ -107,32 +104,32 @@ class FormsFinisher extends AbstractFinisher {
 		$mailTemplateService->setIgnoreMailQueue($ignoreMailQueue);
 		$mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']);
 
-		$mailToAdresses = trim($this->parseOption('mailTo'));
+		$mailToAdresses = trim((string) $this->parseOption('mailTo'));
 		if ($mailToAdresses !== '') {
 			$mailTemplateService->setToAddresses($this->parseOption('mailTo'));
 		}
 
-		$fromAddress = trim($this->parseOption('mailFrom'));
+		$fromAddress = trim((string) $this->parseOption('mailFrom'));
 		if ($fromAddress !== '') {
 			$mailTemplateService->setFromAddress($fromAddress);
 		}
 
-		$fromName = trim($this->parseOption('userName'));
+		$fromName = trim((string) $this->parseOption('userName'));
 		if ($fromName !== '') {
 			$mailTemplateService->setFromName($fromName);
 		}
 
-		$replyTo = trim($this->parseOption('replyTo'));
+		$replyTo = trim((string) $this->parseOption('replyTo'));
 		if ($replyTo !== '') {
 			$mailTemplateService->setReplyToAddress($replyTo);
 		}
 
-		$ccAddresses = trim($this->parseOption('cc'));
+		$ccAddresses = trim((string) $this->parseOption('cc'));
 		if ($ccAddresses !== '') {
 			$mailTemplateService->setCcAddresses($ccAddresses);
 		}
 
-		$bccAddresses = trim($this->parseOption('bcc'));
+		$bccAddresses = trim((string) $this->parseOption('bcc'));
 		if ($bccAddresses !== '') {
 			$mailTemplateService->setBccAddresses($bccAddresses);
 		}
diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php
index 121a12c1..3eceed49 100644
--- a/Classes/Service/MailTemplateService.php
+++ b/Classes/Service/MailTemplateService.php
@@ -173,7 +173,7 @@ class MailTemplateService {
 		$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
 
 		// use defaultMailFromAddress if it is provided in LocalConfiguration.php; use the sg_mail TS setting as fallback
-		if (!filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
+		if (filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
 			$this->fromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
 		} else {
 			$this->fromAddress = $tsSettings['mail']['default']['from'];
-- 
GitLab