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
 [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

Pull Requests

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: Mon Dec 30 14:01:28 2024 UTC