@@ -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 | $uidKey = array_search('UID', $tokens[2]) + 1; |
| 604 | 604 | } |
| 605 | 605 | } |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | $data = $tokens[2][1]; |
| 617 | 617 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 618 | 618 | $data = $tokens[2][3]; |
| 619 | - } else { |
|
| 619 | + }else { |
|
| 620 | 620 | // maybe the server send an other field we didn't wanted |
| 621 | 621 | $count = count($tokens[2]); |
| 622 | 622 | // we start with 2, because 0 was already checked |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | break; |
| 629 | 629 | } |
| 630 | 630 | } |
| 631 | - } else { |
|
| 631 | + }else { |
|
| 632 | 632 | $data = []; |
| 633 | 633 | while (key($tokens[2]) !== null) { |
| 634 | 634 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | } |
| 646 | 646 | if ($uid) { |
| 647 | 647 | $result[$tokens[2][$uidKey]] = $data; |
| 648 | - }else{ |
|
| 648 | + }else { |
|
| 649 | 649 | $result[$tokens[0]] = $data; |
| 650 | 650 | } |
| 651 | 651 | } |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | $ids = $this->getUid(); |
| 747 | 747 | foreach ($ids as $k => $v) { |
| 748 | 748 | if ($v == $id) { |
| 749 | - return (int)$k; |
|
| 749 | + return (int) $k; |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
| 804 | 804 | |
| 805 | 805 | if ($silent) { |
| 806 | - return (bool)$response; |
|
| 806 | + return (bool) $response; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | $result = []; |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | public function copyMessage(string $folder, $from, $to = null, $uid = IMAP::ST_UID): bool { |
| 857 | 857 | $set = $this->buildSet($from, $to); |
| 858 | 858 | $command = $this->buildUIDCommand("COPY", $uid); |
| 859 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 859 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | $set = $this->buildSet($from, $to); |
| 896 | 896 | $command = $this->buildUIDCommand("MOVE", $uid); |
| 897 | 897 | |
| 898 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 898 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | * @throws RuntimeException |
| 948 | 948 | */ |
| 949 | 949 | public function createFolder(string $folder): bool { |
| 950 | - return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 950 | + return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | /** |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * @throws RuntimeException |
| 960 | 960 | */ |
| 961 | 961 | public function renameFolder(string $old, string $new): bool { |
| 962 | - return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 962 | + return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | * @throws RuntimeException |
| 971 | 971 | */ |
| 972 | 972 | public function deleteFolder(string $folder): bool { |
| 973 | - return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 973 | + return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | * @throws RuntimeException |
| 982 | 982 | */ |
| 983 | 983 | public function subscribeFolder(string $folder): bool { |
| 984 | - return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 984 | + return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | /** |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | * @throws RuntimeException |
| 993 | 993 | */ |
| 994 | 994 | public function unsubscribeFolder(string $folder): bool { |
| 995 | - return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 995 | + return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | /** |
@@ -1002,7 +1002,7 @@ discard block |
||
| 1002 | 1002 | * @throws RuntimeException |
| 1003 | 1003 | */ |
| 1004 | 1004 | public function expunge(): bool { |
| 1005 | - return (bool)$this->requestAndResponse('EXPUNGE'); |
|
| 1005 | + return (bool) $this->requestAndResponse('EXPUNGE'); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | * @throws RuntimeException |
| 1013 | 1013 | */ |
| 1014 | 1014 | public function noop(): bool { |
| 1015 | - return (bool)$this->requestAndResponse('NOOP'); |
|
| 1015 | + return (bool) $this->requestAndResponse('NOOP'); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | /** |
@@ -1105,7 +1105,7 @@ discard block |
||
| 1105 | 1105 | $ids = []; |
| 1106 | 1106 | foreach ($uids as $msgn => $v) { |
| 1107 | 1107 | $id = $uid ? $v : $msgn; |
| 1108 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1108 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1109 | 1109 | $ids[] = $id; |
| 1110 | 1110 | } |
| 1111 | 1111 | } |
@@ -1119,14 +1119,14 @@ discard block |
||
| 1119 | 1119 | /** |
| 1120 | 1120 | * Enable the debug mode |
| 1121 | 1121 | */ |
| 1122 | - public function enableDebug(){ |
|
| 1122 | + public function enableDebug() { |
|
| 1123 | 1123 | $this->debug = true; |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | /** |
| 1127 | 1127 | * Disable the debug mode |
| 1128 | 1128 | */ |
| 1129 | - public function disableDebug(){ |
|
| 1129 | + public function disableDebug() { |
|
| 1130 | 1130 | $this->debug = false; |
| 1131 | 1131 | } |
| 1132 | 1132 | |
@@ -1138,9 +1138,9 @@ discard block |
||
| 1138 | 1138 | * @return int|string |
| 1139 | 1139 | */ |
| 1140 | 1140 | public function buildSet($from, $to = null) { |
| 1141 | - $set = (int)$from; |
|
| 1141 | + $set = (int) $from; |
|
| 1142 | 1142 | if ($to !== null) { |
| 1143 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1143 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1144 | 1144 | } |
| 1145 | 1145 | return $set; |
| 1146 | 1146 | } |