From e1fc7a15f8d8d7fdfc513edc48253ae3cad1b0d9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 8 Sep 2021 16:52:46 +0200 Subject: [PATCH] Fix #73110: Mails with unknown MIME version are treated as plain/text We are already liberal regarding a missing MIME version header, but not for versions other than 1.0. However, there are no other MIME versions, and it is somewhat unlikely that there ever will[1]. Thus, we treat an unknown MIME version like we treat a missing MIME version, i.e. we assume 1.0. [1] --- php_mailparse_mime.c | 6 +++++- tests/bug73110.phpt | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/bug73110.phpt diff --git a/php_mailparse_mime.c b/php_mailparse_mime.c index cd812a7..c6adcf3 100644 --- a/php_mailparse_mime.c +++ b/php_mailparse_mime.c @@ -656,8 +656,12 @@ static int php_mimepart_process_line(php_mimepart *workpart) --workpart->nbodylines; /* some broken mailers include the content-type header but not a mime-version header. + * some others may use a MIME version other than 1.0. * Let's relax and pretend they said they were mime 1.0 compatible */ - if (workpart->mime_version == NULL && workpart->content_type != NULL) { + if (!IS_MIME_1(workpart) && workpart->content_type != NULL) { + if (workpart->mime_version != NULL) { + efree(workpart->mime_version); + } workpart->mime_version = estrdup("1.0"); } diff --git a/tests/bug73110.phpt b/tests/bug73110.phpt new file mode 100644 index 0000000..0c896ab --- /dev/null +++ b/tests/bug73110.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #73110 (Mails with unknown MIME version are treated as plain/text) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(21) "multipart/alternative"