php-i18n Digest 3 Jun 2006 11:45:38 -0000 Issue 328

Topics (messages 1004 through 1006):

Re: MBStrings question for in PEAR::Mail_Mime
        1004 by: Moriyoshi Koizumi
        1005 by: Cipriano Groenendal

Question on zend_make_printable
        1006 by: Marcus Boerger

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hi,

It'd not be a good idea to use mb_encode_mimeheader() as it is not quite
handy
when it comes to non-CJK encoding. Instead, you can write a more
standard-compliant
alternative with mb_substr() / base64_encode(), or possibly
iconv_mime_encode() that
provides far better functionality, available since php 5.0.

Regards,
Moriyoshi

Cipriano Groenendal wrote:
> Hello all,
>
> My name is Cipriano Groenendal, and I'm the maintainer for
> pear.php.net's Mail_Mime package. I'm trying to make the mails
> generated by this package compatible with non ISO-8869-1 charsets, but
> I ran into a small problem.
> The current code I'm using is not multi-bytecompatible, so I was
> wanting to use the mb_encode_mimeheader function to do this for me
> instead.
> However, upon reading the documentation, I noticed a lot of people had
> posted comments about the buggyness and instability of this function,
> so I was wondering if anyone could shed some light on this, and maybe
> know up to which version what bugs were there, so I can work around
> those and provide everyone with a good working version of Mail_Mime
> that can send in more then just singlebyte charsets :)
>
> Thanks in advance,
> Cipri
>

--- End Message ---
--- Begin Message ---
Hello,

It'd not be a good idea to use mb_encode_mimeheader() as it is not quite
handy
when it comes to non-CJK encoding. Instead, you can write a more
standard-compliant
alternative with mb_substr() / base64_encode(), or possibly
iconv_mime_encode() that
provides far better functionality, available since php 5.0.


Thanks for the info!
I've implemented the iconv_mime_encode function in the Mail_Mime package as you can see at http://cvs.php.net/viewcvs.cgi/pear/Mail_Mime/mime.php?annotate=1.56#l791 In that function, I only call the replacing function if the line to encode contains characters that should be encoded. This is currently done with a regexp but I fear it might not always find all the characters. The regexp I'm using searches for [\x80-\xFF]. This would catch any cyrilic, or otherwise, xtened single byte characters in charsets such as ISO-8859-XX. Would this work in etecting all multibte charaters, or do you know a better way to determine whether or not to encode a line ?

Thanks again,
Cipri
--- End Message ---
--- Begin Message ---
Hello Anrei,

  why don't we simply make zend_make_printable_zval() call on of
zend_make_unicode_zval/zend_make_string_zval() depending on ini
setting unicode_semantics, see attached patch.

-- 
Best regards,
 Marcus                          mailto:[EMAIL PROTECTED]
Index: Zend/zend.c
===================================================================
RCS file: /repository/ZendEngine2/zend.c,v
retrieving revision 1.359
diff -u -p -d -r1.359 zend.c
--- Zend/zend.c 3 Jun 2006 11:41:29 -0000       1.359
+++ Zend/zend.c 3 Jun 2006 11:43:06 -0000
@@ -348,79 +348,11 @@ ZEND_API void zend_make_string_zval(zval
 
 ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int 
*use_copy)
 {
-       UErrorCode temp = U_ZERO_ERROR;
-       TSRMLS_FETCH();
-
-       if (
-         /* UTODO: clean this up */
-           (Z_TYPE_P(expr) == IS_STRING &&
-           (!strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), 
&temp),
-                                
ucnv_getName(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &temp))))) {
-               *use_copy = 0;
-               return;
-       }
-       switch (Z_TYPE_P(expr)) {
-               case IS_NULL:
-                       Z_STRLEN_P(expr_copy) = 0;
-                       Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
-                       break;
-               case IS_BOOL:
-                       if (Z_LVAL_P(expr)) {
-                               Z_STRLEN_P(expr_copy) = 1;
-                               Z_STRVAL_P(expr_copy) = estrndup("1", 1);
-                       } else {
-                               Z_STRLEN_P(expr_copy) = 0;
-                               Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC();
-                       }
-                       break;
-               case IS_RESOURCE:
-                       Z_STRVAL_P(expr_copy) = (char *) 
emalloc(sizeof("Resource id #")-1 + MAX_LENGTH_OF_LONG);
-                       Z_STRLEN_P(expr_copy) = sprintf(Z_STRVAL_P(expr_copy), 
"Resource id #%ld", Z_LVAL_P(expr));
-                       break;
-               case IS_ARRAY:
-                       Z_STRLEN_P(expr_copy) = sizeof("Array")-1;
-                       Z_STRVAL_P(expr_copy) = estrndup("Array", 
Z_STRLEN_P(expr_copy));
-                       break;
-               case IS_OBJECT:
-                       if(Z_OBJ_HT_P(expr)->cast_object && 
Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == 
SUCCESS) {
-                               break;
-                       }
-                       if (Z_OBJ_HANDLER_P(expr, get)) {
-                               zval *z = Z_OBJ_HANDLER_P(expr, get)(expr 
TSRMLS_CC);
-                               
-                               z->refcount++;
-                               if(Z_TYPE_P(z) != IS_OBJECT) {
-                                       zend_make_printable_zval(z, expr_copy, 
use_copy);
-                                       if (*use_copy) {
-                                               zval_ptr_dtor(&z);
-                                       } else {
-                                               ZVAL_ZVAL(expr_copy, z, 0, 1);
-                                               *use_copy = 1;
-                                       }
-                                       return;
-                               }
-                               zval_ptr_dtor(&z);
-                       }
-                       zend_error(EG(exception) ? E_ERROR : 
E_RECOVERABLE_ERROR, "Object of class %v could not be converted to string", 
Z_OBJCE_P(expr)->name);
-                       ZVAL_EMPTY_STRING(expr_copy);
-                       break;
-               case IS_DOUBLE:
-                       *expr_copy = *expr;
-                       zval_copy_ctor(expr_copy);
-                       zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
-                       break;
-               default:
-                       *expr_copy = *expr;
-                       zval_copy_ctor(expr_copy);
-                       if (UG(unicode)) {
-                               convert_to_string_with_converter(expr_copy, 
ZEND_U_CONVERTER(UG(output_encoding_conv)));
-                       } else {
-                               convert_to_string(expr_copy);
-                       }
-                       break;
+       if (UG(unicode)) {
+               zend_make_unicode_zval(expr, expr_copy, use_copy);
+       } else {
+               zend_make_string_zval(expr, expr_copy, use_copy);
        }
-       Z_TYPE_P(expr_copy) = IS_STRING;
-       *use_copy = 1;
 }
 
 

--- End Message ---

Reply via email to