Skip to content

Commit c783495

Browse files
committed
Fixed bug #52681 (mb_send_mail() appends an extra MIME-Version header).
1 parent f9c6bb1 commit c783495

10 files changed

+47
-17
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
- Changed the $context parameter on copy() to actually have an effect. (Kalle)
1616
- Fixed possible crash in mssql_fetch_batch(). (Kalle)
1717

18+
- Fixed bug #52681 (mb_send_mail() appends an extra MIME-Version header).
19+
(Adam)
1820
- Fixed bug #52674 (FPM Status page returns inconsistent Content-Type headers).
1921
(fat)
2022
- Fixed bug #52654 (mysqli doesn't install headers with structures it uses).

ext/mbstring/mbstring.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -4044,7 +4044,7 @@ PHP_FUNCTION(mb_send_mail)
40444044
}
40454045

40464046
/* other headers */
4047-
#define PHP_MBSTR_MAIL_MIME_HEADER1 "Mime-Version: 1.0"
4047+
#define PHP_MBSTR_MAIL_MIME_HEADER1 "MIME-Version: 1.0"
40484048
#define PHP_MBSTR_MAIL_MIME_HEADER2 "Content-Type: text/plain"
40494049
#define PHP_MBSTR_MAIL_MIME_HEADER3 "; charset="
40504050
#define PHP_MBSTR_MAIL_MIME_HEADER4 "Content-Transfer-Encoding: "
@@ -4057,8 +4057,10 @@ PHP_FUNCTION(mb_send_mail)
40574057
}
40584058
}
40594059

4060-
mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER1, sizeof(PHP_MBSTR_MAIL_MIME_HEADER1) - 1);
4061-
mbfl_memory_device_strncat(&device, "\n", 1);
4060+
if (!zend_hash_exists(&ht_headers, "MIME-VERSION", sizeof("MIME-VERSION") - 1)) {
4061+
mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER1, sizeof(PHP_MBSTR_MAIL_MIME_HEADER1) - 1);
4062+
mbfl_memory_device_strncat(&device, "\n", 1);
4063+
}
40624064

40634065
if (!suppressed_hdrs.cnt_type) {
40644066
mbfl_memory_device_strncat(&device, PHP_MBSTR_MAIL_MIME_HEADER2, sizeof(PHP_MBSTR_MAIL_MIME_HEADER2) - 1);

ext/mbstring/tests/bug52861.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #52681 (mb_send_mail() appends an extra MIME-Version header)
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists("mb_send_mail") || !mb_language("neutral")) {
6+
die("skip mb_send_mail() not available");
7+
}
8+
?>
9+
--INI--
10+
sendmail_path=/bin/cat
11+
mail.add_x_header=off
12+
--FILE--
13+
<?php
14+
15+
$headers = 'MIME-Version: 2.0';
16+
17+
mb_send_mail($to, mb_language(), "test", $headers);
18+
?>
19+
--EXPECTF--
20+
21+
Subject: %s
22+
MIME-Version: 2.0
23+
Content-Type: text/plain; charset=%s
24+
Content-Transfer-Encoding: %s
25+
26+
%s

ext/mbstring/tests/mb_send_mail01.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if (mb_language("neutral")) {
2525
--EXPECTF--
2626
2727
Subject: %s
28-
Mime-Version: 1.0
28+
MIME-Version: 1.0
2929
Content-Type: text/plain; charset=%s
3030
Content-Transfer-Encoding: %s
3131

3232
%s
3333
3434
Subject: test neutral
35-
Mime-Version: 1.0
35+
MIME-Version: 1.0
3636
Content-Type: text/plain; charset=UTF-8
3737
Content-Transfer-Encoding: BASE64
3838

ext/mbstring/tests/mb_send_mail02.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if (mb_language("japanese")) {
2525
--EXPECTF--
2626
2727
Subject: %s
28-
Mime-Version: 1.0
28+
MIME-Version: 1.0
2929
Content-Type: text/plain; charset=%s
3030
Content-Transfer-Encoding: %s
3131

3232
%s
3333
3434
Subject: =?ISO-2022-JP?B?GyRCJUYlOSVIGyhCIEphcGFuZXNl?=
35-
Mime-Version: 1.0
35+
MIME-Version: 1.0
3636
Content-Type: text/plain; charset=ISO-2022-JP
3737
Content-Transfer-Encoding: 7bit
3838

ext/mbstring/tests/mb_send_mail03.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if (mb_language("english")) {
2525
--EXPECTF--
2626
2727
Subject: %s
28-
Mime-Version: 1.0
28+
MIME-Version: 1.0
2929
Content-Type: text/plain; charset=%s
3030
Content-Transfer-Encoding: %s
3131

3232
%s
3333
3434
Subject: test English
35-
Mime-Version: 1.0
35+
MIME-Version: 1.0
3636
Content-Type: text/plain; charset=%s-8859-1
3737
Content-Transfer-Encoding: 8bit
3838

ext/mbstring/tests/mb_send_mail04.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if (mb_language("german")) {
2525
--EXPECTF--
2626
2727
Subject: %s
28-
Mime-Version: 1.0
28+
MIME-Version: 1.0
2929
Content-Type: text/plain; charset=%s
3030
Content-Transfer-Encoding: %s
3131

3232
%s
3333
3434
Subject: =?ISO-8859-15?Q?Pr=FCfung=20German?=
35-
Mime-Version: 1.0
35+
MIME-Version: 1.0
3636
Content-Type: text/plain; charset=%s-8859-15
3737
Content-Transfer-Encoding: 8bit
3838

ext/mbstring/tests/mb_send_mail05.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ if (mb_language("simplified chinese")) {
2828
--EXPECTF--
2929
3030
Subject: %s
31-
Mime-Version: 1.0
31+
MIME-Version: 1.0
3232
Content-Type: text/plain; charset=%s
3333
Content-Transfer-Encoding: %s
3434

3535
%s
3636
3737
Subject: =?HZ-GB-2312?B?fnsyYlFpfn0gU2ltcGxpZmllZCBD?=
3838
=?HZ-GB-2312?B?aGluZXNl?=
39-
Mime-Version: 1.0
39+
MIME-Version: 1.0
4040
Content-Type: text/plain; charset=HZ-GB-2312
4141
Content-Transfer-Encoding: 7bit
4242

ext/mbstring/tests/mb_send_mail06.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ if (mb_language("traditional chinese")) {
2828
--EXPECTF--
2929
3030
Subject: %s
31-
Mime-Version: 1.0
31+
MIME-Version: 1.0
3232
Content-Type: text/plain; charset=%s
3333
Content-Transfer-Encoding: %s
3434

3535
%s
3636
3737
Subject: =?BIG5?B?tPrF5yBUcmFkaXRpb25hbCBDaGluZXNl?=
38-
Mime-Version: 1.0
38+
MIME-Version: 1.0
3939
Content-Type: text/plain; charset=BIG5
4040
Content-Transfer-Encoding: 8bit
4141

ext/mbstring/tests/mb_send_mail07.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ if (mb_language("korean")) {
2828
--EXPECTF--
2929
3030
Subject: %s
31-
Mime-Version: 1.0
31+
MIME-Version: 1.0
3232
Content-Type: text/plain; charset=%s
3333
Content-Transfer-Encoding: %s
3434

3535
%s
3636
3737
Subject: =?ISO-2022-KR?B?GyQpQw5FVz06Ri4PIEtvcmVhbg8=?=
38-
Mime-Version: 1.0
38+
MIME-Version: 1.0
3939
Content-Type: text/plain; charset=ISO-2022-KR
4040
Content-Transfer-Encoding: 7bit
4141

0 commit comments

Comments
 (0)