diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index d60fcec11d..d4cd47087a 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -34,9 +34,10 @@ $text_body_headers = $parser->getMessageBodyHeaders('text'); $content_type = idx($text_body_headers, 'content-type'); if ( !phutil_is_utf8($text_body) && - preg_match('/charset="(.*?)"/', $content_type, $matches) + (preg_match('/charset="(.*?)"/', $content_type, $matches) || + preg_match('/charset=(\S+)/', $content_type, $matches)) ) { - $text_body = mb_convert_encoding($text_body, "UTF-8", $matches[1]); + $text_body = phutil_utf8_convert($text_body, "UTF-8", $matches[1]); } $headers = $parser->getHeaders(); diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index 38e6a3bf92..5687813209 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -318,7 +318,7 @@ final class PhabricatorRepositoryCommitHeraldWorker return; } - $encoding = $repository->getDetail('encoding', 'utf-8'); + $encoding = $repository->getDetail('encoding', 'UTF-8'); $result = null; $patch_error = null; @@ -347,9 +347,8 @@ final class PhabricatorRepositoryCommitHeraldWorker if ($len <= $inline_patches) { // We send email as utf8, so we need to convert the text to utf8 if // we can. - if (strtolower($encoding) != 'utf-8' && - function_exists('mb_convert_encoding')) { - $raw_patch = mb_convert_encoding($raw_patch, 'utf-8', $encoding); + if ($encoding) { + $raw_patch = phutil_utf8_convert($raw_patch, 'UTF-8', $encoding); } $result = phutil_utf8ize($raw_patch); } diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php index 8d394ab679..079f20123e 100644 --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php @@ -37,17 +37,9 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker $parts = explode("\0", $info); $encoding = array_shift($parts); - // See note above - git doesn't always convert the encoding correctly. - $do_convert = false; - if (strlen($encoding) && strtoupper($encoding) != 'UTF-8') { - if (function_exists('mb_convert_encoding')) { - $do_convert = true; - } - } - foreach ($parts as $key => $part) { - if ($do_convert) { - $parts[$key] = mb_convert_encoding($part, 'UTF-8', $encoding); + if ($encoding) { + $part = phutil_utf8_convert($part, 'UTF-8', $encoding); } $parts[$key] = phutil_utf8ize($part); }