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

Array to string conversion on $folder_->messages()->all()->setFetchOrderDesc()->get(); #520

Open
Pascal76 opened this issue Sep 26, 2024 · 5 comments

Comments

@Pascal76
Copy link

Pascal76 commented Sep 26, 2024

When doing :
$messages = $folder_->messages()->all()->setFetchOrderDesc()->get();

I sometimes get this error :

[26-Sep-2024 10:40:13 Europe/Paris] PHP Warning: Array to string conversion in /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php on line 707
[26-Sep-2024 10:40:13 Europe/Paris] PHP Stack trace:
[26-Sep-2024 10:40:13 Europe/Paris] PHP 1. {main}() /apache_sites/jbm/new_msg_retrieve_new_msg_php-imap.php:0
[26-Sep-2024 10:40:13 Europe/Paris] PHP 2. Webklex\PHPIMAP\Query\Query->get() /apache_sites/jbm/new_msg_retrieve_new_msg_php-imap.php:491
[26-Sep-2024 10:40:13 Europe/Paris] PHP 3. Webklex\PHPIMAP\Query\Query->curate_messages($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:380
[26-Sep-2024 10:40:13 Europe/Paris] PHP 4. Webklex\PHPIMAP\Query\Query->populate($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:316
[26-Sep-2024 10:40:13 Europe/Paris] PHP 5. Webklex\PHPIMAP\Query\Query->fetch($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:347
[26-Sep-2024 10:40:13 Europe/Paris] PHP 6. Webklex\PHPIMAP\Connection\Protocols\ImapProtocol->flags($uids = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]], $uid = 1) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:241
[26-Sep-2024 10:40:13 Europe/Paris] PHP 7. Webklex\PHPIMAP\Connection\Protocols\ImapProtocol->fetch($items = [0 => 'FLAGS'], $from = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]], $to = NULL, $uid = 1) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php:841
[26-Sep-2024 10:40:13 Europe/Paris] PHP 8. implode($separator = ',', $array = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]]) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php:707

@Webklex
Copy link
Owner

Webklex commented Jan 17, 2025

Hi @Pascal76 ,
many thanks for your report. Are you still able to reproduce this with the latest release? If that's the case, please provide some more information as well as the latest stack trace and reopen this ticket :)

Best regards & happy coding,

@Webklex Webklex closed this as completed Jan 17, 2025
@Pascal76
Copy link
Author

waiting for the post 6.0 build, because you added some new changes.
Will it be out today ?

@Ruud-Gerrits
Copy link

Ruud-Gerrits commented Jan 27, 2025

This exception is thrown when the flags, headers, sizes or content method on the ImapProtocol.php is called with the $uids as an empty array. Because the fetch method checks if the $from is an array and filled with at least one item, the check fails and causes an Array to String conversion.

Image

Still happens on version 6.1.0

@Webklex Webklex reopened this Jan 28, 2025
@Webklex
Copy link
Owner

Webklex commented Jan 28, 2025

Hi @Ruud-Gerrits ,
many thanks for the information. Any idea how I could replicate this issue and or how this could be tested and verified? :)

Best regards & happy coding,

@toshderv
Copy link

toshderv commented Feb 3, 2025

Hi @Webklex.

Any idea how I could replicate this issue and or how this could be tested and verified? :)

For example, when working with pagination.

/**
 * @var \Webklex\PHPIMAP\Client $client
 * @var \Carbon\Carbon $date
 */
$client->getFolder('FOLDER_NAME')->messages()->since(date: $date)->limit(limit: 3, page: 2)->get();

When there are 0 or 1 letters on the second page. There are 3 or 4 emails in total.

If 0 (empty) on second page, then the error is:
\Webklex\PHPIMAP\Exceptions\GetMessagesFailedException (Undefined array key 0)
If 1 email on second page, then the error is:
\Webklex\PHPIMAP\Exceptions\GetMessagesFailedException (Array to string conversion)

php: 8.4.2/8.4.3
webklex/php-imap: 6.1.0

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