|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78820 mailparse incorrect body ending position
Submitted: 2019-11-15 16:00 UTC Modified: 2020-09-14 09:11 UTC
From: shariefjamiel at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: mailparse (PECL)
PHP Version: 7.2Git-2019-11-15 (Git) OS: ubuntu 18.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: shariefjamiel at gmail dot com
New email:
PHP Version: OS:


 [2019-11-15 16:00 UTC] shariefjamiel at gmail dot com
When parsing emails with one line the starting position and ending position of the body are the same.

if you add a second line with one character it jumps from 344 to 405, but then when you add a third line with a single character it shows end pos 407. So the issue seems to be with parsing the positions when there is just one line in body.

Test script:

$message = <<< EOF
MIME-Version: 1.0
Date: Tue, 12 Nov 2019 08:39:50 +0100
Message-ID: <>
Subject: Text Message
From: Jamiel Sharief <>
To: Jamiel Sharief <>
Cc:, Jamiel Sharief <>
Content-Type: text/plain; charset="UTF-8"

One line email results in same starting and ending position.

 # Create resource
 $resource = mailparse_msg_create();
 mailparse_msg_parse($resource, $message);
 $structure = mailparse_msg_get_structure($resource);

 $parts = [];
 foreach ($structure as $id) {
     $part = mailparse_msg_get_part($resource, $id);
     $parts[] = mailparse_msg_get_part_data($part);

# This is a bug with starting-pos-body

Expected result:
[starting-pos] => 0
[starting-pos-body] => 344
[ending-pos] => 404
ending-pos-body] => 404

Actual result:
[starting-pos] => 0
[starting-pos-body] => 344
[ending-pos] => 344
ending-pos-body] => 344


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-14 09:11 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-09-14 09:11 UTC]
The actual problem is that the last line of the mail is ignored,
if the mail does not end with a newline.  So this is a duplicate
of bug #75923.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Mar 05 20:01:24 2021 UTC