FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=13659&edit=1

ID: 13659
Updated by: daniel.oconnor@gmail.com
Reported By: miklos at krivan dot hu
Summary: Mail parse error in special condition
-Status: Verified
+Status: Closed
Type: Bug
Package: Mail
Operating System: Windows XP
Package Version: 1.1.14
PHP Version: 5.2.5
-Assigned To:
+Assigned To: doconnor
Roadmap Versions:
New Comment:

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




Previous Comments:
------------------------------------------------------------------------

[2010-01-08 10:11:00] alec

Added #patch bug:13659;patch:test_13659.phpt;revision:1262945460;.

------------------------------------------------------------------------

[2009-12-23 10:31:01] alec

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;
}

------------------------------------------------------------------------

[2008-04-17 10:05:27] doconnor

Miklos,
I don't suppose you know how to make a patch with your changes and
attach it to the ticket....?

------------------------------------------------------------------------

[2008-04-17 10:04:48] doconnor

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)
[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)
[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)
[1] => anydomain.com
[2] => 1
)

)

)

[callback] =>
)

------------------------------------------------------------------------

[2008-04-12 22:42:40] mkrivan

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)';
$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;
}

------------------------------------------------------------------------

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouppear-bugs @
categoriesphp
postedFeb 8, '10 at 8:22a
activeFeb 8, '10 at 8:22a
posts2
users1
websitepear.php.net

1 user in discussion

Daniel Oconnor: 2 posts

People

Translate

site design / logo © 2021 Grokbase