[BUGFIX] Always use system getFrom() when sending emails 85/51885/3
authorBenni Mack <benni@typo3.org>
Tue, 28 Feb 2017 06:40:09 +0000 (07:40 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 28 Feb 2017 14:30:05 +0000 (15:30 +0100)
When instantiating MailMessage() and no valid sender is
given, a fallback is used in different places of TYPO3. To ensure
that all mails sent out (e.g. when instantiated via extensions)
have a proper From() header, the default fallback is set
just before sending the emails.

Resolves: #80055
Releases: master
Change-Id: I6b740b2dcf5a84437fac2e9bf60aac3321e91377
Reviewed-on: https://review.typo3.org/51885
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
typo3/sysext/core/Classes/Mail/MailMessage.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/reports/Classes/Task/SystemStatusUpdateTask.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index b977620..85dba0e 100644 (file)
@@ -2452,10 +2452,9 @@ This is a dump of the failures:
                         ) . ':  ' . @sprintf($row['details'], (string)$theData[0], (string)$theData[1], (string)$theData[2]);
                     $email_body .= LF;
                 }
-                $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                 /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                 $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
-                $mail->setTo($email)->setFrom($from)->setSubject($subject)->setBody($email_body);
+                $mail->setTo($email)->setSubject($subject)->setBody($email_body);
                 $mail->send();
                 // Logout written to log
                 $this->writelog(255, 4, 0, 3, 'Failure warning (%s failures within %s seconds) sent by email to %s', [$result->rowCount(), $secondsBack, $email]);
@@ -2647,19 +2646,17 @@ This is a dump of the failures:
                     $prefix = '[AdminLoginWarning]';
                 }
                 if ($warn) {
-                    $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                     /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                     $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
-                    $mail->setTo($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'])->setFrom($from)->setSubject($prefix . ' ' . $subject)->setBody($msg);
+                    $mail->setTo($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'])->setSubject($prefix . ' ' . $subject)->setBody($msg);
                     $mail->send();
                 }
             }
             // If An email should be sent to the current user, do that:
             if ($this->uc['emailMeAtLogin'] && strstr($this->user['email'], '@')) {
-                $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                 /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                 $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
-                $mail->setTo($this->user['email'])->setFrom($from)->setSubject($subject)->setBody($msg);
+                $mail->setTo($this->user['email'])->setSubject($subject)->setBody($msg);
                 $mail->send();
             }
         }
index e2f2776..b621f7c 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Mail;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\MailUtility;
+
 /**
  * Adapter for Swift_Mailer to be used by TYPO3 extensions
  */
@@ -58,6 +60,10 @@ class MailMessage extends \Swift_Message
      */
     public function send()
     {
+        // Ensure to always have a From: header set
+        if (empty($this->getFrom())) {
+            $this->setFrom(MailUtility::getSystemFrom());
+        }
         $this->initializeMailer();
         $this->sent = true;
         $this->getHeaders()->addTextHeader('X-Mailer', $this->mailerHeader);
index 8e70e39..2f1e4f5 100644 (file)
@@ -6909,13 +6909,10 @@ class ContentObjectRenderer
         $senderName = trim($senderName);
         $senderAddress = trim($senderAddress);
         if ($senderName !== '' && $senderAddress !== '') {
-            $sender = [$senderAddress => $senderName];
+            $mail->setFrom([$senderAddress => $senderName]);
         } elseif ($senderAddress !== '') {
-            $sender = [$senderAddress];
-        } else {
-            $sender = MailUtility::getSystemFrom();
+            $mail->setFrom([$senderAddress]);
         }
-        $mail->setFrom($sender);
         $parsedReplyTo = MailUtility::parseAddresses($replyTo);
         if (!empty($parsedReplyTo)) {
             $mail->setReplyTo($parsedReplyTo);
@@ -6935,12 +6932,13 @@ class ContentObjectRenderer
             }
             $parsedCc = MailUtility::parseAddresses($cc);
             if (!empty($parsedCc)) {
+                $from = $mail->getFrom();
                 /** @var $mail MailMessage */
                 $mail = GeneralUtility::makeInstance(MailMessage::class);
                 if (!empty($parsedReplyTo)) {
                     $mail->setReplyTo($parsedReplyTo);
                 }
-                $mail->setFrom($sender)
+                $mail->setFrom($from)
                     ->setTo($parsedCc)
                     ->setSubject($subject)
                     ->setBody($plainMessage);
index 8cb9513..a72f9f6 100644 (file)
@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Reports\Task;
 use TYPO3\CMS\Core\Mail\MailMessage;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\MailUtility;
 use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Reports\Status;
 use TYPO3\CMS\Scheduler\Task\AbstractTask;
@@ -115,10 +114,8 @@ class SystemStatusUpdateTask extends AbstractTask
         $message .= $this->getLanguageService()->getLL('status_updateTask_email_issues') . ': ' . CRLF;
         $message .= implode(CRLF, $systemIssues);
         $message .= CRLF . CRLF;
-        $from = MailUtility::getSystemFrom();
         /** @var MailMessage $mail */
         $mail = GeneralUtility::makeInstance(MailMessage::class);
-        $mail->setFrom($from);
         $mail->setTo($sendEmailsTo);
         $mail->setSubject($subject);
         $mail->setBody($message);
index 6d328b3..8ae7778 100644 (file)
@@ -656,7 +656,6 @@ class DataHandlerHook
                 }
                 $mail->setTo($recipient)
                     ->setSubject($emailSubject)
-                    ->setFrom(\TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom())
                     ->setBody($emailMessage);
                 $mail->send();
             }