function Unicode::mimeHeaderDecode
Same name in other branches
- 8.9.x core/lib/Drupal/Component/Utility/Unicode.php \Drupal\Component\Utility\Unicode::mimeHeaderDecode()
Decodes MIME/HTTP encoded header values.
Parameters
string $header: The header to decode.
Return value
string The mime-decoded header.
Deprecated
in drupal:9.2.0 and is removed from drupal:10.0.0. Use iconv_mime_decode() instead.
See also
https://www.drupal.org/node/3207439
1 call to Unicode::mimeHeaderDecode()
- UnicodeTest::testMimeHeaderDecode in core/
tests/ Drupal/ Tests/ Component/ Utility/ UnicodeTest.php - Tests multibyte decoding.
File
-
core/
lib/ Drupal/ Component/ Utility/ Unicode.php, line 437
Class
- Unicode
- Provides Unicode-related conversions and operations.
Namespace
Drupal\Component\UtilityCode
public static function mimeHeaderDecode($header) {
@trigger_error('\\Drupal\\Component\\Utility\\Unicode::mimeHeaderDecode() is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use iconv_mime_decode() instead. See https://www.drupal.org/node/3207439', E_USER_DEPRECATED);
$callback = function ($matches) {
$data = strtolower($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('/=\\?([^?]+)\\?([Qq]|[Bb])\\?([^?]+|\\?(?!=))\\?=\\s+(?==\\?)/', $callback, $header);
// Second step: remaining chunks (do not collapse whitespace)
return preg_replace_callback('/=\\?([^?]+)\\?([Qq]|[Bb])\\?([^?]+|\\?(?!=))\\?=/', $callback, $header);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.