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

Invalid argument supplied for foreach() ? #356

Closed
receperdogan opened this issue Oct 15, 2020 · 6 comments
Closed

Invalid argument supplied for foreach() ? #356

receperdogan opened this issue Oct 15, 2020 · 6 comments

Comments

@receperdogan
Copy link

receperdogan commented Oct 15, 2020

Hi,

A connection is successfully established with the server and i listed all unseen() messages.
But when i use all() argument it gives me error.

Webklex\PHPIMAP\Exceptions\GetMessagesFailedException
Invalid argument supplied for foreach()





Webklex\PHPIMAP\Query\Query::get
vendor/webklex/php-imap/src/Query/Query.php:224
-----------
......
                            break;
                        case 'list':
                            $message_key = $msglist;
                            break;
                        default:
                            $message_key = $message->getMessageId();
                            break;
                    }
                    $messages->put($message_key, $message);
                });
            }

            return $messages;
        } catch (\Exception $e) {
            throw new GetMessagesFailedException($e->getMessage(),0, $e);
        }
    }
-----------

How can i solve this ? leaved my code below.
Thanks

            ...
           $client->connect();
 
           $folder = $client->getFolder('INBOX');
           //$message = $folder->query()->unseen()->get();
           $message = $folder->query()->all()->get();

           dd($message);
@receperdogan
Copy link
Author

receperdogan commented Oct 15, 2020

#348 (comment)
Same problem, I cant get messages on IMAP MS Exchange.

I think i figure it.
For example i have one unseen mail no problem.
More than one unseen, more than one email it gives error.
Looks like a bug.

@receperdogan
Copy link
Author

/vendor/webklex/php-imap/src/Header.php:477)

In Header.php 477

foreach ($list as $item) {
                $address = (object) $item;

Should be:

if(is_array($list) && !empty($list)){
foreach ($list as $item) {
                $address = (object) $item;

Tested on Laravel 7.

@Webklex
Copy link
Owner

Webklex commented Oct 15, 2020

Hi @rerdogantr ,
thanks for your report. A patch has been applied :)

Bets regards,

@receperdogan
Copy link
Author

Hi @Webklex additional bug :)
/vendor/webklex/php-imap/src/PART.php:224)

In PART.php 224

 if (($pos = strpos($content_type, "/")) !== false){
            $this->subtype = substr($content_type, $pos + 1);
        }

Probably should be:

        if(is_array($content_type)){
            $con=$content_type[0];
        }else{
            $con=$content_type;
        }

        if (($pos = strpos($con, "/")) !== false){
            $this->subtype = substr($con, $pos + 1);
        }

@receperdogan
Copy link
Author

Last one:

/vendor/webklex/php-imap/src/PART.php:191)

In PART.php 191

$contentTypeArray = explode(';', $rawContentType);

Probably should be:

            if(is_array($rawContentType)){
                $con=$rawContentType[0];
            }else{
                $con=$rawContentType;
            }

            $contentTypeArray = explode(';', $con);

@Webklex
Copy link
Owner

Webklex commented Oct 16, 2020

Hi @rerdogantr ,
thanks for your report. A patch has been applied :)

Bets regards,

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

No branches or pull requests

2 participants