|
| 1 | +<?php |
| 2 | + |
| 3 | +use DirectoryTree\ImapEngine\Connection\FakeStream; |
| 4 | +use DirectoryTree\ImapEngine\Connection\ImapConnection; |
| 5 | +use DirectoryTree\ImapEngine\Idle; |
| 6 | +use DirectoryTree\ImapEngine\Mailbox; |
| 7 | + |
| 8 | +test('idle', function () { |
| 9 | + $stream = new FakeStream; |
| 10 | + |
| 11 | + $stream->open(); |
| 12 | + |
| 13 | + $stream->feed([ |
| 14 | + // Initial connection |
| 15 | + '* OK IMAP4rev1 Service Ready', |
| 16 | + |
| 17 | + // Login response |
| 18 | + 'TAG1 OK Logged in', |
| 19 | + |
| 20 | + // Select folder response |
| 21 | + '* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $Forwarded)', |
| 22 | + '* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $Forwarded \*)] Flags permitted.', |
| 23 | + '* 3 EXISTS', |
| 24 | + '* 0 RECENT', |
| 25 | + '* OK [UIDVALIDITY 1707169026] UIDs valid', |
| 26 | + '* OK [UIDNEXT 626] Predicted next UID', |
| 27 | + '* OK [HIGHESTMODSEQ 4578] Highest', |
| 28 | + 'TAG2 OK [READ-WRITE] Select completed (0.002 + 0.000 + 0.001 secs).', |
| 29 | + |
| 30 | + // Idling response |
| 31 | + '+ idling', |
| 32 | + |
| 33 | + // New message arrival |
| 34 | + '* 24 EXISTS', |
| 35 | + '* 24 FETCH (FLAGS (\Seen) UID 12345)', |
| 36 | + |
| 37 | + // Logout |
| 38 | + 'TAG4 OK LOGOUT completed', |
| 39 | + ]); |
| 40 | + |
| 41 | + $mailbox = new Mailbox; |
| 42 | + |
| 43 | + $mailbox->connect(new ImapConnection($stream)); |
| 44 | + |
| 45 | + try { |
| 46 | + (new Idle($mailbox, 'INBOX', 10))->await( |
| 47 | + function ($msgn, $sequence) use (&$receivedMsgn, &$receivedSequence) { |
| 48 | + $this->assertEquals(24, $msgn); |
| 49 | + $this->assertEquals(1, $sequence); |
| 50 | + } |
| 51 | + ); |
| 52 | + } catch (Exception) { |
| 53 | + // Do nothing. |
| 54 | + } |
| 55 | +}); |
0 commit comments