From: Pierre Joye Date: Sat, 2 May 2009 17:59:46 +0000 (+0000) Subject: - [DOC] MFH: add imap_mutf7_to_utf8 and imap_utf8_to_mutf7 X-Git-Tag: php-5.3.0RC2~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9faccc3da1ccea9f7d6475e07b9a761ebd276c37;p=php - [DOC] MFH: add imap_mutf7_to_utf8 and imap_utf8_to_mutf7 --- diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 0114056c3a..8ad4ac1a4a 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -351,6 +351,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf7_encode, 0, 0, 1) ZEND_ARG_INFO(0, buf) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_utf8_to_mutf7, 0, 0, 1) + ZEND_ARG_INFO(0, in) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_mutf7_to_utf8, 0, 0, 1) + ZEND_ARG_INFO(0, in) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setflag_full, 0, 0, 3) ZEND_ARG_INFO(0, stream_id) ZEND_ARG_INFO(0, sequence) @@ -509,6 +517,8 @@ const zend_function_entry imap_functions[] = { PHP_FE(imap_search, arginfo_imap_search) PHP_FE(imap_utf7_decode, arginfo_imap_utf7_decode) PHP_FE(imap_utf7_encode, arginfo_imap_utf7_encode) + PHP_FE(imap_utf8_to_mutf7, arginfo_imap_utf8_to_mutf7) + PHP_FE(imap_mutf7_to_utf8, arginfo_imap_mutf7_to_utf8) PHP_FE(imap_mime_header_decode, arginfo_imap_mime_header_decode) PHP_FE(imap_thread, arginfo_imap_thread) PHP_FE(imap_timeout, arginfo_imap_timeout) @@ -2885,6 +2895,47 @@ PHP_FUNCTION(imap_utf7_encode) #undef B64 #undef UNB64 +static void php_imap_mutf7(INTERNAL_FUNCTION_PARAMETERS, int mode) +{ + char *in; + int in_len; + unsigned char *out; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in, &in_len) == FAILURE) { + return; + } + + if (in_len < 1) { + RETURN_EMPTY_STRING(); + } + + if (mode == 0) { + out = utf8_to_mutf7((unsigned char *) in); + } else { + out = utf8_from_mutf7((unsigned char *) in); + } + + if (out == NIL) { + RETURN_FALSE; + } else { + RETURN_STRING((char *)out, 1); + } +} + +/* {{{ proto string imap_utf8_to_mutf7(string in) + Encode a UTF-8 string to modified UTF-7 */ +PHP_FUNCTION(imap_utf8_to_mutf7) +{ + php_imap_mutf7(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); +} + +/* {{{ proto string imap_mutf7_to_utf8(string in) + Decode a modified UTF-7 string to UTF-8 */ +PHP_FUNCTION(imap_mutf7_to_utf8) +{ + php_imap_mutf7(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); +} + /* {{{ proto bool imap_setflag_full(resource stream_id, string sequence, string flag [, int options]) Sets flags on messages */ PHP_FUNCTION(imap_setflag_full) diff --git a/ext/imap/php_imap.h b/ext/imap/php_imap.h index b0c65419d0..6f44029562 100644 --- a/ext/imap/php_imap.h +++ b/ext/imap/php_imap.h @@ -165,6 +165,8 @@ PHP_FUNCTION(imap_search); PHP_FUNCTION(imap_utf8); PHP_FUNCTION(imap_utf7_decode); PHP_FUNCTION(imap_utf7_encode); +PHP_FUNCTION(imap_utf8_to_mutf7); +PHP_FUNCTION(imap_mutf7_to_utf8); PHP_FUNCTION(imap_mime_header_decode); PHP_FUNCTION(imap_thread); PHP_FUNCTION(imap_timeout); diff --git a/ext/imap/tests/imap_mutf7_to_utf8.phpt b/ext/imap/tests/imap_mutf7_to_utf8.phpt new file mode 100644 index 0000000000..30029c2950 --- /dev/null +++ b/ext/imap/tests/imap_mutf7_to_utf8.phpt @@ -0,0 +1,22 @@ +--TEST-- +imap_mutf7_to_utf8 +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(0) "" +string(1) "1" + +Warning: imap_mutf7_to_utf8() expects parameter 1 to be string, array given in %s on line %d +NULL +string(5) "täst" +Done diff --git a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt new file mode 100644 index 0000000000..f092e938a4 --- /dev/null +++ b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +imap_utf8_to_mutf7 +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +string(0) "" +string(1) "1" + +Warning: imap_utf8_to_mutf7() expects parameter 1 to be string, array given in %s on line %d +NULL +string(8) "t&AOQ-st" +Done