Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Iconv.php

function Iconv::iconv_mime_decode

1 call to Iconv::iconv_mime_decode()
Iconv::iconv_mime_decode_headers in vendor/symfony/polyfill-iconv/Iconv.php

File

vendor/symfony/polyfill-iconv/Iconv.php, line 266

Class

Iconv
iconv implementation in pure PHP, UTF-8 centric.

Namespace

Symfony\Polyfill\Iconv

Code

public static function iconv_mime_decode($str, $mode = 0, $charset = null) {
    if (null === $charset) {
        $charset = self::$internalEncoding;
    }
    if (\ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode) {
        $charset .= '//IGNORE';
    }
    if (false !== strpos($str, "\r")) {
        $str = strtr(str_replace("\r\n", "\n", $str), "\r", "\n");
    }
    $str = preg_split('/\\n(?![ \\t])/', rtrim($str), 2);
    $str = preg_replace('/[ \\t]*\\n[ \\t]+/', ' ', rtrim($str[0]));
    $str = preg_split('/=\\?([^?]+)\\?([bqBQ])\\?(.*?)\\?=/', $str, -1, \PREG_SPLIT_DELIM_CAPTURE);
    $result = self::iconv('utf-8', $charset, $str[0]);
    if (false === $result) {
        return false;
    }
    $i = 1;
    $len = \count($str);
    while ($i < $len) {
        $c = strtolower($str[$i]);
        if (\ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode && 'utf-8' !== $c && !isset(self::$alias[$c]) && !self::loadMap('from.', $c, $d)) {
            $d = false;
        }
        elseif ('B' === strtoupper($str[$i + 1])) {
            $d = base64_decode($str[$i + 2]);
        }
        else {
            $d = rawurldecode(strtr(str_replace('%', '%25', $str[$i + 2]), '=_', '% '));
        }
        if (false !== $d) {
            if ('' !== $d) {
                if ('' === ($d = self::iconv($c, $charset, $d))) {
                    $str[$i + 3] = substr($str[$i + 3], 1);
                }
                else {
                    $result .= $d;
                }
            }
            $d = self::iconv('utf-8', $charset, $str[$i + 3]);
            if ('' !== trim($d)) {
                $result .= $d;
            }
        }
        elseif (\ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode) {
            $result .= "=?{$str[$i]}?{$str[$i + 1]}?{$str[$i + 2]}?={$str[$i + 3]}";
        }
        else {
            $result = false;
            break;
        }
        $i += 4;
    }
    return $result;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal