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

parseBody() & nextLine() - problem with double "\n" #293

Closed
jack-2729 opened this issue Oct 5, 2022 · 3 comments
Closed

parseBody() & nextLine() - problem with double "\n" #293

jack-2729 opened this issue Oct 5, 2022 · 3 comments

Comments

@jack-2729
Copy link

jack-2729 commented Oct 5, 2022

Describe the bug
When body is separeted from header with two or more "\n" the function nextLine() thows a RuntimeException with message 'empty response'

Code to Reproduce

        /** @var Webklex\PHPIMAP\ClientManager $cm */
        $client_manager = new ClientManager($options = []);

        /** @var \Webklex\PHPIMAP\Client $client */
        $client = $client_manager->make([
            'host' => "outlook.office365.com",
            'port' => 993,
            'encryption' => "ssl",
            'validate_cert' => true,
            'username' => "username",
            'password' => "access_token",
            'protocol' => 'imap',
            'authentication' => "oauth"
        ]);

        $client->connect();

        if (!isset($client) || !$client->isConnected()) {
            throw new \Exception("Cannot connect IMAP service");
        }

        $client->checkConnection();

        /** @var Webklex\PHPIMAP\Folder $folder*/
        $folder = $client->getFolderByName("INBOX");

        /** @var \Webklex\PHPIMAP\Message $message */
        $message = $folder->query()->getMessageByUid($uid = $uid);

Expected behavior
Function nextLine() read body despite it is seperated from header by two or more '\n'

Screenshots
Example of raw file

=?Windows-1252?Q?euHxzLy7ZFW/osqOmPOQn200R+dh7Np2oiEUYA=3D=3D?=


------=_NextPart_001_239A_273F714F.45965D0B

Possibile solution
I try this solution and for my problem works

    public function nextLine(): string {
        $line = "";
        while (($next_char = fread($this->stream, 1)) !== false && $next_char !== "\n") {
            $line .= $next_char;
        }
        if ($line === "" && $next_char !== "\n") {
            throw new RuntimeException('empty response');
        }
        if ($this->debug) echo "<< ".$line."\n";
        return $line . "\n";
    }

Desktop / Server :

  • OS: RockyLinux
  • PHP: 8.0
  • Version 4.0.2
  • Provider Gmail
@marcelmolenaar
Copy link

I experienced the same issue. Jack's solution works for me as well

Peter-Smith-Activ added a commit to Peter-Smith-Activ/php-imap that referenced this issue Oct 11, 2022
@Peter-Smith-Activ
Copy link

I'm having the same bug, and Jack's solution worked for me as well. Pull request #274 looks like it will address this - the proposed code there works for me too.

@Webklex
Copy link
Owner

Webklex commented Mar 16, 2023

Hi,
many thanks for your reports. Please update to v5.1 and give it another try.
If you are currently using an older version below v5.0, please read the breaking changes leading up to v5.1 before upgrading.

Best regards,

@Webklex Webklex closed this as completed Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants