Index: t3lib/config_default.php =================================================================== --- t3lib/config_default.php (Revision 10226) +++ t3lib/config_default.php (Revision 10227) @@ -91,7 +91,7 @@ '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<return_path> 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: 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. 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<return_path> 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 php.net. If this is not set, a valid fallback will be searched for by PHP (php.ini's date.timezone setting, server defaults, etc); and if no fallback is found, the value of "UTC" is used instead. 'systemLog' => '', //

String: semi-colon separated list. Defines one or more logging methods. Possible methods:

file,<abs-path-to-file>[,<level>]
logs to a file
mail,<to>[/<from>][,<level>]
sends the log entries via mail
syslog,<facility>,[,<level>]
uses the operating system's log. Facility may be one of LOCAL0..LOCAL7, USER (on Windows USER is the only valid type).
error_log[,,<level>]
uses the PHP error log

The <level> is the individual logging level (see [SYS][systemLogLevel]).

Index: t3lib/utility/class.t3lib_utility_mail.php =================================================================== --- t3lib/utility/class.t3lib_utility_mail.php (Revision 10226) +++ t3lib/utility/class.t3lib_utility_mail.php (Revision 10227) @@ -116,6 +116,90 @@ } 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: t3lib/class.t3lib_beuserauth.php =================================================================== --- t3lib/class.t3lib_beuserauth.php (Revision 10226) +++ t3lib/class.t3lib_beuserauth.php (Revision 10227) @@ -74,7 +74,6 @@ 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 '; var $enablecolumns = Array( 'rootLevel' => 1, @@ -348,21 +347,27 @@ $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: t3lib/class.t3lib_htmlmail.php =================================================================== --- t3lib/class.t3lib_htmlmail.php (Revision 10226) +++ t3lib/class.t3lib_htmlmail.php (Revision 10227) @@ -245,6 +245,7 @@ * @return void */ public function t3lib_htmlmail() { + t3lib_div::logDeprecatedFunction(); $this->forceReturnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath']; $this->mailer = 'TYPO3'; Index: t3lib/class.t3lib_div.php =================================================================== --- t3lib/class.t3lib_div.php (Revision 10226) +++ t3lib/class.t3lib_div.php (Revision 10227) @@ -6038,13 +6038,20 @@ // 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: t3lib/mail/class.t3lib_mail_swiftmaileradapter.php =================================================================== --- t3lib/mail/class.t3lib_mail_swiftmaileradapter.php (Revision 10226) +++ t3lib/mail/class.t3lib_mail_swiftmaileradapter.php (Revision 10227) @@ -256,7 +256,7 @@ // 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: t3lib/mail/class.t3lib_mail_message.php =================================================================== --- t3lib/mail/class.t3lib_mail_message.php (Revision 10226) +++ t3lib/mail/class.t3lib_mail_message.php (Revision 10227) @@ -45,6 +45,11 @@ 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 @@ public function send() { $this->initializeMailer(); $this->sent = TRUE; + $this->getHeaders()->addTextHeader('X-Mailer', $this->mailerHeader); return $this->mailer->send($this, $this->failedRecipients); } Index: t3lib/class.t3lib_formmail.php =================================================================== --- t3lib/class.t3lib_formmail.php (Revision 10226) +++ t3lib/class.t3lib_formmail.php (Revision 10227) @@ -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) * @@ -55,11 +55,30 @@ * @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 * This class is able to generate a mail in formmail-style from the data in $V @@ -82,116 +101,153 @@ * @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 = ''; + $plainTextContent = ''; + $htmlContent = '
'; // 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 .= ''; + $plainTextContent .= strtoupper($key) . ': ' . $space . $plainTextValue . LF . $space; + $htmlContent .= ''; } } } - $HTML_content .= '
' . strtoupper($key) . '' . nl2br($HTML_val) . ' 
' . strtoupper($key) + . '' . nl2br($HtmlValue) + . ' 
'; + $htmlContent .= ''; - if ($V['html_enabled']) { - $this->setHTML($this->encodeMsg($HTML_content)); + $this->plainContent = $plainTextContent; + + 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 @@ } /** - * 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 @@ } 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 @@ include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']); } -?> \ No newline at end of file +?> Index: t3lib/class.t3lib_userauthgroup.php =================================================================== --- t3lib/class.t3lib_userauthgroup.php (Revision 10226) +++ t3lib/class.t3lib_userauthgroup.php (Revision 10227) @@ -1890,8 +1890,7 @@ 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 @@ $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: typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php =================================================================== --- typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php (Revision 10226) +++ typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php (Revision 10227) @@ -97,8 +97,6 @@ } } - $fromEmail = $this->getFromAddress(); - $subject = sprintf( $GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] @@ -118,66 +116,16 @@ $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; - } } Index: typo3/sysext/cms/tslib/class.tslib_pagegen.php =================================================================== --- typo3/sysext/cms/tslib/class.tslib_pagegen.php (Revision 10226) +++ typo3/sysext/cms/tslib/class.tslib_pagegen.php (Revision 10227) @@ -278,6 +278,7 @@ } // 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: typo3/sysext/install/mod/class.tx_install.php =================================================================== --- typo3/sysext/install/mod/class.tx_install.php (Revision 10226) +++ typo3/sysext/install/mod/class.tx_install.php (Revision 10227) @@ -2655,17 +2655,9 @@ case 'get_form': $out = '

- 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. -
- Since almost all mails in TYPO3 are sent using the - t3lib_htmlmail class, sending with this class can be - tested by checking the box - Test t3lib_htmlmail 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".

'; // Get the template file @@ -2688,7 +2680,6 @@ '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 @@ $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 TEST CONTENT')); - $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 TEST CONTENT'); + $mailMessage->addPart('TEST CONTENT'); + $mailMessage->send(); $this->mailMessage= 'Mail was sent to: ' . $email; } break; Index: typo3/sysext/install/Resources/Private/Templates/CheckMail.html =================================================================== --- typo3/sysext/install/Resources/Private/Templates/CheckMail.html (Revision 10226) +++ typo3/sysext/install/Resources/Private/Templates/CheckMail.html (Revision 10227) @@ -20,10 +20,6 @@ -
  • - - -