Fixed issue #17065: Use Swift Mailer in core (t3lib_mail_*) and deprecate t3lib_htmlm...
authorErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 21:32:43 +0000 (21:32 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 21:32:43 +0000 (21:32 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10227 709f56b5-9817-0410-a4d7-c38de5d9e867

14 files changed:
ChangeLog
t3lib/class.t3lib_beuserauth.php
t3lib/class.t3lib_div.php
t3lib/class.t3lib_formmail.php
t3lib/class.t3lib_htmlmail.php
t3lib/class.t3lib_userauthgroup.php
t3lib/config_default.php
t3lib/mail/class.t3lib_mail_message.php
t3lib/mail/class.t3lib_mail_swiftmaileradapter.php
t3lib/utility/class.t3lib_utility_mail.php
typo3/sysext/cms/tslib/class.tslib_pagegen.php
typo3/sysext/install/Resources/Private/Templates/CheckMail.html
typo3/sysext/install/mod/class.tx_install.php
typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php

index abdbdb4..59557e1 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
 
 2011-01-21  Ernesto Baschny  <ernst@cron-it.de>
 
+       * Fixed issue #17065: Use Swift Mailer in core (t3lib_mail_*) and deprecate t3lib_htmlmail and related settings (Thanks to Jigal van Hemert)
        * Fixed bug #17173: CSRF: In the user settings module, saving form data is not possible if simulate user option is used (Thanks to Helmut Hummel)
        * Follow-up to issue #16878: Keep t3lib_utility_Client::getBrowserInfo backwards compatible, deprecate 'system' and only use 'all_systems' from now on
        * Fixed bug #16994: ExtDirect in frontend generates php warnings (Thanks to Stefan Galinski)
index a188bb3..5718e4c 100644 (file)
@@ -74,7 +74,6 @@ class t3lib_beUserAuth extends t3lib_userAuthGroup {
        var $userident_column = 'password'; // Column for password
        var $userid_column = 'uid'; // Column for user-id
        var $lastLogin_column = 'lastlogin';
-       var $notifyHeader = 'From: TYPO3 Login notify <no_reply@no_reply.no_reply>';
 
        var $enablecolumns = Array(
                'rootLevel' => 1,
@@ -348,21 +347,27 @@ class t3lib_beUserAuth extends t3lib_userAuthGroup {
                                        $prefix = '[AdminLoginWarning]';
                                }
                                if ($warn) {
-                                       t3lib_utility_Mail::mail($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'],
-                                                       $prefix . ' ' . $subject,
-                                               $msg,
-                                               $this->notifyHeader
-                                       );
+                                       $from = t3lib_utility_Mail::getSystemFrom();
+                                       /** @var $mail t3lib_mail_Message */
+                                       $mail = t3lib_div::makeInstance('t3lib_mail_Message');
+                                       $mail->setTo($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'])
+                                                       ->setFrom($from)
+                                                       ->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'], '@')) {
-                               t3lib_utility_Mail::mail($this->user['email'],
-                                       $subject,
-                                       $msg,
-                                       $this->notifyHeader
-                               );
+                               $from = t3lib_utility_Mail::getSystemFrom();
+                               /** @var $mail t3lib_mail_Message */
+                               $mail = t3lib_div::makeInstance('t3lib_mail_Message');
+                               $mail->setTo($this->user['email'])
+                                               ->setFrom($from)
+                                               ->setSubject($subject)
+                                               ->setBody($msg);
+                               $mail->send();
                        }
                }
        }
index d263511..1c824e1 100644 (file)
@@ -6038,13 +6038,20 @@ final class t3lib_div {
                                // send message per mail
                        elseif ($type == 'mail') {
                                list($to, $from) = explode('/', $destination);
-                               t3lib_utility_Mail::mail($to, 'Warning - error in TYPO3 installation',
-                                               'Host: ' . $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] . LF .
+                               if (!t3lib_div::validEmail($from)) {
+                                       $from = t3lib_utility_Mail::getSystemFrom();
+                               }
+                               /** @var $mail t3lib_mail_Message */
+                               $mail = t3lib_div::makeInstance('t3lib_mail_Message');
+                               $mail->setTo($to)
+                                               ->setFrom($from)
+                                               ->setSubject('Warning - error in TYPO3 installation')
+                                               ->setBody('Host: ' . $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] . LF .
                                                                'Extension: ' . $extKey . LF .
                                                                'Severity: ' . $severity . LF .
-                                                               LF . $msg,
-                                       ($from ? 'From: ' . $from : '')
+                                                               LF . $msg
                                );
+                               $mail->send();
                        }
                                // use the PHP error log
                        elseif ($type == 'error_log') {
index 8c280dc..40448b3 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  *
- *   69: class t3lib_formmail extends t3lib_htmlmail
+ *   69: class t3lib_formmail
  *   95:        function start($V,$base64=false)
  *  172:        function addAttachment($file, $filename)
  *
  * @subpackage t3lib
  * @see tslib_fe::sendFormmail(), t3lib/formmail.php
  */
-class t3lib_formmail extends t3lib_htmlmail {
+class t3lib_formmail {
        protected $reserved_names = 'recipient,recipient_copy,auto_respond_msg,auto_respond_checksum,redirect,subject,attachment,from_email,from_name,replyto_email,replyto_name,organisation,priority,html_enabled,quoted_printable,submit_x,submit_y';
-       var $dirtyHeaders = array(); // collection of suspicious header data, used for logging
+       protected $dirtyHeaders = array(); // collection of suspicious header data, used for logging
 
+       protected $characterSet;
+       protected $subject;
+       protected $fromName;
+       protected $replyToName;
+       protected $organisation;
+       protected $fromAddress;
+       protected $replyToAddress;
+       protected $priority;
+       protected $autoRespondMessage;
+       protected $encoding = 'quoted-printable';
+
+       /** @var t3lib_mail_Message */
+       protected $mailMessage;
+       protected $recipient;
+       protected $returnPath;
+       protected $plainContent = '';
+
+       /** @var array Files to clean up at the end (attachments) */
+       protected $temporaryFiles = array();
 
        /**
         * Start function
@@ -82,116 +101,153 @@ class t3lib_formmail extends t3lib_htmlmail {
         * @param       boolean         Whether to base64 encode the mail content
         * @return      void
         */
-       function start($V, $base64 = false) {
-               $convCharset = FALSE; // do we need to convert form data?
+       function start($valueList, $base64 = false) {
 
-               if ($GLOBALS['TSFE']->config['config']['formMailCharset']) { // Respect formMailCharset if it was set
-                       $this->charset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
-                       $convCharset = TRUE;
+               $this->mailMessage = t3lib_div::makeInstance('t3lib_mail_Message');
 
-               } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) { // Use metaCharset for mail if different from renderCharset
-                       $this->charset = $GLOBALS['TSFE']->metaCharset;
-                       $convCharset = TRUE;
+               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath']) {
+                       $this->returnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath'];
+                       $this->mailMessage->setReturnPath($this->returnPath);
                }
+               $this->mailMessage->getHeaders()->addTextHeader('X-Mailer', 'TYPO3');
 
-               parent::start();
+               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;
+               }
 
-               if ($base64 || $V['use_base64']) {
-                       $this->useBase64();
+               if ($base64 || $valueList['use_base64']) {
+                       $this->encoding = 'base64';
                }
 
-               if (isset($V['recipient'])) {
+               if (isset($valueList['recipient'])) {
                                // convert form data from renderCharset to mail charset
-                       $val = ($V['subject']) ? $V['subject'] : 'Formmail on ' . t3lib_div::getIndpEnv('HTTP_HOST');
-                       $this->subject = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val, $GLOBALS['TSFE']->renderCharset, $this->charset) : $val;
+                       $this->subject = ($valueList['subject'])
+                                       ? $valueList['subject']
+                                       : 'Formmail on ' . t3lib_div::getIndpEnv('HTTP_HOST');
                        $this->subject = $this->sanitizeHeaderString($this->subject);
-                       $val = ($V['from_name']) ? $V['from_name'] : (($V['name']) ? $V['name'] : ''); // Be careful when changing $val! It is used again as the fallback value for replyto_name
-                       $this->from_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val, $GLOBALS['TSFE']->renderCharset, $this->charset) : $val;
-                       $this->from_name = $this->sanitizeHeaderString($this->from_name);
-                       $this->from_name = preg_match('/\s|,/', $this->from_name) >= 1 ? '"' . $this->from_name . '"' : $this->from_name;
-                       $val = ($V['replyto_name']) ? $V['replyto_name'] : $val;
-                       $this->replyto_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val, $GLOBALS['TSFE']->renderCharset, $this->charset) : $val;
-                       $this->replyto_name = $this->sanitizeHeaderString($this->replyto_name);
-                       $this->replyto_name = preg_match('/\s|,/', $this->replyto_name) >= 1 ? '"' . $this->replyto_name . '"' : $this->replyto_name;
-                       $val = ($V['organisation']) ? $V['organisation'] : '';
-                       $this->organisation = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val, $GLOBALS['TSFE']->renderCharset, $this->charset) : $val;
+
+                       $this->fromName = ($valueList['from_name'])
+                                       ? $valueList['from_name']
+                                       : (($valueList['name']) ? $valueList['name'] : '');
+                       $this->fromName = $this->sanitizeHeaderString($this->fromName);
+                       $this->fromName = preg_match('/\s|,/', $this->fromName) >= 1 ? '"' . $this->fromName . '"' : $this->fromName;
+
+                       $this->replyToName = ($valueList['replyto_name']) ? $valueList['replyto_name'] : $this->fromName;
+                       $this->replyToName = $this->sanitizeHeaderString($this->replyToName);
+                       $this->replyToName = preg_match('/\s|,/', $this->replyToName) >= 1 ? '"' . $this->replyToName . '"' : $this->replyToName;
+
+                       $this->organisation = ($valueList['organisation']) ? $valueList['organisation'] : '';
                        $this->organisation = $this->sanitizeHeaderString($this->organisation);
 
-                       $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email']) ? $V['email'] : '');
-                       $this->from_email = t3lib_div::validEmail($this->from_email) ? $this->from_email : '';
-                       $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email;
-                       $this->replyto_email = t3lib_div::validEmail($this->replyto_email) ? $this->replyto_email : '';
-                       $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'], 1, 5) : 3;
+                       $this->fromAddress = ($valueList['from_email']) ? $valueList['from_email'] : (
+                               ($valueList['email']) ? $valueList['email'] : ''
+                       );
+                       $this->fromAddress = t3lib_div::validEmail($this->fromAddress)
+                                       ? $this->fromAddress
+                                       : t3lib_utility_Mail::getSystemFromAddress();
+
+                       $this->replyToAddress = ($valueList['replyto_email']) ? $valueList['replyto_email'] : $this->fromAddress;
+                       $this->replyToAddress = t3lib_div::validEmail($this->replyToAddress)
+                                       ? $this->replyToAddress
+                                       : t3lib_utility_Mail::getSystemFromAddress();
+
+                       $this->priority = ($valueList['priority']) ? t3lib_div::intInRange($valueList['priority'], 1, 5) : 3;
 
                                // auto responder
-                       $this->auto_respond_msg = (trim($V['auto_respond_msg']) && $this->from_email) ? trim($V['auto_respond_msg']) : '';
+                       $this->autoRespondMessage = (trim($valueList['auto_respond_msg']) && $this->fromAddress)
+                                       ? trim($valueList['auto_respond_msg'])
+                                       : '';
 
-                       if ($this->auto_respond_msg !== '') {
+                       if ($this->autoRespondMessage !== '') {
                                        // Check if the value of the auto responder message has been modified with evil intentions
-                               $autoRespondChecksum = $V['auto_respond_checksum'];
-                               $correctHmacChecksum = t3lib_div::hmac($this->auto_respond_msg);
+                               $autoRespondChecksum = $valueList['auto_respond_checksum'];
+                               $correctHmacChecksum = t3lib_div::hmac($this->autoRespondMessage);
                                if ($autoRespondChecksum !== $correctHmacChecksum) {
-                                       t3lib_div::sysLog('Possible misuse of t3lib_formmail auto respond method. Subject: ' . $V['subject'], 'Core', 3);
+                                       t3lib_div::sysLog('Possible misuse of t3lib_formmail auto respond method. Subject: ' . $valueList['subject'],
+                                               'Core',
+                                               3);
                                        return;
                                } else {
-                                       $this->auto_respond_msg = $this->sanitizeHeaderString($this->auto_respond_msg);
+                                       $this->autoRespondMessage = $this->sanitizeHeaderString($this->autoRespondMessage);
                                }
                        }
 
-                       $Plain_content = '';
-                       $HTML_content = '<table border="0" cellpadding="2" cellspacing="2">';
+                       $plainTextContent = '';
+                       $htmlContent = '<table border="0" cellpadding="2" cellspacing="2">';
 
                                // Runs through $V and generates the mail
-                       if (is_array($V)) {
-                               foreach ($V as $key => $val) {
+                       if (is_array($valueList)) {
+                               foreach ($valueList as $key => $val) {
                                        if (!t3lib_div::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)
-                                               $Plain_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val, $GLOBALS['TSFE']->renderCharset, $this->charset, 0) : $val;
-                                               $HTML_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv(htmlspecialchars($val), $GLOBALS['TSFE']->renderCharset, $this->charset, 1) : htmlspecialchars($val);
+                                               $plainTextValue = $val;
+                                               $HtmlValue = htmlspecialchars($val);
 
-                                               $Plain_content .= strtoupper($key) . ':  ' . $space . $Plain_val . LF . $space;
-                                               $HTML_content .= '<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><strong>' . strtoupper($key) . '</strong></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">' . nl2br($HTML_val) . '&nbsp;</font></td></tr>';
+                                               $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>';
                                        }
                                }
                        }
-                       $HTML_content .= '</table>';
+                       $htmlContent .= '</table>';
+
+                       $this->plainContent = $plainTextContent;
 
-                       if ($V['html_enabled']) {
-                               $this->setHTML($this->encodeMsg($HTML_content));
+                       if ($valueList['html_enabled']) {
+                               $this->mailMessage->setBody($htmlContent, 'text/html');
+                               $this->mailMessage->addPart($plainTextContent, 'text/plain');
+                       } else {
+                               $this->mailMessage->setBody($plainTextContent, 'text/plain');
                        }
-                       $this->addPlain($Plain_content);
 
                        for ($a = 0; $a < 10; $a++) {
-                               $varname = 'attachment' . (($a) ? $a : '');
-                               if (!isset($_FILES[$varname])) {
+                               $variableName = 'attachment' . (($a) ? $a : '');
+                               if (!isset($_FILES[$variableName])) {
                                        continue;
                                }
-                               if (!is_uploaded_file($_FILES[$varname]['tmp_name'])) {
-                                       t3lib_div::sysLog('Possible abuse of t3lib_formmail: temporary file "' . $_FILES[$varname]['tmp_name'] . '" ("' . $_FILES[$varname]['name'] . '") was not an uploaded file.', 'Core', 3);
+                               if (!is_uploaded_file($_FILES[$variableName]['tmp_name'])) {
+                                       t3lib_div::sysLog('Possible abuse of t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name']
+                                                       . '" ("' . $_FILES[$variableName]['name'] . '") was not an uploaded file.', 'Core', 3);
                                }
-                               if ($_FILES[$varname]['tmp_name']['error'] !== UPLOAD_ERR_OK) {
-                                       t3lib_div::sysLog('Error in uploaded file in t3lib_formmail: temporary file "' . $_FILES[$varname]['tmp_name'] . '" ("' . $_FILES[$varname]['name'] . '") Error code: ' . $_FILES[$varname]['tmp_name']['error'], 'Core', 3);
+                               if ($_FILES[$variableName]['tmp_name']['error'] !== UPLOAD_ERR_OK) {
+                                       t3lib_div::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', 3);
                                }
-                               $theFile = t3lib_div::upload_to_tempfile($_FILES[$varname]['tmp_name']);
-                               $theName = $_FILES[$varname]['name'];
+                               $theFile = t3lib_div::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->addAttachment($theFile, $theName);
+                                               $this->mailMessage->attach(Swift_Attachment::fromPath($theFile)->setFilename($theName));
                                        }
                                }
-                               t3lib_div::unlink_tempfile($theFile);
+                               $this->temporaryFiles[] = $theFile;
                        }
 
-                       $this->setHeaders();
-                       $this->setContent();
-                       $this->setRecipient($V['recipient']);
-                       if ($V['recipient_copy']) {
-                               $this->recipient_copy = trim($V['recipient_copy']);
+                       $this->recipient = $valueList['recipient'];
+                       $this->mailMessage->setSubject($this->subject)
+                                       ->setFrom(array($this->fromAddress => $this->fromName))
+                                       ->setTo($this->recipient)
+                                       ->setPriority($this->priority);
+                       $this->mailMessage->getHeaders()->addTextHeader('Organization', $this->organisation);
+                       if ($valueList['recipient_copy']) {
+                               $this->mailMessage->addCc(trim($valueList['recipient_copy']));
                        }
+                       if ($this->characterSet) {
+                               $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) {
                                t3lib_div::sysLog('Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', 3);
@@ -203,51 +259,12 @@ class t3lib_formmail extends t3lib_htmlmail {
        }
 
        /**
-        * Adds an attachment to the mail
-        *
-        * @param       string          The absolute path to the file to add as attachment
-        * @param       string          The files original filename (not necessarily the same as the current since this could be uploaded files...)
-        * @return      boolean         True if the file existed and was added.
-        * @access private
-        */
-       function addAttachment($file, $filename) {
-               $content = $this->getURL($file); // We fetch the content and the mime-type
-               $fileInfo = $this->split_fileref($filename);
-               if ($fileInfo['fileext'] == 'gif') {
-                       $content_type = 'image/gif';
-               }
-               if ($fileInfo['fileext'] == 'bmp') {
-                       $content_type = 'image/bmp';
-               }
-               if ($fileInfo['fileext'] == 'jpg' || $fileInfo['fileext'] == 'jpeg') {
-                       $content_type = 'image/jpeg';
-               }
-               if ($fileInfo['fileext'] == 'html' || $fileInfo['fileext'] == 'htm') {
-                       $content_type = 'text/html';
-               }
-               if (!$content_type) {
-                       $content_type = 'application/octet-stream';
-               }
-
-               if ($content) {
-                       $theArr['content_type'] = $content_type;
-                       $theArr['content'] = $content;
-                       $theArr['filename'] = $filename;
-                       $this->theParts['attach'][] = $theArr;
-                       return TRUE;
-               } else {
-                       return FALSE;
-               }
-       }
-
-
-       /**
         * Checks string for suspicious characters
         *
         * @param       string  String to check
         * @return      string  Valid or empty string
         */
-       function sanitizeHeaderString($string) {
+       protected function sanitizeHeaderString($string) {
                $pattern = '/[\r\n\f\e]/';
                if (preg_match($pattern, $string) > 0) {
                        $this->dirtyHeaders[] = $string;
@@ -255,6 +272,50 @@ class t3lib_formmail extends t3lib_htmlmail {
                }
                return $string;
        }
+       
+       /**
+        * Sends the actual mail and handles autorespond message
+        *
+        * @return boolean
+        */
+       public function sendTheMail() {
+
+                       // Sending the mail requires the recipient and message to be set.
+               if (!$this->mailMessage->getTo() || !trim($this->mailMessage->getBody())) {
+                       return FALSE;
+               }
+
+               $this->mailMessage->send();
+
+                       // Auto response
+               if ($this->autoRespondMessage) {
+                       $theParts = explode('/', $this->autoRespondMessage, 2);
+                       $theParts[0] = str_replace('###SUBJECT###', $this->subject, $theParts[0]);
+                       $theParts[1] = str_replace("/", LF, $theParts[1]);
+                       $theParts[1] = str_replace("###MESSAGE###", $this->plainContent, $theParts[1]);
+
+                               /** @var $autoRespondMail t3lib_mail_Message */
+                       $autoRespondMail = t3lib_div::makeInstance('t3lib_mail_Message');
+                       $autoRespondMail->setTo($this->fromAddress)
+                                       ->setSubject($theParts[0])
+                                       ->setFrom($this->recipient)
+                                       ->setBody($theParts[1]);
+                       if ($this->returnPath) {
+                               $autoRespondMail->setReturnPath($this->returnPath);
+                       }
+                       $autoRespondMail->send();
+               }
+               return $this->mailMessage->isSent();
+       }
+
+       /**
+        * Do some cleanup at the end (deleting attachment files)
+        */
+       public function __destruct() {
+               foreach ($this->temporaryFiles as $file) {
+                       t3lib_div::unlink_tempfile($file);
+               }
+       }
 }
 
 
@@ -262,4 +323,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
 }
 
-?>
\ No newline at end of file
+?>
index a3070d9..e5302b7 100644 (file)
@@ -245,6 +245,7 @@ class t3lib_htmlmail {
         * @return      void
         */
        public function t3lib_htmlmail() {
+               t3lib_div::logDeprecatedFunction();
                $this->forceReturnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath'];
 
                $this->mailer = 'TYPO3';
index fd74654..21a5cea 100644 (file)
@@ -1890,8 +1890,7 @@ class t3lib_userAuthGroup extends t3lib_userAuth {
                        if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > $max) {
                                        // OK, so there were more than the max allowed number of login failures - so we will send an email then.
                                $subject = 'TYPO3 Login Failure Warning (at ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . ')';
-                               $email_body = '
-There has been numerous attempts (' . $GLOBALS['TYPO3_DB']->sql_num_rows($res) . ') to login at the TYPO3
+                               $email_body = 'There have been some attempts (' . $GLOBALS['TYPO3_DB']->sql_num_rows($res) . ') to login at the TYPO3
 site "' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '" (' . t3lib_div::getIndpEnv('HTTP_HOST') . ').
 
 This is a dump of the failures:
@@ -1902,11 +1901,14 @@ This is a dump of the failures:
                                        $email_body .= date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $testRows['tstamp']) . ':  ' . @sprintf($testRows['details'], '' . $theData[0], '' . $theData[1], '' . $theData[2]);
                                        $email_body .= LF;
                                }
-                               t3lib_utility_Mail::mail($email,
-                                                                                $subject,
-                                                                                $email_body,
-                                                                                'From: TYPO3 Login WARNING<>'
-                               );
+                               $from = t3lib_utility_Mail::getSystemFrom();
+                               /** @var $mail t3lib_mail_Message */
+                               $mail = t3lib_div::makeInstance('t3lib_mail_Message');
+                               $mail->setTo($email)
+                                               ->setFrom($from)
+                                               ->setSubject($subject)
+                                               ->setBody($email_body);
+                               $mail->send();
                                $this->writelog(255, 4, 0, 3, 'Failure warning (%s failures within %s seconds) sent by email to %s', array($GLOBALS['TYPO3_DB']->sql_num_rows($res), $secondsBack, $email)); // Logout written to log
                        }
                }
index 9c62ed4..edc6e01 100644 (file)
@@ -91,7 +91,7 @@ $TYPO3_CONF_VARS = array(
                'setDBinit' => '-1',                                            // String (textarea): Commands to send to database right after connecting, separated by newline. Ignored by the DBAL extension except for the 'native' type!
                'dbClientCompress' => FALSE,                    // Boolean: if true, data exchange between TYPO3 and database server will be compressed. This may improve performance if (1) database serever is on the different server and (2) network connection speed to database server is 100mbps or less. CPU usage will be higher if this option is used but database operations will be executed faster due to much less (up to 3 times) database network traffic. This option has no effect if MySQL server is localhost.
                'setMemoryLimit' => 0,                                  // Integer: memory_limit in MB: If more than 16, TYPO3 will try to use ini_set() to set the memory limit of PHP to the value. This works only if the function ini_set() is not disabled by your sysadmin.
-               'forceReturnPath' => FALSE,                             // Boolean: Force return path to be applied in mail() calls. If this is set, all calls to mail() done by t3lib_htmlmail will be called with '-f&lt;return_path&gt; as the 5th parameter. This will make the return path correct on almost all Unix systems. There is a known problem with Postfix below version 2: Mails are not sent if this option is set and Postfix is used. On Windows platforms, the return path is set via a call to ini_set. This has no effect if safe_mode in PHP is on.
+               'forceReturnPath' => FALSE,                             // Boolean: <em>Note: This option is deprecated as of TYPO3 4.5 together with t3lib_htmlmail. This behaviour is the default using the new t3lib_mail methods.</em> Force return path to be applied in mail() calls. If this is set, all calls to mail() done by t3lib_htmlmail will be called with '-f&lt;return_path&gt; as the 5th parameter. This will make the return path correct on almost all Unix systems. There is a known problem with Postfix below version 2: Mails are not sent if this option is set and Postfix is used. On Windows platforms, the return path is set via a call to ini_set. This has no effect if safe_mode in PHP is on.
                'serverTimeZone' => 1,                                  // Integer: GMT offset of servers time (from time()). Default is "1" which is "GMT+1" (central european time). This value can be used in extensions that are GMT aware and wants to convert times to/from other timezones.
                'phpTimeZone' => '',                                    // String: timezone to force for all date() and mktime() functions. A list of supported values can be found at <a href="http://php.net/manual/en/timezones.php" target="_blank">php.net</a>. If this is not set, a valid fallback will be searched for by PHP (php.ini's <a href="http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone" target="_blank">date.timezone</a> setting, server defaults, etc); and if no fallback is found, the value of "UTC" is used instead.
                'systemLog' => '',                                              // <p>String: semi-colon separated list. Defines one or more logging methods. Possible methods:</p><dl><dt>file,&lt;abs-path-to-file&gt;[,&lt;level&gt;]</dt><dd>logs to a file</dd><dt>mail,&lt;to&gt;[/&lt;from&gt;][,&lt;level&gt;]</dt><dd>sends the log entries via mail</dd><dt>syslog,&lt;facility&gt;,[,&lt;level&gt;]</dt><dd>uses the operating system's log. Facility may be one of LOCAL0..LOCAL7, USER (on Windows USER is the only valid type).</dd><dt>error_log[,,&lt;level&gt;]</dt><dd>uses the PHP error log</dd></dl><p>The &lt;level&gt; is the individual logging level (see <a href="#SYS-systemLogLevel">[SYS][systemLogLevel]</a>).</p>
index 64e018b..929f245 100644 (file)
@@ -45,6 +45,11 @@ class t3lib_mail_Message extends Swift_Message {
        protected $mailer;
 
        /**
+        * @var string This will be added as X-Mailer to all outgoing mails
+        */
+       protected $mailerHeader = 'TYPO3';
+
+       /**
         * True if the message has been sent.
         * @var boolean
         */
@@ -73,6 +78,7 @@ class t3lib_mail_Message extends Swift_Message {
        public function send() {
                $this->initializeMailer();
                $this->sent = TRUE;
+               $this->getHeaders()->addTextHeader('X-Mailer', $this->mailerHeader);
                return $this->mailer->send($this, $this->failedRecipients);
        }
 
index 654c8af..f97e010 100644 (file)
@@ -256,7 +256,7 @@ class t3lib_mail_SwiftMailerAdapter implements t3lib_mail_MailerAdapter {
                                // The headers have already been set, so use header information
                        $contentType = $this->message->getContentType();
                        $charset = $this->message->getCharset();
-                       $encoding = $this->message->getEncoder();
+                       $encoding = $this->message->getEncoder()->getName();
                                // reverse encoding and set body
                        $rawBody = $this->decode($body, $encoding);
                        $this->message->setBody($rawBody, $contentType, $charset);
index 9d245c6..f507492 100644 (file)
@@ -116,6 +116,90 @@ final class t3lib_utility_Mail {
                }
                return $success;
        }
+
+       /**
+        * Gets a valid "from" for mail messages (email and name).
+        *
+        * Ready to be passed to $mail->setFrom() (t3lib_mail)
+        *
+        * @return array key=Valid email address which can be used as sender, value=Valid name which can be used as a sender. NULL if no address is configured
+        */
+       public static function getSystemFrom() {
+               $address = self::getSystemFromAddress();
+               $name = self::getSystemFromName();
+               if (!$address) {
+                       return NULL;
+               } elseif ($name) {
+                       return array($address => $name);
+               } else {
+                       return array($address);
+               }
+       }
+
+       /**
+        * Creates a valid "from" name for mail messages.
+        *
+        * As configured in Install Tool.
+        *
+        * @return string The name (unquoted, unformatted). NULL if none is set
+        */
+       public static function getSystemFromName() {
+               if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) {
+                       return $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
+               } else {
+                       return NULL;
+               }
+       }
+
+       /**
+        * Creates a valid email address for the sender of mail messages.
+        *
+        * Uses a fall back chain:
+        *     Install Tool ->
+        *     no-reply@FirstDomainRecordFound ->
+        *     no-reply@php_uname('n')
+        *
+        * Ready to be passed to $mail->setFrom() (t3lib_mail)
+        *
+        * @return array key=Valid email address which can be used as sender, value=Valid name which can be used as a sender
+        */
+       public static function getSystemFromAddress() {
+
+                       // first check the localconf setting
+               $address = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
+               if (!t3lib_div::validEmail($address)) {
+                               // just get us a domain record we can use
+                       $domainRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
+                               'domainName',
+                               'sys_domain',
+                               'hidden = 0',
+                               '',
+                               'pid ASC, sorting ASC'
+                       );
+                       if (!empty($domainRecord['domainName'])) {
+                               $tempUrl = $domainRecord['domainName'];
+
+                               if (!t3lib_div::isFirstPartOfStr($tempUrl, 'http')) {
+                                               // shouldn't be the case anyways, but you never know
+                                               // ... there're crazy people out there
+                                       $tempUrl = 'http://' .$tempUrl;
+                               }
+                               $host = parse_url($tempUrl, PHP_URL_HOST);
+                       }
+                       $address = 'no-reply@' . $host;
+                       if (!t3lib_div::validEmail($address)) {
+                                       // get host name from server
+                               $host = php_uname('n');
+                               $address = 'no-reply@' . $host;
+                               if (!t3lib_div::validEmail($address)) {
+                                               // if everything fails use a dummy address
+                                       $address = 'no-reply@example.org';
+                               }
+                       }
+
+               }
+               return $address;
+       }
 }
 
 ?>
\ No newline at end of file
index 056c278..02517ca 100644 (file)
@@ -278,6 +278,7 @@ See <a href="http://wiki.typo3.org/index.php/TYPO3_3.8.1" target="_blank">wiki.t
                }
                        // Include HTML mail library?
                if ($GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail'])    {
+                       $GLOBALS['TSFE']->logDeprecatedTyposcript('config.incT3Lib_htmlmail');
                        $incFilesArray[] = 't3lib/class.t3lib_htmlmail.php';
                }
                return $incFilesArray;
index 0e8c57c..a453c0a 100644 (file)
                                                <label for="t3-install-checkmail" class="t3-install-strong">###ENTEREMAIL###</label>
                                                <input id="t3-install-checkmail" type="text" name="TYPO3_INSTALL[check_mail]" class="t3-install-form-input-text" />
                                        </li>
-                                       <li class="t3-install-form-label-after">
-                                               <input id="t3-install-usehtmlmail" type="checkbox" name="TYPO3_INSTALL[use_htmlmail]" />
-                                               <label for="t3-install-usehtmlmail" class="t3-install-strong">###USEHTMLMAILLABEL###</label>
-                                       </li>
                                </ol>
                        </fieldset>
                        <fieldset class="t3-install-form-submit">
index 057638f..37f3dde 100755 (executable)
@@ -2655,17 +2655,9 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                        case 'get_form':
                                $out = '
                                        <p id="checkMailForm">
-                                               You can check the mail() function by entering your email
+                                               You can check the t3lib_mail functionality by entering your email
                                                address here and press the button. You should then
-                                               receive a testmail from test@test.test.
-                                               <br />
-                                               Since almost all mails in TYPO3 are sent using the
-                                               t3lib_htmlmail class, sending with this class can be
-                                               tested by checking the box
-                                               <strong>Test t3lib_htmlmail</strong> below.
-                                               The return-path of the mail is set to null@' . t3lib_div::getIndpEnv('HTTP_HOST') . '.
-                                               Some mail servers won\'t send the mail if the host of
-                                               the return-path is not resolved correctly.
+                                               receive a testmail from "typo3installtool@example.org".
                                        </p>
                                ';
                                        // Get the template file
@@ -2688,7 +2680,6 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        'message' => $this->mailMessage,
                                        'enterEmail' => 'Enter the email address',
                                        'actionUrl' => $this->action . '#checkMailForm',
-                                       'useHtmlMailLabel' => 'Test t3lib_htmlmail',
                                        'submit' => 'Send test mail'
                                );
                                        // Fill the markers
@@ -2705,20 +2696,14 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        $subject = 'TEST SUBJECT';
                                        $email = trim($this->INSTALL['check_mail']);
 
-                                       if($this->INSTALL['use_htmlmail']) {
-                                               $emailObj = t3lib_div::makeInstance('t3lib_htmlmail');
-                                               /* @var $emailObj t3lib_htmlmail */
-                                               $emailObj->start();
-                                               $emailObj->subject = $subject;
-                                               $emailObj->from_email = 'test@test.test';
-                                               $emailObj->from_name = 'TYPO3 Install Tool';
-                                               $emailObj->returnPath = 'null@'.t3lib_div::getIndpEnv('HTTP_HOST');
-                                               $emailObj->addPlain('TEST CONTENT');
-                                               $emailObj->setHTML($emailObj->encodeMsg('<html><body>HTML TEST CONTENT</body></html>'));
-                                               $emailObj->send($email);
-                                       } else {
-                                               t3lib_div::plainMailEncoded($email,$subject,'TEST CONTENT','From: test@test.test');
-                                       }
+                                               /** @var $mailMessage t3lib_mail_Message */
+                                       $mailMessage = t3lib_div::makeInstance('t3lib_mail_Message');
+                                       $mailMessage->addTo($email)
+                                                       ->addFrom('typo3installtool@example.org', 'TYPO3 Install Tool')
+                                                       ->setSubject($subject)
+                                                       ->setBody('<html><body>HTML TEST CONTENT</body></html>');
+                                       $mailMessage->addPart('TEST CONTENT');
+                                       $mailMessage->send();
                                        $this->mailMessage= 'Mail was sent to: ' . $email;
                                }
                        break;
index c0cc163..aa13eda 100644 (file)
@@ -97,8 +97,6 @@ class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task {
                        }
                }
 
-               $fromEmail = $this->getFromAddress();
-
                $subject = sprintf(
                        $GLOBALS['LANG']->getLL('status_updateTask_email_subject'),
                        $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
@@ -118,66 +116,16 @@ class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task {
                $message .= implode(CRLF, $systemIssues);
                $message .= CRLF . CRLF;
 
+               $from = t3lib_utility_Mail::getSystemFrom();
+
                $mail = t3lib_div::makeInstance('t3lib_mail_Message');
-               $mail->setFrom(array($fromEmail => $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']));
+               $mail->setFrom($from);
                $mail->setTo($this->notificationEmail);
                $mail->setSubject($subject);
                $mail->setBody($message);
 
                $mail->send();
        }
-
-       /**
-        * Tries to find an email address to use for the From email header.
-        *
-        * Uses a fall back chain:
-        *     Install Tool ->
-        *     no-reply@FirstDomainRecordFound ->
-        *     no-reply@php_uname('n')
-        *
-        * @return      string  email address
-        */
-       protected function getFromAddress() {
-               $email = '';
-               $user  = 'no-reply';
-
-                       // default
-               $email = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'];
-
-                       // find domain record
-               if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
-                               // just get us a domain record we can use
-                       $domainRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
-                               'domainName',
-                               'sys_domain',
-                               'hidden = 0',
-                               '',
-                               'pid ASC, sorting ASC'
-                       );
-
-                       if (!empty($domainRecord['domainName'])) {
-                               $tempUrl = $domainRecord['domainName'];
-
-                               if (!t3lib_div::isFirstPartOfStr($tempUrl, 'http')) {
-                                               // shouldn't be the case anyways, but you never know
-                                               // ... there're crazy people out there
-                                       $tempUrl = 'http://' .$tempUrl;
-                               }
-
-                               $host = parse_url($tempUrl, PHP_URL_HOST);
-                       }
-
-                       $email = $user . '@' . $host;
-               }
-
-                       // uname
-               if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
-                       $host  = php_uname('n');
-                       $email = $user . '@' . $host;
-               }
-
-               return $email;
-       }
 }