]> granicus.if.org Git - php/commitdiff
- [DOC] MFH: add imap_mutf7_to_utf8 and imap_utf8_to_mutf7
authorPierre Joye <pajoye@php.net>
Sat, 2 May 2009 17:59:46 +0000 (17:59 +0000)
committerPierre Joye <pajoye@php.net>
Sat, 2 May 2009 17:59:46 +0000 (17:59 +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 0114056c3a63ac8039853765c5383c895bc66fdb..8ad4ac1a4ab6157f27c92cc8a4f66555be158811 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)
@@ -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)
index b0c65419d04334cef3a89985df5d38f7dbe649a2..6f44029562a407efd11d763ba8651982613e0b83 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..30029c2
--- /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(""));
+var_dump(imap_mutf7_to_utf8(1));
+var_dump(imap_mutf7_to_utf8(array(1,2)));
+var_dump(imap_mutf7_to_utf8("t&AOQ-st"));
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..f092e93
--- /dev/null
@@ -0,0 +1,22 @@
+--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)));
+var_dump(imap_utf8_to_mutf7("täst"));
+
+echo "Done\n";
+?>
+--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