PHP Classes

Fix to solve the problem when local_part is null

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Fix to solve the problem when...  >  (Un) Subscribe thread alerts  
Subject:Fix to solve the problem when...
Summary:Fix for bug in php8.1 when local_part is null
Messages:4
Author:Josep Sanz Campderrós
Date:2024-11-04 10:00:49
 

  1. Fix to solve the problem when...   Reply   Report abuse  
Picture of Josep Sanz Campderrós Josep Sanz Campderrós - 2024-11-04 10:00:49
Fixed a bug in php8.1 in rfc822_addresses.php to solve the problem when local_part is null

Function ParseAddrSpec(&$p, &$addr_spec)
{
$addr_spec = null;
$v = $this->v;
$l = strlen($v);
$a = $p;
if(!$this->ParseQuotedString($a, $local_part))
return(0);
if(!IsSet($local_part))
{
if(!$this->ParseAtom($a, $local_part, 1))
return(0);
// BEGIN TO SOLVE THE PROBLEM WHEN LOCAL_PART IS NULL IN PHP8.1 BY SANZ
if(!IsSet($local_part))
return(1);
// END TO SOLVE THE PROBLEM WHEN LOCAL_PART IS NULL IN PHP8.1 BY SANZ
$local_part = trim($local_part);
}
if($a >= $l
|| strcmp($v[$a], '@'))
return(1);
++$a;
if(!$this->ParseAtom($a, $domain, 1))
return(0);
if(!IsSet($domain))
return(1);
$addr_spec = $local_part.'@'.trim($domain);
$p = $a;
return(1);
}

  2. Re: Fix to solve the problem when...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2024-11-04 12:22:04 - In reply to message 1 from Josep Sanz Campderrós
Hello Josep,

Great. Can you provide an example address that I can use to create a test to verify the issue?

  3. Re: Fix to solve the problem when...   Reply   Report abuse  
Picture of abc def abc def - 2025-04-07 00:19:47 - In reply to message 2 from Manuel Lemos
This should throw an error with all addresses.

In ParseAddressList() you have
$p = 0;
if(!$this->ParseAddress($p, $address))
In ParseAddrSpec(), this goes to this function
$a = $p;
if(!$this->ParseQuotedString($a, $local_part))
And in Function ParseQuotedString(&$p, &$quoted_string)
$quoted_string = null;
$s = $p;
if($s >= $l
|| strcmp($v[$s], '"'))
return(1);
Which will leave $local_part as NULL.
if(!IsSet($local_part))
{
$local_part = trim($local_part);
This will do trim(null) and fail.

  4. Re: Fix to solve the problem when...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2025-04-08 21:05:46 - In reply to message 3 from abc def
Great. Let me try to check that over the weekend.