php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57431 can not support rfc2231
Submitted: 2006-12-14 22:04 UTC Modified: 2007-09-08 04:56 UTC
From: zhaoweikid at 163 dot com Assigned:
Status: Closed Package: mailparse (PECL)
PHP Version: 5.2.0 RC4 OS: redhat linux 9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zhaoweikid at 163 dot com
New email:
PHP Version: OS:

 

 [2006-12-14 22:04 UTC] zhaoweikid at 163 dot com
Description:
------------
not support rfc2231 mime parameter value.

Example: 
Content-Type: message/external-body; access-type=URL;
URL*0="ftp://";
URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"

is semantically identical to
                
Content-Type: message/external-body; access-type=URL;              URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"

mailparse can't parse this.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-26 20:46 UTC] zhaowei at eyou dot net
I fix this bug ...
patch php_mailparse_mime.c

--- php_mailparse_mime.c	Mon Feb 28 14:21:45 2005
+++ php_mailparse_mime.c.new	Fri Dec 15 10:57:16 2006
@@ -54,7 +54,11 @@
 {
 	struct php_mimeheader_with_attributes *attr;
 	int i, first_semi, next_semi, comments_before_semi, netscape_bug = 0;
-	
+    char *name_buf = NULL;
+    smart_str value_buf = {0};
+    int is_rfc2231_name = 0;
+    char *check_name;
+
 	attr = ecalloc(1, sizeof(struct php_mimeheader_with_attributes));
 
 	MAKE_STD_ZVAL(attr->attributes);
@@ -106,7 +110,7 @@
 
 				/* count those tokens; we expect "token = token" (3 tokens); if there are
 				 * more than that, then something is quite possibly wrong - Netscape Bug! */
-				if (next_semi <= toks->ntokens
+				if (next_semi < toks->ntokens
 						&& toks->tokens[next_semi].token != ';'
 						&& next_semi - first_semi - comments_before_semi > 3) {
 					next_semi = i + 1;
@@ -117,9 +121,56 @@
 						PHP_RFC822_RECOMBINE_STRTOLOWER|PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
 				value = php_rfc822_recombine_tokens(toks, i, next_semi - i,
 						PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
-			
-				add_assoc_string(attr->attributes, name, value, 0);
-				efree(name);
+	
+                /* support rfc2231 mime parameter value 
+                 *
+                 * Parameter Value Continuations:
+                 *
+                 * Content-Type: message/external-body; access-type=URL;
+                 * URL*0="ftp://";
+                 * URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
+                 * 
+                 * is semantically identical to
+                 *
+                 * Content-Type: message/external-body; access-type=URL;
+                 * URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
+                 * 
+                 * Parameter Value Character Set and Language Information: 
+                 *
+                 * Content-Type: application/x-stuff;
+                 * title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A
+                 *
+                 * Modify by Zhao Wei
+                 * E-mail: zhaowei@eyou.net
+                 */
+                check_name = name;
+                while (*check_name) {
+                    if (*check_name == '*')
+                        break;
+                    check_name++;
+                }
+                if (*check_name == '*') {
+                    *check_name = 0;
+                    if (NULL == name_buf)
+                        name_buf = name;
+                    else
+                        efree(name);
+                    smart_str_appends(&value_buf, value);
+                    efree(value);
+                    is_rfc2231_name = 1;
+                }
+                
+                if (1 == is_rfc2231_name) {
+                    if (*name != 0 && strcmp(name_buf, name) != 0) {
+                        add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
+                        efree(name_buf);
+                        smart_str_free(&value_buf);
+                        is_rfc2231_name = 0;
+                    }
+                } else {
+                    add_assoc_string(attr->attributes, name, value, 0);
+                    efree(name);
+                }
 			}
 		}
 		if (next_semi < toks->ntokens && !netscape_bug)
@@ -128,6 +179,13 @@
 		first_semi = next_semi;
 		netscape_bug = 0;
 	}
+    if (1 == is_rfc2231_name) {
+        add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
+        efree(name_buf);
+        smart_str_free(&value_buf);
+    }
+
+
 	return attr;
 }
 [2007-09-08 04:56 UTC] shire@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 11:01:29 2025 UTC