diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -539,6 +539,7 @@ 'phutil_console_wrap' => 'console/format.php', 'phutil_count' => 'internationalization/pht.php', 'phutil_date_format' => 'utils/viewutils.php', + 'phutil_decode_mime_header' => 'utils/utils.php', 'phutil_deprecated' => 'moduleutils/moduleutils.php', 'phutil_error_listener_example' => 'error/phlog.php', 'phutil_escape_html' => 'markup/render.php', diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php --- a/src/utils/__tests__/PhutilUtilsTestCase.php +++ b/src/utils/__tests__/PhutilUtilsTestCase.php @@ -670,13 +670,9 @@ phutil_var_export( array('foo' => array('bar' => array('baz' => array()))))); - // Objects - $this->assertEqual( - "stdClass::__set_state(array(\n))", - phutil_var_export(new stdClass())); - $this->assertEqual( - "PhutilTestPhobject::__set_state(array(\n))", - phutil_var_export(new PhutilTestPhobject())); + // NOTE: Object behavior differs across PHP versions. Older versions of + // PHP export objects as "stdClass::__set_state(array())". Newer versions + // of PHP (7.3+) export objects as "(object) array()". } public function testFnmatch() { diff --git a/src/utils/utils.php b/src/utils/utils.php --- a/src/utils/utils.php +++ b/src/utils/utils.php @@ -1558,3 +1558,18 @@ return $query; } + +function phutil_decode_mime_header($header) { + if (function_exists('iconv_mime_decode')) { + return iconv_mime_decode($header, 0, 'UTF-8'); + } + + if (function_exists('mb_decode_mimeheader')) { + return mb_decode_mimeheader($header); + } + + throw new Exception( + pht( + 'Unable to decode MIME header: install "iconv" or "mbstring" '. + 'extension.')); +}