Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
francisderit opened this issue Dec 28, 2022 · 1 comment
Assignees
Labels
need-investigations Need investigations to classify

Comments

@francisderit
Copy link

francisderit commented Dec 28, 2022

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;
}
@francisderit francisderit added the need-investigations Need investigations to classify label Dec 28, 2022
@deepvision7
Copy link
Contributor

Same issue with PHP 8.1

deepvision7 pushed a commit to deepvision7/instagram-user-feed that referenced this issue Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-investigations Need investigations to classify
Projects
None yet
Development

No branches or pull requests

3 participants