diff --git a/typo3/sysext/core/Classes/Mail/TransportFactory.php b/typo3/sysext/core/Classes/Mail/TransportFactory.php index 9c242591e6994047224d8e24bed37b6fe50d124b..1bd203bff6bdd533edf26261b207ed8413c14b87 100644 --- a/typo3/sysext/core/Classes/Mail/TransportFactory.php +++ b/typo3/sysext/core/Classes/Mail/TransportFactory.php @@ -53,22 +53,30 @@ class TransportFactory implements SingletonInterface break; case 'smtp': // Get settings to be used when constructing the transport object - list($host, $port) = preg_split('/:/', $mailSettings['transport_smtp_server'] ?? ''); + if (isset($mailSettings['transport_smtp_server']) && strpos($mailSettings['transport_smtp_server'], ':') > 0) { + $parts = GeneralUtility::trimExplode(':', $mailSettings['transport_smtp_server'], true); + $host = $parts[0]; + $port = $parts[1] ?? null; + } else { + $host = (string)$mailSettings['transport_smtp_server'] ?? null; + $port = null; + } + if ($host === '') { throw new Exception('$GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'transport_smtp_server\'] needs to be set when transport is set to "smtp".', 1291068606); } if ($port === null || $port === '') { $port = 25; } - $useEncryption = $mailSettings['transport_smtp_encrypt'] ?: null; + $useEncryption = $mailSettings['transport_smtp_encrypt'] ?? null; // Create our transport $transport = \Swift_SmtpTransport::newInstance($host, $port, $useEncryption); // Need authentication? - $username = $mailSettings['transport_smtp_username']; + $username = (string)($mailSettings['transport_smtp_username'] ?? ''); if ($username !== '') { $transport->setUsername($username); } - $password = $mailSettings['transport_smtp_password']; + $password = (string)($mailSettings['transport_smtp_password'] ?? ''); if ($password !== '') { $transport->setPassword($password); } diff --git a/typo3/sysext/core/Tests/Unit/Mail/MailerTest.php b/typo3/sysext/core/Tests/Unit/Mail/MailerTest.php index 89eb32f2a51b09a4148acf4f10ee2489787a360c..678e2eaf562d54bb5cf514e031e8ce5667f12108 100644 --- a/typo3/sysext/core/Tests/Unit/Mail/MailerTest.php +++ b/typo3/sysext/core/Tests/Unit/Mail/MailerTest.php @@ -15,26 +15,25 @@ namespace TYPO3\CMS\Core\Tests\Unit\Mail; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Controller\ErrorPageController; +use TYPO3\CMS\Core\Exception; +use TYPO3\CMS\Core\Mail\Mailer; use TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeTransportFixture; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * Testcase for the TYPO3\CMS\Core\Mail\Mailer class. */ -class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase +class MailerTest extends UnitTestCase { /** - * Subject is not notice free, disable E_NOTICES - */ - protected static $suppressNotices = true; - - /** - * @var \TYPO3\CMS\Core\Mail\Mailer + * @var Mailer */ protected $subject; protected function setUp() { - $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer::class) + $this->subject = $this->getMockBuilder(Mailer::class) ->setMethods(['emitPostInitializeMailerSignal']) ->disableOriginalConstructor() ->getMock(); @@ -76,7 +75,7 @@ class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase 'smtp but no host' => [['transport' => 'smtp']], 'sendmail but no command' => [['transport' => 'sendmail']], 'mbox but no file' => [['transport' => 'mbox']], - 'no instance of Swift_Transport' => [['transport' => \TYPO3\CMS\Core\Controller\ErrorPageController::class]] + 'no instance of Swift_Transport' => [['transport' => ErrorPageController::class]] ]; } @@ -87,7 +86,7 @@ class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function wrongConfigurationThrowsException($settings) { - $this->expectException(\TYPO3\CMS\Core\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionCode(1291068569); $this->subject->injectMailSettings($settings);