]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #35669 (imap_mail_compose() crashes with
authorIlia Alshanetsky <iliaa@php.net>
Thu, 5 Jan 2006 00:50:20 +0000 (00:50 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 5 Jan 2006 00:50:20 +0000 (00:50 +0000)
multipart-multiboundary-email).

NEWS
ext/imap/php_imap.c

diff --git a/NEWS b/NEWS
index 6e7113d4d1ffdbc030e8928720765ea1dfc3ed04..78751309af44c1a98d2a5c5c1a6442e6d5f27bd1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP 4                                                                      NEWS
 - Fixed bug #35817 (unpack() does not decode odd number of hexadecimal values).
   (Ilia)
 - Fixed bug #35735 ($EGREP not defined in configure). (Jani)
+- Fixed bug #35669 (imap_mail_compose() crashes with 
+  multipart-multiboundary-email).  (Ilia)
 - Fixed bug #35655 (whitespace following end of heredoc is lost). (Ilia)
 - Fixed bug #35646 (%{mod_php_memory_usage}n is not reset after exit). 
   (vovik at getart dot ru, Tony)
index d3858f413a0afc0e0790e5c4f16bf06788c4a360..b1a9f9478457d25f19b2f3c133e922861d1daafe 100644 (file)
@@ -2784,9 +2784,10 @@ PHP_FUNCTION(imap_mail_compose)
        char *cookie = NIL;
        ENVELOPE *env;
        BODY *bod=NULL, *topbod=NULL;
-       PART *mypart=NULL, *toppart=NULL, *part;
+       PART *mypart=NULL, *part;
        PARAMETER *param, *disp_param = NULL, *custom_headers_param = NULL, *tmp_param = NULL;
        char tmp[8 * MAILTMPLEN], *mystring=NULL, *t=NULL, *tempstring=NULL;
+       int toppart = 0;
 
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &envelope, &body) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
@@ -2869,7 +2870,6 @@ PHP_FUNCTION(imap_mail_compose)
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "body parameter cannot be empty");
                RETURN_FALSE;
        }
-       zend_hash_get_current_key(Z_ARRVAL_PP(body), &key, &ind, 0); /* FIXME: is this necessary?  we're not using key/ind */
 
        if (Z_TYPE_PP(data) == IS_ARRAY) {
                bod = mail_newbody();
@@ -2969,23 +2969,28 @@ PHP_FUNCTION(imap_mail_compose)
        zend_hash_move_forward(Z_ARRVAL_PP(body));
 
        while (zend_hash_get_current_data(Z_ARRVAL_PP(body), (void **) &data) == SUCCESS) {
-               zend_hash_get_current_key(Z_ARRVAL_PP(body), &key, &ind, 0);  /* FIXME: Is this necessary?  We're not using key/ind */
                if (Z_TYPE_PP(data) == IS_ARRAY) {
+                       short type = -1;
+                       if (zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &pvalue)== SUCCESS) {
+                               convert_to_long_ex(pvalue);
+                               type = (short) Z_LVAL_PP(pvalue);
+                       }
+
                        if (!toppart) {
                                bod->nested.part = mail_newbody_part();
                                mypart = bod->nested.part;
-                               toppart = mypart;
-                               bod=&mypart->body;
+                               toppart = 1;
                        } else {
-                                mypart->next = mail_newbody_part();
-                                mypart = mypart->next;
-                                bod = &mypart->body;
+                               mypart->next = mail_newbody_part();
+                               mypart = mypart->next;
                        }
 
-                       if (zend_hash_find(Z_ARRVAL_PP(data), "type", sizeof("type"), (void **) &pvalue)== SUCCESS) {
-                               convert_to_long_ex(pvalue);
-                               bod->type = (short) Z_LVAL_PP(pvalue);
-                       }
+                       bod = &mypart->body;
+
+                       if (type != TYPEMULTIPART) {
+                               bod->type = type;
+                       }                       
+
                        if (zend_hash_find(Z_ARRVAL_PP(data), "encoding", sizeof("encoding"), (void **) &pvalue)== SUCCESS) {
                                convert_to_long_ex(pvalue);
                                bod->encoding = (short) Z_LVAL_PP(pvalue);
@@ -3082,12 +3087,6 @@ PHP_FUNCTION(imap_mail_compose)
                goto done;
        }
 
-       if (bod && bod->type == TYPEMULTIPART && (!bod->nested.part || !bod->nested.part->next)) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot generate multipart e-mail without components.");
-               RETVAL_FALSE;
-               goto done;
-       }
-
        rfc822_encode_body_7bit(env, topbod); 
        rfc822_header (tmp, env, topbod);