]> granicus.if.org Git - php/commitdiff
- [DOC] add imap_mutf7_to_utf8 and imap_utf8_to_mutf7
authorPierre Joye <pajoye@php.net>
Sat, 2 May 2009 17:32:35 +0000 (17:32 +0000)
committerPierre Joye <pajoye@php.net>
Sat, 2 May 2009 17:32:35 +0000 (17:32 +0000)
ext/imap/php_imap.c
ext/imap/php_imap.h
ext/imap/tests/imap_mutf7_to_utf8.phpt [new file with mode: 0644]
ext/imap/tests/imap_utf8_to_mutf7_basic.phpt [new file with mode: 0644]

index 067e03accb772c338d9f8fdb8e39f600fc6d9f06..feadb0677435b35ae6e661772179bd01c71acb1d 100644 (file)
@@ -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)
@@ -2881,6 +2891,61 @@ 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 (mode == 0) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in, &in_len, UG(utf8_conv)) == FAILURE) {
+                       return;
+               }
+       
+               if (in_len < 1) {
+                       RETURN_EMPTY_STRING();
+               }
+
+               out = utf8_to_mutf7((unsigned char *) in);
+       } else {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &in, &in_len) == FAILURE) {
+                       return;
+               }
+
+               if (in_len < 1) {
+                       RETURN_EMPTY_UNICODE();
+               }
+
+               out = utf8_from_mutf7((unsigned char *) in);
+       }
+
+       if (out == NIL) {
+               RETURN_FALSE;
+               return;
+       }
+
+       if (mode == 0) {
+               RETURN_STRING((char *)out, 1);
+       } else {
+               RETURN_UTF8_STRING(out, ZSTR_DUPLICATE);
+       }
+}
+
+/* {{{ 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)
index 2f549254476cdd576352eb8870963c1f2e852f3a..8903cd4c6fb1ceb719ad387b159beb1bd3a4ccd0 100644 (file)
@@ -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 (file)
index 0000000..0b74700
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+imap_mutf7_to_utf8
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(imap_mutf7_to_utf8(b""));
+var_dump(imap_mutf7_to_utf8(1));
+var_dump(imap_mutf7_to_utf8(array(1,2)));
+var_dump(imap_mutf7_to_utf8(b"t&AOQ-st"));
+
+echo "Done\n";
+?>
+--EXPECTF--    
+unicode(0) ""
+unicode(1) "1"
+
+Warning: imap_mutf7_to_utf8() expects parameter 1 to be binary string, array given in %s on line %d
+NULL
+unicode(4) "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 (file)
index 0000000..3ec2c52
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+imap_utf8_to_mutf7
+--SKIPIF--
+<?php if (!extension_loaded("imap")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(imap_utf8_to_mutf7(""));
+var_dump(imap_utf8_to_mutf7(1));
+var_dump(imap_utf8_to_mutf7(array(1,2)));
+
+$test = 't' . chr(228) . 'st';
+var_dump(imap_utf8_to_mutf7(utf8_encode($test)));
+
+echo "Done\n";
+?>
+--EXPECTF--    
+string(0) ""
+string(1) "1"
+
+Warning: imap_utf8_to_mutf7() expects parameter 1 to be binary string, array given in %s on line %d
+NULL
+string(8) "t&AOQ-st"
+Done