@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @throws ConnectionFailedException |
90 | 90 | * @throws RuntimeException |
91 | 91 | */ |
92 | - protected function enableStartTls(){ |
|
92 | + protected function enableStartTls() { |
|
93 | 93 | $response = $this->requestAndResponse('STARTTLS'); |
94 | 94 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
95 | 95 | if (!$result) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | throw new RuntimeException('empty response'); |
113 | 113 | } |
114 | 114 | if ($this->debug) echo "<< ".$line."\n"; |
115 | - return $line . "\n"; |
|
115 | + return $line."\n"; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $stack = []; |
166 | 166 | |
167 | 167 | // replace any trailing <NL> including spaces with a single space |
168 | - $line = rtrim($line) . ' '; |
|
168 | + $line = rtrim($line).' '; |
|
169 | 169 | while (($pos = strpos($line, ' ')) !== false) { |
170 | 170 | $token = substr($line, 0, $pos); |
171 | 171 | if (!strlen($token)) { |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | if (strlen($token) > $chars) { |
196 | 196 | $line = substr($token, $chars); |
197 | 197 | $token = substr($token, 0, $chars); |
198 | - } else { |
|
198 | + }else { |
|
199 | 199 | $line .= $this->nextLine(); |
200 | 200 | } |
201 | 201 | $tokens[] = $token; |
202 | - $line = trim($line) . ' '; |
|
202 | + $line = trim($line).' '; |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $line = $this->nextTaggedLine($tag); // get next tag |
250 | 250 | if (!$dontParse) { |
251 | 251 | $tokens = $this->decodeLine($line); |
252 | - } else { |
|
252 | + }else { |
|
253 | 253 | $tokens = $line; |
254 | 254 | } |
255 | 255 | |
@@ -299,20 +299,20 @@ discard block |
||
299 | 299 | public function sendRequest(string $command, array $tokens = [], string &$tag = null) { |
300 | 300 | if (!$tag) { |
301 | 301 | $this->noun++; |
302 | - $tag = 'TAG' . $this->noun; |
|
302 | + $tag = 'TAG'.$this->noun; |
|
303 | 303 | } |
304 | 304 | |
305 | - $line = $tag . ' ' . $command; |
|
305 | + $line = $tag.' '.$command; |
|
306 | 306 | |
307 | 307 | foreach ($tokens as $token) { |
308 | 308 | if (is_array($token)) { |
309 | - $this->write($line . ' ' . $token[0]); |
|
309 | + $this->write($line.' '.$token[0]); |
|
310 | 310 | if (!$this->assumedNextLine('+ ')) { |
311 | 311 | throw new RuntimeException('failed to send literal string'); |
312 | 312 | } |
313 | 313 | $line = $token[1]; |
314 | - } else { |
|
315 | - $line .= ' ' . $token; |
|
314 | + }else { |
|
315 | + $line .= ' '.$token; |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | $this->write($line); |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | * @throws RuntimeException |
326 | 326 | */ |
327 | 327 | public function write(string $data) { |
328 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
328 | + if ($this->debug) echo ">> ".$data."\n"; |
|
329 | 329 | |
330 | - if (fwrite($this->stream, $data . "\r\n") === false) { |
|
330 | + if (fwrite($this->stream, $data."\r\n") === false) { |
|
331 | 331 | throw new RuntimeException('failed to write - connection closed?'); |
332 | 332 | } |
333 | 333 | } |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | public function escapeString($string) { |
358 | 358 | if (func_num_args() < 2) { |
359 | 359 | if (strpos($string, "\n") !== false) { |
360 | - return ['{' . strlen($string) . '}', $string]; |
|
361 | - } else { |
|
362 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
360 | + return ['{'.strlen($string).'}', $string]; |
|
361 | + }else { |
|
362 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | $result = []; |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | $result[] = $this->escapeList($v); |
386 | 386 | } |
387 | - return '(' . implode(' ', $result) . ')'; |
|
387 | + return '('.implode(' ', $result).')'; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -425,12 +425,12 @@ discard block |
||
425 | 425 | error_log("got an extra server challenge: $response"); |
426 | 426 | // respond with an empty response. |
427 | 427 | $this->sendRequest(''); |
428 | - } else { |
|
428 | + }else { |
|
429 | 429 | if (preg_match('/^NO /i', $response) || |
430 | 430 | preg_match('/^BAD /i', $response)) { |
431 | 431 | error_log("got failure response: $response"); |
432 | 432 | return false; |
433 | - } else if (preg_match("/^OK /i", $response)) { |
|
433 | + }else if (preg_match("/^OK /i", $response)) { |
|
434 | 434 | return true; |
435 | 435 | } |
436 | 436 | } |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | $result[strtolower($tokens[1])] = $tokens[0]; |
512 | 512 | break; |
513 | 513 | case '[UIDVALIDITY': |
514 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
514 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
515 | 515 | break; |
516 | 516 | case '[UIDNEXT': |
517 | - $result['uidnext'] = (int)$tokens[2]; |
|
517 | + $result['uidnext'] = (int) $tokens[2]; |
|
518 | 518 | break; |
519 | 519 | case '[NONEXISTENT]': |
520 | 520 | throw new RuntimeException("folder doesn't exist"); |
@@ -573,14 +573,14 @@ discard block |
||
573 | 573 | if (is_array($from)) { |
574 | 574 | $set = implode(',', $from); |
575 | 575 | } elseif ($to === null) { |
576 | - $set = (int)$from; |
|
576 | + $set = (int) $from; |
|
577 | 577 | } elseif ($to === INF) { |
578 | - $set = (int)$from . ':*'; |
|
579 | - } else { |
|
580 | - $set = (int)$from . ':' . (int)$to; |
|
578 | + $set = (int) $from.':*'; |
|
579 | + }else { |
|
580 | + $set = (int) $from.':'.(int) $to; |
|
581 | 581 | } |
582 | 582 | |
583 | - $items = (array)$items; |
|
583 | + $items = (array) $items; |
|
584 | 584 | $itemList = $this->escapeList($items); |
585 | 585 | |
586 | 586 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -597,9 +597,9 @@ discard block |
||
597 | 597 | $count = count($tokens[2]); |
598 | 598 | if ($tokens[2][$count - 2] == 'UID') { |
599 | 599 | $uidKey = $count - 1; |
600 | - } else if ($tokens[2][0] == 'UID') { |
|
600 | + }else if ($tokens[2][0] == 'UID') { |
|
601 | 601 | $uidKey = 1; |
602 | - } else { |
|
602 | + }else { |
|
603 | 603 | $found = array_search('UID', $tokens[2]); |
604 | 604 | if ($found === false || $found === -1) { |
605 | 605 | continue; |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | $data = $tokens[2][1]; |
622 | 622 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
623 | 623 | $data = $tokens[2][3]; |
624 | - } else { |
|
624 | + }else { |
|
625 | 625 | // maybe the server send an other field we didn't wanted |
626 | 626 | $count = count($tokens[2]); |
627 | 627 | // we start with 2, because 0 was already checked |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | break; |
634 | 634 | } |
635 | 635 | } |
636 | - } else { |
|
636 | + }else { |
|
637 | 637 | $data = []; |
638 | 638 | while (key($tokens[2]) !== null) { |
639 | 639 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | } |
651 | 651 | if ($uid) { |
652 | 652 | $result[$tokens[2][$uidKey]] = $data; |
653 | - }else{ |
|
653 | + }else { |
|
654 | 654 | $result[$tokens[0]] = $data; |
655 | 655 | } |
656 | 656 | } |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | $ids = $this->getUid(); |
752 | 752 | foreach ($ids as $k => $v) { |
753 | 753 | if ($v == $id) { |
754 | - return (int)$k; |
|
754 | + return (int) $k; |
|
755 | 755 | } |
756 | 756 | } |
757 | 757 | |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
809 | 809 | |
810 | 810 | if ($silent) { |
811 | - return (bool)$response; |
|
811 | + return (bool) $response; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | $result = []; |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | public function copyMessage(string $folder, $from, $to = null, $uid = IMAP::ST_UID): bool { |
862 | 862 | $set = $this->buildSet($from, $to); |
863 | 863 | $command = $this->buildUIDCommand("COPY", $uid); |
864 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
864 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | $set = $this->buildSet($from, $to); |
901 | 901 | $command = $this->buildUIDCommand("MOVE", $uid); |
902 | 902 | |
903 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
903 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -952,7 +952,7 @@ discard block |
||
952 | 952 | * @throws RuntimeException |
953 | 953 | */ |
954 | 954 | public function createFolder(string $folder): bool { |
955 | - return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
955 | + return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
956 | 956 | } |
957 | 957 | |
958 | 958 | /** |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | * @throws RuntimeException |
965 | 965 | */ |
966 | 966 | public function renameFolder(string $old, string $new): bool { |
967 | - return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
967 | + return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | /** |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | * @throws RuntimeException |
976 | 976 | */ |
977 | 977 | public function deleteFolder(string $folder): bool { |
978 | - return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
978 | + return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | * @throws RuntimeException |
987 | 987 | */ |
988 | 988 | public function subscribeFolder(string $folder): bool { |
989 | - return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
989 | + return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | /** |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | * @throws RuntimeException |
998 | 998 | */ |
999 | 999 | public function unsubscribeFolder(string $folder): bool { |
1000 | - return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
1000 | + return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | * @throws RuntimeException |
1008 | 1008 | */ |
1009 | 1009 | public function expunge(): bool { |
1010 | - return (bool)$this->requestAndResponse('EXPUNGE'); |
|
1010 | + return (bool) $this->requestAndResponse('EXPUNGE'); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | * @throws RuntimeException |
1018 | 1018 | */ |
1019 | 1019 | public function noop(): bool { |
1020 | - return (bool)$this->requestAndResponse('NOOP'); |
|
1020 | + return (bool) $this->requestAndResponse('NOOP'); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | $ids = []; |
1111 | 1111 | foreach ($uids as $msgn => $v) { |
1112 | 1112 | $id = $uid ? $v : $msgn; |
1113 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
1113 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
1114 | 1114 | $ids[] = $id; |
1115 | 1115 | } |
1116 | 1116 | } |
@@ -1124,14 +1124,14 @@ discard block |
||
1124 | 1124 | /** |
1125 | 1125 | * Enable the debug mode |
1126 | 1126 | */ |
1127 | - public function enableDebug(){ |
|
1127 | + public function enableDebug() { |
|
1128 | 1128 | $this->debug = true; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | /** |
1132 | 1132 | * Disable the debug mode |
1133 | 1133 | */ |
1134 | - public function disableDebug(){ |
|
1134 | + public function disableDebug() { |
|
1135 | 1135 | $this->debug = false; |
1136 | 1136 | } |
1137 | 1137 | |
@@ -1143,9 +1143,9 @@ discard block |
||
1143 | 1143 | * @return int|string |
1144 | 1144 | */ |
1145 | 1145 | public function buildSet($from, $to = null) { |
1146 | - $set = (int)$from; |
|
1146 | + $set = (int) $from; |
|
1147 | 1147 | if ($to !== null) { |
1148 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
1148 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
1149 | 1149 | } |
1150 | 1150 | return $set; |
1151 | 1151 | } |