javanile / php-imap2

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

Undefined variable section in Message class #5

Open Gizmo091 opened 2 years ago

Gizmo091 commented 2 years ago
Q A
javanile/php-imap2 version 0.1.7
PHP version 7.4.3
IMAP provider imap.gmail.com

Summary

Trying to use imap2_bodystruct, the function throw a notice for an undefined variable called section.

Current behavior

A call to imap2_bodystruct function trigger an "undefined variable" notice.

Notice: Undefined variable: section in .../vendor/javanile/php-imap2/src/Message.php on line 186

Indeed, the $section variable is never declared or instantiated.

 public static function bodyStruct($imap, $messageNum, $flags = 0)
    {
        if (is_a($imap, Connection::class)) {
            $client = $imap->getClient();
            #$client->setDebug(true);

            $messages = $client->fetch($imap->getMailboxName(), $messageNum, false, ['BODY['.$section.']']);

            if ($section) {
                return $messages[$messageNum]->bodypart[$section];
            }

            return $messages[$messageNum]->body;
        }

        return imap_fetchstructure($imap, $messageNum, $flags);
    }
francescobianco commented 1 year ago

Hi @Gizmo091 , could you please test our new version https://github.com/javanile/php-imap2/releases/tag/0.1.9

tnaumann-wecg commented 1 year ago

Hi @francescobianco, I can confirm that this bug still exists in v0.1.10. Like @Gizmo091 already noted, the variable $section is never initialized in the bodyStruct function. The Section is actually passed as $flag argument (which is unused in this function): https://github.com/javanile/php-imap2/blob/0.1.10/bootstrap.php#L945