@@ -335,17 +335,17 @@ public function readResponse(Response $response, string $tag, bool $parse = true
335
335
*/
336
336
public function sendRequest (string $ command , array $ tokens = [], ?string &$ tag = null ): Response
337
337
{
338
- $ imapCommand = new ImapCommand ($ command , $ tokens );
338
+ $ command = new ImapCommand ($ command , $ tokens );
339
339
340
340
if (! $ tag ) {
341
341
$ this ->sequence ++;
342
342
343
343
$ tag = 'TAG ' .$ this ->sequence ;
344
344
}
345
345
346
- $ imapCommand ->setTag ($ tag );
346
+ $ command ->setTag ($ tag );
347
347
348
- return $ this ->sendCommand ($ imapCommand );
348
+ return $ this ->sendCommand ($ command );
349
349
}
350
350
351
351
/**
@@ -976,14 +976,17 @@ public function idle(): void
976
976
while (true ) {
977
977
$ line = $ this ->nextLine ($ response );
978
978
979
+ // Server indicates it's ready for IDLE.
979
980
if (str_starts_with ($ line , '+ ' )) {
980
981
return ;
981
982
}
982
983
983
- if (preg_match ('/^\* OK/i ' , $ line ) || preg_match ('/^TAG\d+ OK/i ' , $ line )) {
984
+ // Typical untagged or tagged "OK" lines.
985
+ if (preg_match ('/^\* /i ' , $ line ) || preg_match ('/^TAG\d+ OK/i ' , $ line )) {
984
986
continue ;
985
987
}
986
988
989
+ // Unexpected response.
987
990
throw new RuntimeException ('Idle failed. Unexpected response: ' .trim ($ line ));
988
991
}
989
992
}
@@ -997,8 +1000,21 @@ public function done(): void
997
1000
998
1001
$ this ->write ($ response , 'DONE ' );
999
1002
1000
- if (! $ this ->assumedNextTaggedLine ($ response , 'OK ' , $ tags )) {
1001
- throw new RuntimeException ('Done failed ' );
1003
+ while (true ) {
1004
+ $ line = $ this ->nextLine ($ response );
1005
+
1006
+ // Typical tagged "OK" line.
1007
+ if (preg_match ('/^TAG\d+ OK/i ' , $ line )) {
1008
+ break ;
1009
+ }
1010
+
1011
+ // Handle untagged notifications (e.g. "* 4 EXISTS").
1012
+ if (preg_match ('/^\* /i ' , $ line )) {
1013
+ continue ;
1014
+ }
1015
+
1016
+ // Unexpected response.
1017
+ throw new RuntimeException ('Done failed. Unexpected response: ' .trim ($ line ));
1002
1018
}
1003
1019
}
1004
1020
@@ -1064,14 +1080,6 @@ public function setDebug(bool $enabled): void
1064
1080
$ this ->debug = $ enabled ;
1065
1081
}
1066
1082
1067
- /**
1068
- * Disable the debug mode.
1069
- */
1070
- public function disableDebug (): void
1071
- {
1072
- $ this ->debug = false ;
1073
- }
1074
-
1075
1083
/**
1076
1084
* Build a valid UID number set.
1077
1085
*/
0 commit comments