php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73110 Mails with unknown MIME version are treated as plain/text
Submitted: 2016-09-19 06:20 UTC Modified: 2021-09-08 14:57 UTC
From: jochem dot blok at fasterforward dot nl Assigned: cmb (profile)
Status: Closed Package: mailparse (PECL)
PHP Version: 5.6.26 OS: Ubuntu 14.04
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: jochem dot blok at fasterforward dot nl
New email:
PHP Version: OS:

 

 [2016-09-19 06:20 UTC] jochem dot blok at fasterforward dot nl
Description:
------------
We are trying to parse an e-mail with mailparse extension. The header Mime-Version is as follows: "Mime-Version: 1.0;", note the semicolon at the end. Due to this semicolon mailparse treats the mail as text/plain.

Test script:
---------------
$tekst = 'Mime-Version: 1.0;
Content-Type: multipart/Alternative; boundary="=====1473780076CSSSMTP_CLIENT=="

--=====1473780076CSSSMTP_CLIENT==
Content-Type: text/plain

Hello please pay attached invoice
--=====1473780076CSSSMTP_CLIENT==
Content-Type: text/html; charset=utf-8

Hello please pay attached invoice

--=====1473780076CSSSMTP_CLIENT==--';
$stream = fopen('php://memory', 'r+');
fwrite($stream, $tekst);
fseek($stream, 0);
$resource = mailparse_msg_create();
mailparse_msg_parse($resource, fread($stream, 10000));
$data = mailparse_msg_get_part_data(mailparse_msg_get_part($resource, 1));
print_r($data['content-type']);

Expected result:
----------------
multipart/alternative

Actual result:
--------------
text/plain

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-06 11:32 UTC] jochem dot blok at fasterforward dot nl
Any update regarding the open bugs in Mailparse? I found another but this very old bug is still not solved?
 [2021-09-02 11:52 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-09-02 11:52 UTC] cmb@php.net
I can confirm the broken behavior.  Either the parser should be
liberal and ignore that semicolon, or the parsing should fail.
However, if I remove the semicolon manually, I get several memory
leaks.  This should be addressed first; it might be related to bug
#74233.
 [2021-09-07 15:05 UTC] cmb@php.net
> However, if I remove the semicolon manually, I get several
> memory leaks.

That is caused by the fix for bug #73562, and can't be avoided;
otherwise there is a NULL pointer dereference.  I have documented
that mailparse_msg_free() should be called explicitly[1].  The
clean solution would require to convert the resource to an opaque
object.

[1] <https://github.com/php/doc-en/commit/f7ee3294054f619f354d22aca3c5cb7c92b69962>
 [2021-09-07 16:49 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-09-07 16:49 UTC] cmb@php.net
Back to the actual topic of this ticket.  The problem is that for
any unknown MIME version (i.e. everything except "1.0"), the
content-type and boundary are discarded[1].  However, that is a
doubtful decision, given that a *missing* MIME version is treated
like 1.0[2].  Especially considering that it is somewhat unlikely
that there ever will be another MIME version than 1.0[3], in my
opinion any given MIME version should be treated as 1.0.

[1] <https://github.com/php/pecl-mail-mailparse/blob/7fe7a0316f7bc0c9111d00a2c916d87b3db47d0f/php_mailparse_mime.c#L664-L666>
[2] <https://github.com/php/pecl-mail-mailparse/blob/7fe7a0316f7bc0c9111d00a2c916d87b3db47d0f/php_mailparse_mime.c#L658-L659>
[3] <https://www.networkworld.com/article/2199390/the-mime-guys--how-two-internet-gurus-changed-e-mail-forever.html>
 [2021-09-08 14:56 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #73110: Mails with unknown MIME version are treated as plain/text
On GitHub:  https://github.com/php/pecl-mail-mailparse/pull/18
Patch:      https://github.com/php/pecl-mail-mailparse/pull/18.patch
 [2021-09-08 14:57 UTC] cmb@php.net
-Summary: Mails with header mime-version which end with a semicolon gets treated as plain +Summary: Mails with unknown MIME version are treated as plain/text
 [2021-09-20 08:10 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/pecl-mail-mailparse/commit/dfb1fd9b8316e2c5f16c1d8b9d2a7da7faaa916d
Log: Fix #73110: Mails with unknown MIME version are treated as plain/text
 [2021-09-20 08:10 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC