Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.0

Bug #13659 Mail parse error in special condition
Submitted: 2008-04-12 21:42 UTC Modified: 2010-02-08 08:20 UTC
From: mkrivan Assigned: doconnor
Status: Closed Package: Mail (version 1.1.14)
PHP Version: 5.2.5 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2008-04-12 21:42 UTC] mkrivan (Miklós Kriván)
Description: ------------ In special circumstances the parsing fail. If some partial text in string is the same, like mailbox name and comment, the parsing will be failed. I also have written a suggestion to solve the problem because I have found the suspicious place in the code. Thanks for your help. Test script: --------------- $address = '"Test Student" <test@mydomain.com> (test)'; $addresses = Mail_RFC822::parseAddressList( $address, 'anydomain.com', TRUE ); Expected result: ---------------- The result should give the parsed email into the following parts: person: Test Student mailbox: test host: mydomain.com comment: test Actual result: -------------- The suspicious code in RFC822.php // Catch any RFC822 comments and store them separately. $_mailbox = $mailbox; while (strlen(trim($_mailbox)) > 0) { $parts = explode('(', $_mailbox); $before_comment = $this->_splitCheck($parts, '('); if ($before_comment != $_mailbox) { // First char should be a (. $comment = substr(str_replace($before_comment, '', $_mailbox), 1); $parts = explode(')', $comment); $comment = $this->_splitCheck($parts, ')'); $comments[] = $comment; // +1 is for the trailing ) $_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1); } else { break; } } foreach ($comments as $comment) { $mailbox = str_replace("($comment)", '', $mailbox); } I would suggest this: // Catch any RFC822 comments and store them separately. $p = $q = false; do { $p = strrpos( $mailbox, '(' ); // last occured $q = strpos( $mailbox, ')', $p === false ? 0 : $p ); if( $p === false || $q === false ) break; $comments[] = substr( $mailbox, $p + 1, $q - $p -1 ); $mailbox = substr( $mailbox, 0, $p ).substr( $mailbox, $q + 1 ); // delete found comment from mailbox } while( true ); if( $p !== false || $q !== false ) { // there is an error $this->error = 'Invalid address spec. Unmatched quote or bracket ()'; return false; }

Comments

 [2008-04-17 09:04 UTC] doconnor (Daniel O'Connor)
Verified, actual result: PEAR_Error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => [message] => Invalid address spec. Unmatched quote or bracket (<>) [userinfo] => [backtrace] => Array ( [0] => Array ( [file] => G:\php\PEAR\PEAR.php [line] => 576 [function] => PEAR_Error [class] => PEAR_Error [type] => -> [args] => Array ( [0] => Invalid address spec. Unmatched quote or bracket (<>) [1] => [2] => 1 [3] => 1024 [4] => ) ) [1] => Array ( [file] => G:\php\PEAR\Mail\RFC822.php [line] => 198 [function] => raiseError [class] => PEAR [object] => Mail_RFC822 Object ( [address] => [default_domain] => anydomain.com [nestGroups] => 1 [validate] => 1 [addresses] => Array ( [0] => Array ( [address] => "Test Student" <test@mydomain.com> (test) [group] => ) ) [structure] => Array ( ) [error] => Invalid address spec. Unmatched quote or bracket (<>) [index] => 0 [num_groups] => 0 [mailRFC822] => 1 [limit] => ) [type] => -> [args] => Array ( [0] => Invalid address spec. Unmatched quote or bracket (<>) ) ) [2] => Array ( [file] => G:\php\PEAR\Mail\RFC822.php [line] => 166 [function] => parseAddressList [class] => Mail_RFC822 [object] => Mail_RFC822 Object ( [address] => [default_domain] => anydomain.com [nestGroups] => 1 [validate] => 1 [addresses] => Array ( [0] => Array ( [address] => "Test Student" <test@mydomain.com> (test) [group] => ) ) [structure] => Array ( ) [error] => Invalid address spec. Unmatched quote or bracket (<>) [index] => 0 [num_groups] => 0 [mailRFC822] => 1 [limit] => ) [type] => -> [args] => Array ( ) ) [3] => Array ( [file] => G:\bug-13659.php [line] => 6 [function] => parseAddressList [class] => Mail_RFC822 [type] => :: [args] => Array ( [0] => "Test Student" <test@mydomain.com> (test) [1] => anydomain.com [2] => 1 ) ) ) [callback] => )
 [2008-04-17 09:05 UTC] doconnor (Daniel O'Connor)
Miklos, I don't suppose you know how to make a patch with your changes and attach it to the ticket....?
 [2009-12-23 10:31 UTC] alec (Aleksander Machniak)
I've got a simpler patch: --- RFC822.php (wersja 292361) +++ RFC822.php (kopia robocza) @@ -635,8 +635,8 @@ $comment = $this->_splitCheck($parts, ')'); $comments[] = $comment; - // +1 is for the trailing ) - $_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1); + // +2 is for the brackets + $_mailbox = substr($_mailbox, strpos($_mailbox, '('.$comment)+strlen($comment)+2); } else { break; }
 [2010-01-08 10:11 UTC] alec (Aleksander Machniak)
 [2010-02-08 08:20 UTC] doconnor (Daniel O'Connor)
-Status: Verified +Status: Closed -Assigned To: +Assigned To: doconnor
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2010-02-08 08:20 UTC] doconnor (Daniel O'Connor)
Completed: At revision: 294749