W3cubDocs

/Drupal 8

public static function Unicode::mimeHeaderDecode

public static Unicode::mimeHeaderDecode($header)

Decodes MIME/HTTP encoded header values.

Parameters

string $header: The header to decode.

Return value

string The mime-decoded header.

File

core/lib/Drupal/Component/Utility/Unicode.php, line 634

Class

Unicode
Provides Unicode-related conversions and operations.

Namespace

Drupal\Component\Utility

Code

public static function mimeHeaderDecode($header) {
  $callback = function($matches) {
    $data = ($matches[2] == 'B') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3]));
    if (strtolower($matches[1]) != 'utf-8') {
      $data = static::convertToUtf8($data, $matches[1]);
    }
    return $data;
  };
  // First step: encoded chunks followed by other encoded chunks (need to collapse whitespace)
  $header = preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=\s+(?==\?)/', $callback, $header);
  // Second step: remaining chunks (do not collapse whitespace)
  return preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=/', $callback, $header);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Unicode.php/function/Unicode::mimeHeaderDecode/8.1.x