ddeboer / imap

Object-oriented, fully tested PHP IMAP library
MIT License
888 stars 253 forks source link

Is there any support IMAP IDLE? #489

Open StasToken opened 3 years ago

StasToken commented 3 years ago

Actually, the question in the title is whether it is possible to receive mail in real time using IMAP IDLE?

Slamdunk commented 3 years ago

As far as I know, PHP doesn't provide any idle functionality, does it?

StasToken commented 3 years ago

Oh, really?

require 'vendor/autoload.php';

$imap = new \Noi\Util\Mail\ImapIdleClient('your.imap.host', 993);
$imap->login('username', 'password');
$imap->selectMailbox('INBOX');

while (!$imap->idle(300) instanceof \PEAR_Error) {
    $mails = $imap->search('UNSEEN');
    foreach ($imap->getMessages($mails) as $mail) {
        echo '==== New Message ====', "\n";
        echo $mail, "\n";
    }
}

I found this in another package, but I wonder if you have it :)

Slamdunk commented 3 years ago

That sounds like a sleep call, easy to implement by yourself

thesky2017 commented 3 years ago

Oh, really?

require 'vendor/autoload.php';

$imap = new \Noi\Util\Mail\ImapIdleClient('your.imap.host', 993);
$imap->login('username', 'password');
$imap->selectMailbox('INBOX');

while (!$imap->idle(300) instanceof \PEAR_Error) {
    $mails = $imap->search('UNSEEN');
    foreach ($imap->getMessages($mails) as $mail) {
        echo '==== New Message ====', "\n";
        echo $mail, "\n";
    }
}

I found this in another package, but I wonder if you have it :)

hello you can use the search method from 163 email?