php-imap: idle function not returning any message when new mail comes
idle function not returning any message when new mail comes
Config:
'custom' => [
'host' => 'outlook.office365.com',
'port' => 993,
'encryption' => "ssl",
'validate_cert' => true,
'username' => 'email@my_domain.com',
'password' => get_access_token(),
'authentication' => "oauth",
],
// halper_functions.php
function get_access_token()
{
$tenantId = env("TENANT_ID");
$clientId = env("CLIENT_ID");
$clientSecret = env("CLIENT_SECRET");
$guzzle = new \GuzzleHttp\Client();
$url = 'https://login.microsoftonline.com/' . $tenantId . '/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'client_id' => $clientId,
'client_secret' => $clientSecret,
'scope' => 'https://outlook.office.com/IMAP.AccessAsUser.All',
'grant_type' => 'password',
'username' => 'email@my_domain.com',
'password' => 'password',
],
])->getBody()->getContents());
$accessToken = $token->access_token;
return $accessToken;
}
custom command:
public function handle()
{
$client = Client::account("custom");
try {
$client->connect();
} catch (ConnectionFailedException $e) {
Log::error($e->getMessage());
return 1;
}
try {
/** @var Folder $folder */
$folder = $client->getFolder("INBOX");
} catch (ConnectionFailedException $e) {
Log::error($e->getMessage());
return 1;
} catch (FolderFetchingException $e) {
Log::error($e->getMessage());
return 1;
}
try {
dump("listening...");
$folder->idle(function ($message) {
dump($message); // this doesn't run
}, 1200, true);
} catch (ConnectionFailedException $e) {
Log::error($e->getMessage());
return 1;
}
but when i get messages manually it works
Route::get("test", function () {
$client = Client::account("custom");
try {
$client->connect();
} catch (ConnectionFailedException $e) {
throw $e;
}
try {
/** @var Folder $folder */
$folder = $client->getFolder("INBOX");
} catch (ConnectionFailedException $e) {
throw $e;
} catch (FolderFetchingException $e) {
throw $e;
}
dump($client->getFolder("INBOX")->examine());
dump($client->getFolder("INBOX")->messages()->all()->limit(5)->get());
dd("done");
});

- OS: CentOs (prod), win 11 (dev)
- PHP: 8.1
- webklex/laravel-imap : 2.4
- Provider: Outlook
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 26 (11 by maintainers)
Commits related to this issue
- Idle command reworked and several issues fixed #170 #229 #237 #249 #258 — committed to Webklex/php-imap by Webklex 2 years ago
Hi @syedajmal1998 , nah you’ve did everything right 😃 Thanks for bringing this issue up 👍
At the moment I would like to wait a little bit to see if this “feature” gets fixed by outlook / Microsoft or if other providers behave the same. I don’t think they intended it to work this way. Also removing the “idle” check in general isn’t great. So for now I wont modify the idle methods. However you can use the snipped from above to build your own custom idle implementation.
I hope you’re having a great weekend 😃
Best regards,
and sorry if i said or did something wrong this was my first ever issued a bug in github 😃
here is the full one
<< * OK The Microsoft Exchange IMAP4 service is ready. [some long code]