Skip to content

Stdlib: mb_encode_mimeheader()/mb_decode_mimeheader() RFC 2047 parity (#6038) - #8679

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6038-mb-encode-mimeheader
Jun 15, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-6038-mb-encode-mimeheader

Conversation

@PurHur

@PurHur PurHur commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement mb_encode_mimeheader() and mb_decode_mimeheader() in ext/mbstring/ with RFC 2047 B/Q encoded-word support (php-src ext/mbstring/mbstring.c).
  • PHP-in-PHP: VmMbstring::encodeMimeheader() / decodeMimeheader(); compile-time JIT/AOT fold via JitMbMimeheader.php; enum operands throw TypeError via shared string guards.
  • Compliance + AOT fixtures guard round-trip, mixed ASCII/non-ASCII, Q encoding, and php-src-strict enum rejection.

Closes #6038

php-src reference

  • ext/mbstring/mbstring.cPHP_FUNCTION(mb_encode_mimeheader), PHP_FUNCTION(mb_decode_mimeheader), mb_mime_header_encode, mb_mime_header_decode

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "
echo function_exists(\"mb_encode_mimeheader\") ? \"encode yes\n\" : \"encode no\n\";
\$s = \"日本語\";
\$enc = mb_encode_mimeheader(\$s, \"UTF-8\");
echo \$enc, \"\n\";
echo mb_decode_mimeheader(\$enc), \"\n\";
echo mb_encode_mimeheader(\"Hello 世界\", \"UTF-8\"), \"\n\";
"
vendor/bin/phpunit --filter mb_encode_mimeheader
'

Output:

encode yes
=?UTF-8?B?5pel5pys6Kqe?=
日本語
Hello =?UTF-8?B?5LiW55WM?=
OK (6 tests, 10 assertions)

Test plan

  • VM repro matches Zend for UTF-8 round-trip, ASCII passthrough, mixed strings
  • vendor/bin/phpunit --filter mb_encode_mimeheader — 6/6 (VM + JIT + AOT + enum TypeError)
  • Capability matrix rows: mb_encode_mimeheader, mb_decode_mimeheader (yes/yes/yes)

Made with Cursor

…#6038)

Implement MIME header encoded-word encode/decode in ext/mbstring with VM,
compile-time JIT/AOT folding, enum TypeError guards, and compliance tests.

php-src ref: ext/mbstring/mbstring.c — PHP_FUNCTION(mb_encode_mimeheader),
PHP_FUNCTION(mb_decode_mimeheader).

Closes #6038

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: mb_encode_mimeheader()/mb_decode_mimeheader() — MIME header encoding missing (ext/mbstring/mbstring.c)

1 participant