javanile / php-imap2

PHP IMAP with OAUTH2
https://php-imap2.javanile.org/
GNU General Public License v3.0
48 stars 28 forks source link

ImapClient::tokenizeResponse() causes NOTICE error when using custom error handler #47

Open scr34m opened 1 year ago

scr34m commented 1 year ago

The error suppression doesn't work, if you have a custom error handler, at this line while (@list($name, $value) = $this->tokenizeResponse($line, 2)) { so it generates NOTICE when tokenizeResponse returns an empty array, https://github.com/javanile/php-imap2/blob/main/src/Roundcube/ImapClient.php#L2497.

The generated notice message is the following /vendor/javanile/php-imap2/src/Roundcube/ImapClient.php:2497 Undefined offset: 0 and /vendor/javanile/php-imap2/src/Roundcube/ImapClient.php:2496 Undefined offset: 1

To test simply use $line with UID 69)\n so it will be parsed as

array(2) {
  [0]=>
  string(3) "UID"
  [1]=>
  string(2) "69"
}

then remaining content is only )\n which is resulting an empty array php array(0) { }

A better solution would be to check return value instead of error suppression.

while (true) {
    $ret = $this->tokenizeResponse($line, 2);
    if (empty($ret) {
        break;
    }
   list($name, $value) = $ret;
scr34m commented 1 year ago

Another suppressed error causing this message vendor/javanile/php-imap2/src/Roundcube/Charset.php:228 Undefined offset: 2 here https://github.com/javanile/php-imap2/blob/main/src/Roundcube/Charset.php#L228

else if (preg_match('/U[A-Z][A-Z](7|8|16|32)(BE|LE)*/', $str, $m)) {

If $str is simply UTF-8 then this generates a warning.