javanile / php-imap2

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

bug in Mime::decode_mime_string #39

Open gabriel-tandil opened 1 year ago

gabriel-tandil commented 1 year ago

in Mime.php an attempt is made to access an array in a position that does not exist.

            foreach ($matches as $idx => $m) {
 ....
 ....

                $tmp[] = $text;
                if ($next_match = $matches[$idx+1]) {

message: Undefined offset: 1 file: /var/www/html/ver2/vendor/javanile/php-imap2/src/Roundcube/Mime.php line: 210 trace:

#0 /var/www/html/ver2/vendor/javanile/php-imap2/src/Roundcube/Mime.php(210): yii\web\ErrorHandler->handleError('8', ''Undefined offs...', ''/var/www/html/...', '210', '['input' => '=?...') 
#1 /var/www/html/ver2/vendor/javanile/php-imap2/src/Roundcube/Mime.php(153): Javanile\Imap2\Roundcube\Mime::decode_mime_string(''=?iso-8859-1?Q...', 'NULL') 
#2 /var/www/html/ver2/vendor/javanile/php-imap2/src/Roundcube/MessageHeader.php(237): Javanile\Imap2\Roundcube\Mime::decode_header(''=?iso-8859-1?Q...', 'NULL') 
#3 /var/www/html/ver2/vendor/javanile/php-imap2/src/Message.php(341): Javanile\Imap2\Roundcube\MessageHeader->get(''to'', '???') 
#4 /var/www/html/ver2/vendor/javanile/php-imap2/bootstrap.php(1025): Javanile\Imap2\Message::fetchOverview('class Javanile\\...', '21315', '0') 
#5 /var/www/html/ver2/common/clasespropias/mails/ClienteMailImap2.php(297): ::imap2_fetch_overview('class Javanile\\...', '21315', '0') 
#6 /var/www/html/ver2/common/models/CuentasMail.php(678):
gabriel-tandil commented 1 year ago

I changed line 210 to add an isset and the error does not occur, although I did not analyze if the solution is correct in all cases. if (isset($matches[$idx+1]) && $next_match = $matches[$idx+1]) {

if you are ok with the solution, I will make a pull request.

gabriel-tandil commented 1 year ago

The fix I mentioned has been in use for two weeks in the production environment and we haven't received any bug reports, so I created a pull request for it to be added to the repository.