php.net |  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:
Package:
Bug Type:
Summary:
From: shariefjamiel at gmail dot com
New email:
PHP Version: OS:

 

 [2019-11-15 16:00 UTC] shariefjamiel at gmail dot com
Description:
------------
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:
---------------
<?php

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

One line email results in same starting and ending position.
EOF;

 # 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
print_r($parts);;

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-14 09:11 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-09-14 09:11 UTC] cmb@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC