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: -
From: shariefjamiel at gmail dot com Assigned:
Status: Open 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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
34 + 5 = ?
Subscribe to this entry?

 
 [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

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Feb 19 11:01:27 2020 UTC