iconv_mime_decode example

$this->mailRepository = $entityManager->getRepository(Mail::class);
        $this->orderRepository = $entityManager->getRepository(Order::class);
    }

    /** * {@inheritdoc} */
    public function build(Enlight_Components_Mail $mail): Log
    {
        $logEntry = new Log();

        $logEntry->setSubject((string) iconv_mime_decode((string) $mail->getSubject()));
        $logEntry->setSender($mail->getFrom());
        $logEntry->setSentAt(new DateTime((string) $mail->getDate()));
        $logEntry->setContentText($mail->getPlainBodyText());

        if ($mail->getBodyHtml() instanceof Zend_Mime_Part) {
            $logEntry->setContentHtml($mail->getBodyHtml()->getRawContent());
        }

        $this->assignType($logEntry$mail->getTemplateName());
        $this->assignOrder($logEntry$mail);
        $this->assignShop($logEntry$mail);

        
if (!function_exists('iconv_strpos')) {
        function iconv_strpos($haystack$needle$offset = 0, $encoding = null) { return p\Iconv::iconv_strpos($haystack$needle$offset$encoding)}
    }
    if (!function_exists('iconv_strrpos')) {
        function iconv_strrpos($haystack$needle$encoding = null) { return p\Iconv::iconv_strrpos($haystack$needle$encoding)}
    }
    if (!function_exists('iconv_substr')) {
        function iconv_substr($string$offset$length = 2147483647, $encoding = null) { return p\Iconv::iconv_substr($string$offset$length$encoding)}
    }
    if (!function_exists('iconv_mime_decode')) {
        function iconv_mime_decode($string$mode = 0, $encoding = null) { return p\Iconv::iconv_mime_decode($string$mode$encoding)}
    }
}


        if (false !== strpos($str, "\r")) {
            $str = strtr(str_replace("\r\n", "\n", $str), "\r", "\n");
        }
        $str = explode("\n\n", $str, 2);

        $headers = [];

        $str = preg_split('/\n(?![ \t])/', $str[0]);
        foreach ($str as $str) {
            $str = self::iconv_mime_decode($str$mode$charset);
            if (false === $str) {
                return false;
            }
            $str = explode(':', $str, 2);

            if (2 === \count($str)) {
                if (isset($headers[$str[0]])) {
                    if (!\is_array($headers[$str[0]])) {
                        $headers[$str[0]] = [$headers[$str[0]]];
                    }
                    $headers[$str[0]][] = ltrim($str[1]);
                }
// Test that long site names containing characters that need MIME encoding     // works as expected.     $this->config('system.site')->set('name', 'Drépal this is a very long test sentence to test what happens with very long site names')->save();
    // Send an email and check that the From-header contains the site name.     \Drupal::service('plugin.manager.mail')->mail('mail_cancel_test', 'from_test', 'from_test@example.com', $language);
    $captured_emails = \Drupal::state()->get('system.test_mail_collector');
    $sent_message = end($captured_emails);
    // From header is correctly encoded.     $this->assertEquals('=?utf-8?Q?Dr=C3=A9pal?= this is a very long test sentence to test what happens with very long site names <mailtest@example.com>', $sent_message['headers']['From']);
    // From header is correctly encoded.     $this->assertEquals('Drépal this is a very long test sentence to test what happens with very long site names <mailtest@example.com>', iconv_mime_decode($sent_message['headers']['From']));
    $this->assertFalse(isset($sent_message['headers']['Reply-to']), 'Message reply-to is not set if not specified.');
    // Errors-to header must not be set, it is deprecated.     $this->assertFalse(isset($sent_message['headers']['Errors-To']));

    // Test that From names containing commas work as expected.     $this->config('system.site')->set('name', 'Foo, Bar, and Baz')->save();
    // Send an email and check that the From-header contains the site name.     \Drupal::service('plugin.manager.mail')->mail('mail_cancel_test', 'from_test', 'from_test@example.com', $language);
    $captured_emails = \Drupal::state()->get('system.test_mail_collector');
    $sent_message = end($captured_emails);
    // From header contains the quoted site name with commas.
if (!function_exists('iconv_strpos')) {
        function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Iconv::iconv_strpos((string) $haystack(string) $needle(int) $offset$encoding)}
    }
    if (!function_exists('iconv_strrpos')) {
        function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { return p\Iconv::iconv_strrpos((string) $haystack(string) $needle$encoding)}
    }
    if (!function_exists('iconv_substr')) {
        function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { return p\Iconv::iconv_substr((string) $string(string) $offset$length$encoding)}
    }
    if (!function_exists('iconv_mime_decode')) {
        function iconv_mime_decode(?string $string, ?int $mode = 0, ?string $encoding = null): string|false { return p\Iconv::iconv_mime_decode((string) $string(int) $mode$encoding)}
    }
}
array_walk_recursive($varsfunction D&$v) use (&$ok$toEncoding$fromEncoding) {
            if (false === $v = self::mb_convert_encoding($v$toEncoding$fromEncoding)) {
                $ok = false;
            }
        });

        return $ok ? $fromEncoding : false;
    }

    public static function mb_decode_mimeheader($s)
    {
        return iconv_mime_decode($s, 2, self::$internalEncoding);
    }

    public static function mb_encode_mimeheader($s$charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
    {
        trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
    }

    public static function mb_decode_numericentity($s$convmap$encoding = null)
    {
        if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
            trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING);

            

            if ( ( 'multipart/alternative' === $content_type ) && ( str_contains( $line, 'boundary="' ) ) && ( '' === $boundary ) ) {
                $boundary = trim( $line );
                $boundary = explode( '"', $boundary );
                $boundary = $boundary[1];
            }
            if ( preg_match( '/Subject: /i', $line ) ) {
                $subject = trim( $line );
                $subject = substr( $subject, 9, strlen( $subject ) - 9 );
                // Captures any text in the subject before $phone_delim as the subject.                 if ( function_exists( 'iconv_mime_decode' ) ) {
                    $subject = iconv_mime_decode( $subject, 2, get_option( 'blog_charset' ) );
                } else {
                    $subject = wp_iso_descrambler( $subject );
                }
                $subject = explode( $phone_delim$subject );
                $subject = $subject[0];
            }

            /* * Set the author using the email address (From or Reply-To, the last used) * otherwise use the site admin. */
            
Home | Imprint | This part of the site doesn't use cookies.