@@ -98,14 +98,14 @@ public function connect(string $host, int $port = null): bool {
98
98
* Check if the current session is connected
99
99
*
100
100
* @return bool
101
+ * @throws ImapBadRequestException
101
102
*/
102
103
public function connected (): bool {
103
104
if ((bool )$ this ->stream ) {
104
105
try {
105
106
$ this ->requestAndResponse ('NOOP ' );
106
107
return true ;
107
- }
108
- catch (ImapServerErrorException |RuntimeException ) {
108
+ } catch (ImapServerErrorException |RuntimeException ) {
109
109
return false ;
110
110
}
111
111
}
@@ -120,7 +120,7 @@ public function connected(): bool {
120
120
* @throws ImapServerErrorException
121
121
* @throws RuntimeException
122
122
*/
123
- protected function enableStartTls () {
123
+ protected function enableStartTls (): void {
124
124
$ response = $ this ->requestAndResponse ('STARTTLS ' );
125
125
$ result = $ response ->successful () && stream_socket_enable_crypto ($ this ->stream , true , $ this ->getCryptoMethod ());
126
126
if (!$ result ) {
@@ -324,14 +324,33 @@ public function readResponse(Response $response, string $tag, bool $dontParse =
324
324
325
325
$ original = is_array ($ original ) ? $ original : [$ original ];
326
326
327
+
327
328
// last line has response code
328
329
if ($ tokens [0 ] == 'OK ' ) {
329
330
return $ lines ?: [true ];
330
331
} elseif ($ tokens [0 ] == 'NO ' || $ tokens [0 ] == 'BAD ' || $ tokens [0 ] == 'BYE ' ) {
331
- throw new ImapServerErrorException (implode ( "\n" , $ original ));
332
+ throw new ImapServerErrorException ($ this -> stringifyArray ( $ original ));
332
333
}
333
334
334
- throw new ImapBadRequestException (implode ("\n" , $ original ));
335
+ throw new ImapBadRequestException ($ this ->stringifyArray ($ original ));
336
+ }
337
+
338
+ /**
339
+ * Convert an array to a string
340
+ * @param array $arr array to stringify
341
+ *
342
+ * @return string stringified array
343
+ */
344
+ private function stringifyArray (array $ arr ): string {
345
+ $ string = "" ;
346
+ foreach ($ arr as $ value ) {
347
+ if (is_array ($ value )) {
348
+ $ string .= "( " . $ this ->stringifyArray ($ value ) . ") " ;
349
+ } else {
350
+ $ string .= $ value . " " ;
351
+ }
352
+ }
353
+ return $ string ;
335
354
}
336
355
337
356
/**
@@ -523,7 +542,7 @@ public function logout(): Response {
523
542
try {
524
543
$ result = $ this ->requestAndResponse ('LOGOUT ' , [], true );
525
544
fclose ($ this ->stream );
526
- } catch (\ Throwable ) {
545
+ } catch (Throwable ) {
527
546
}
528
547
529
548
$ this ->reset ();
@@ -572,7 +591,7 @@ public function examineOrSelect(string $command = 'EXAMINE', string $folder = 'I
572
591
573
592
$ result = [];
574
593
$ tokens = []; // define $tokens variable before first use
575
- while (!$ this ->readLine ($ response , $ tokens , $ tag, false )) {
594
+ while (!$ this ->readLine ($ response , $ tokens , $ tag )) {
576
595
if ($ tokens [0 ] == 'FLAGS ' ) {
577
596
array_shift ($ tokens );
578
597
$ result ['flags ' ] = $ tokens ;
@@ -645,7 +664,7 @@ public function examineFolder(string $folder = 'INBOX'): Response {
645
664
* @throws RuntimeException
646
665
*/
647
666
public function folderStatus (string $ folder = 'INBOX ' , $ arguments = ['MESSAGES ' , 'UNSEEN ' , 'RECENT ' , 'UIDNEXT ' , 'UIDVALIDITY ' ]): Response {
648
- $ response = $ this ->requestAndResponse ('STATUS ' , [$ this ->escapeString ($ folder ), $ this ->escapeList ($ arguments )], false );
667
+ $ response = $ this ->requestAndResponse ('STATUS ' , [$ this ->escapeString ($ folder ), $ this ->escapeList ($ arguments )]);
649
668
$ data = $ response ->validatedData ();
650
669
651
670
if (!isset ($ data [0 ]) || !isset ($ data [0 ][2 ])) {
@@ -654,7 +673,7 @@ public function folderStatus(string $folder = 'INBOX', $arguments = ['MESSAGES',
654
673
655
674
$ result = [];
656
675
$ key = null ;
657
- foreach ($ data [0 ][2 ] as $ value ) {
676
+ foreach ($ data [0 ][2 ] as $ value ) {
658
677
if ($ key === null ) {
659
678
$ key = $ value ;
660
679
} else {
@@ -1245,7 +1264,7 @@ public function getQuotaRoot(string $quota_root = 'INBOX'): Response {
1245
1264
*
1246
1265
* @throws RuntimeException
1247
1266
*/
1248
- public function idle () {
1267
+ public function idle (): void {
1249
1268
$ response = $ this ->sendRequest ("IDLE " );
1250
1269
if (!$ this ->assumedNextLine ($ response , '+ ' )) {
1251
1270
throw new RuntimeException ('idle failed ' );
0 commit comments