pgrimaud / instagram-user-feed

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.
MIT License
882 stars 138 forks source link

TypeError: imap_delete(): Argument #2 ($message_nums) must be of type string, int given #349

Closed francisderit closed 11 months ago

francisderit commented 1 year ago

The 2nd argument in imap_delete() function in line 139 expects a string but int is given. Please fix by casting the type to string before passing.

public function getLastInstagramEmailContent(int $try = 1): string
{
    $resource  = @imap_open('{' . $this->getServer() . '/' . $this->getConnectionType() . '/ssl/novalidate-cert}INBOX', $this->getLogin(), $this->getPassword()) or die(implode(", ", @imap_errors()));

    if (!$resource) {
      throw new InstagramAuthException('Unable to open IMAP stream.');
    }

    $numberMax = imap_num_msg($resource);

    $foundCode = false;
    $code      = '';

    // $numberMax = 0 when mailbox is empty
    if ($numberMax > 0) {

        // check into the last 3 mails
        for ($i = $numberMax; $i > ($numberMax - 3); $i--) {
            $body = imap_body($resource, $i);
            $body = quoted_printable_decode($body);

            $headers = imap_headerinfo($resource, $i, 0);

            preg_match('/<font size="6">([0-9]{6})<\/font>/s', $body, $match);

            $isMailFromInstagram = false;

            // confirm instagram is the mail sender
            if (
                (property_exists($headers, 'fromaddress') &&
                    $headers->fromaddress === 'Instagram <security@mail.instagram.com>') ||
                (isset($headers->from[0]) && property_exists($headers->from[0], 'host') &&
                    $headers->from[0]->host === 'mail.instagram.com')
            ) {
                $isMailFromInstagram = true;
            }

            if ($isMailFromInstagram && isset($match[1])) {
                imap_delete($resource, $i);

                $foundCode = true;
                $code      = $match[1];
                break;
            }
        }
    }

    imap_close($resource);

    // retry imap check (3 times max)
    if (!$foundCode && $try <= 3) {
        sleep(6);
        $code = $this->getLastInstagramEmailContent($try + 1);
    }

    return $code;
}
deepvision7 commented 1 year ago

Same issue with PHP 8.1