예제 #1
0
 /**
  * Method called from tests mailCallsHook() and mailCallsHookWithDefaultMailFrom().
  */
 protected function doMailCallsHook($fromAddress = '', $fromName = '')
 {
     // Backup configuration
     $mailConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
     $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = $fromAddress;
     $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = $fromName;
     $to = '*****@*****.**';
     $subject = 'Good news everybody!';
     $messageBody = 'The hooks works!';
     $additionalHeaders = 'Reply-to: jane@example.com';
     $additionalParameters = '-f postmaster@example.com';
     $fakeThis = FALSE;
     $additionalHeadersExpected = $additionalHeaders;
     if ($fromAddress !== '' && $fromName !== '') {
         $additionalHeadersExpected .= LF . sprintf('From: "%s" <%s>', $fromName, $fromAddress);
     }
     $mockMailer = $this->getMock('TYPO3\\CMS\\Core\\Mail\\MailerAdapterInterface', array('mail'));
     $mockClassName = get_class($mockMailer);
     \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($mockClassName, $mockMailer);
     $mockMailer->expects($this->once())->method('mail')->with($to, $subject, $messageBody, $additionalHeadersExpected, $additionalParameters, $fakeThis)->will($this->returnValue(TRUE));
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'] = array($mockClassName);
     \TYPO3\CMS\Core\Utility\MailUtility::mail($to, $subject, $messageBody, $additionalHeaders, $additionalParameters);
     // Restore configuration
     $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $mailConfigurationBackup;
 }
 /**
  * Simple substitute for the PHP function mail() which allows you to specify encoding and character set
  * The fifth parameter ($encoding) will allow you to specify 'base64' encryption for the output (set $encoding=base64)
  * Further the output has the charset set to UTF-8 by default.
  *
  * @param string $email Email address to send to. (see PHP function mail())
  * @param string $subject Subject line, non-encoded. (see PHP function mail())
  * @param string $message Message content, non-encoded. (see PHP function mail())
  * @param string $headers Headers, separated by LF
  * @param string $encoding Encoding type: "base64", "quoted-printable", "8bit". Default value is "quoted-printable".
  * @param string $charset Charset used in encoding-headers (only if $encoding is set to a valid value which produces such a header)
  * @param boolean $dontEncodeHeader If set, the header content will not be encoded
  * @return boolean TRUE if mail was accepted for delivery, FALSE otherwise
  * @deprecated since 6.1, will be removed two versions later - Use \TYPO3\CMS\Core\Mail\Mailer instead
  */
 public static function plainMailEncoded($email, $subject, $message, $headers = '', $encoding = 'quoted-printable', $charset = '', $dontEncodeHeader = FALSE)
 {
     self::logDeprecatedFunction();
     if (!$charset) {
         $charset = 'utf-8';
     }
     $email = self::normalizeMailAddress($email);
     if (!$dontEncodeHeader) {
         // Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable
         $newHeaders = array();
         // Split the header in lines and convert each line separately
         foreach (explode(LF, $headers) as $line) {
             // Field tags must not be encoded
             $parts = explode(': ', $line, 2);
             if (count($parts) == 2) {
                 if (0 == strcasecmp($parts[0], 'from')) {
                     $parts[1] = self::normalizeMailAddress($parts[1]);
                 }
                 $parts[1] = self::encodeHeader($parts[1], $encoding, $charset);
                 $newHeaders[] = implode(': ', $parts);
             } else {
                 // Should never happen - is such a mail header valid? Anyway, just add the unchanged line...
                 $newHeaders[] = $line;
             }
         }
         $headers = implode(LF, $newHeaders);
         unset($newHeaders);
         // Email address must not be encoded, but it could be appended by a name which should be so (e.g. "Kasper Skårhøj <*****@*****.**>")
         $email = self::encodeHeader($email, $encoding, $charset);
         $subject = self::encodeHeader($subject, $encoding, $charset);
     }
     switch ((string) $encoding) {
         case 'base64':
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset="' . $charset . '"' . LF . 'Content-Transfer-Encoding: base64';
             // Adding LF because I think MS outlook 2002 wants it... may be removed later again.
             $message = trim(chunk_split(base64_encode($message . LF))) . LF;
             break;
         case '8bit':
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset=' . $charset . LF . 'Content-Transfer-Encoding: 8bit';
             break;
         case 'quoted-printable':
         default:
             $headers = trim($headers) . LF . 'Mime-Version: 1.0' . LF . 'Content-Type: text/plain; charset=' . $charset . LF . 'Content-Transfer-Encoding: quoted-printable';
             $message = self::quoted_printable($message);
     }
     // Headers must be separated by CRLF according to RFC 2822, not just LF.
     // But many servers (Gmail, for example) behave incorrectly and want only LF.
     // So we stick to LF in all cases.
     // Make sure no empty lines are there.
     $headers = trim(implode(LF, self::trimExplode(LF, $headers, TRUE)));
     return \TYPO3\CMS\Core\Utility\MailUtility::mail($email, $subject, $message, $headers);
 }