@@ -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) { |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function nextLine(): string { |
| 107 | 107 | $line = ""; |
| 108 | - while (($next_char = fread($this->stream, 1)) !== false && !in_array($next_char, ["","\n"])) { |
|
| 108 | + while (($next_char = fread($this->stream, 1)) !== false && !in_array($next_char, ["", "\n"])) { |
|
| 109 | 109 | $line .= $next_char; |
| 110 | 110 | } |
| 111 | 111 | if ($line === "" && $next_char === false) { |
| 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 | } |
@@ -508,16 +508,16 @@ discard block |
||
| 508 | 508 | switch ($tokens[1]) { |
| 509 | 509 | case 'EXISTS': |
| 510 | 510 | case 'RECENT': |
| 511 | - $result[strtolower($tokens[1])] = (int)$tokens[0]; |
|
| 511 | + $result[strtolower($tokens[1])] = (int) $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 '[UNSEEN': |
| 520 | - $result['unseen'] = (int)$tokens[2]; |
|
| 520 | + $result['unseen'] = (int) $tokens[2]; |
|
| 521 | 521 | break; |
| 522 | 522 | case '[NONEXISTENT]': |
| 523 | 523 | throw new RuntimeException("folder doesn't exist"); |
@@ -576,14 +576,14 @@ discard block |
||
| 576 | 576 | if (is_array($from)) { |
| 577 | 577 | $set = implode(',', $from); |
| 578 | 578 | } elseif ($to === null) { |
| 579 | - $set = (int)$from; |
|
| 579 | + $set = (int) $from; |
|
| 580 | 580 | } elseif ($to === INF) { |
| 581 | - $set = (int)$from . ':*'; |
|
| 582 | - } else { |
|
| 583 | - $set = (int)$from . ':' . (int)$to; |
|
| 581 | + $set = (int) $from.':*'; |
|
| 582 | + }else { |
|
| 583 | + $set = (int) $from.':'.(int) $to; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | - $items = (array)$items; |
|
| 586 | + $items = (array) $items; |
|
| 587 | 587 | $itemList = $this->escapeList($items); |
| 588 | 588 | |
| 589 | 589 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -600,9 +600,9 @@ discard block |
||
| 600 | 600 | $count = count($tokens[2]); |
| 601 | 601 | if ($tokens[2][$count - 2] == 'UID') { |
| 602 | 602 | $uidKey = $count - 1; |
| 603 | - } else if ($tokens[2][0] == 'UID') { |
|
| 603 | + }else if ($tokens[2][0] == 'UID') { |
|
| 604 | 604 | $uidKey = 1; |
| 605 | - } else { |
|
| 605 | + }else { |
|
| 606 | 606 | $found = array_search('UID', $tokens[2]); |
| 607 | 607 | if ($found === false || $found === -1) { |
| 608 | 608 | continue; |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | $data = $tokens[2][1]; |
| 624 | 624 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 625 | 625 | $data = $tokens[2][3]; |
| 626 | - } else { |
|
| 626 | + }else { |
|
| 627 | 627 | $expectedResponse = 0; |
| 628 | 628 | // maybe the server send an other field we didn't wanted |
| 629 | 629 | $count = count($tokens[2]); |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | continue; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - } else { |
|
| 643 | + }else { |
|
| 644 | 644 | $data = []; |
| 645 | 645 | while (key($tokens[2]) !== null) { |
| 646 | 646 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | } |
| 658 | 658 | if ($uid) { |
| 659 | 659 | $result[$tokens[2][$uidKey]] = $data; |
| 660 | - }else{ |
|
| 660 | + }else { |
|
| 661 | 661 | $result[$tokens[0]] = $data; |
| 662 | 662 | } |
| 663 | 663 | } |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | $ids = $this->getUid(); |
| 759 | 759 | foreach ($ids as $k => $v) { |
| 760 | 760 | if ($v == $id) { |
| 761 | - return (int)$k; |
|
| 761 | + return (int) $k; |
|
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
| 816 | 816 | |
| 817 | 817 | if ($silent) { |
| 818 | - return (bool)$response; |
|
| 818 | + return (bool) $response; |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | $result = []; |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | public function copyMessage(string $folder, $from, $to = null, $uid = IMAP::ST_UID): bool { |
| 869 | 869 | $set = $this->buildSet($from, $to); |
| 870 | 870 | $command = $this->buildUIDCommand("COPY", $uid); |
| 871 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 871 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | $set = $this->buildSet($from, $to); |
| 908 | 908 | $command = $this->buildUIDCommand("MOVE", $uid); |
| 909 | 909 | |
| 910 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 910 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * @throws RuntimeException |
| 960 | 960 | */ |
| 961 | 961 | public function createFolder(string $folder): bool { |
| 962 | - return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 962 | + return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -971,7 +971,7 @@ discard block |
||
| 971 | 971 | * @throws RuntimeException |
| 972 | 972 | */ |
| 973 | 973 | public function renameFolder(string $old, string $new): bool { |
| 974 | - return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 974 | + return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | /** |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | * @throws RuntimeException |
| 983 | 983 | */ |
| 984 | 984 | public function deleteFolder(string $folder): bool { |
| 985 | - return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 985 | + return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | /** |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | * @throws RuntimeException |
| 994 | 994 | */ |
| 995 | 995 | public function subscribeFolder(string $folder): bool { |
| 996 | - return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 996 | + return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | /** |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | * @throws RuntimeException |
| 1005 | 1005 | */ |
| 1006 | 1006 | public function unsubscribeFolder(string $folder): bool { |
| 1007 | - return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 1007 | + return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | * @throws RuntimeException |
| 1015 | 1015 | */ |
| 1016 | 1016 | public function expunge(): bool { |
| 1017 | - return (bool)$this->requestAndResponse('EXPUNGE'); |
|
| 1017 | + return (bool) $this->requestAndResponse('EXPUNGE'); |
|
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | /** |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | * @throws RuntimeException |
| 1025 | 1025 | */ |
| 1026 | 1026 | public function noop(): bool { |
| 1027 | - return (bool)$this->requestAndResponse('NOOP'); |
|
| 1027 | + return (bool) $this->requestAndResponse('NOOP'); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | /** |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | $ids = []; |
| 1118 | 1118 | foreach ($uids as $msgn => $v) { |
| 1119 | 1119 | $id = $uid ? $v : $msgn; |
| 1120 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1120 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1121 | 1121 | $ids[] = $id; |
| 1122 | 1122 | } |
| 1123 | 1123 | } |
@@ -1131,14 +1131,14 @@ discard block |
||
| 1131 | 1131 | /** |
| 1132 | 1132 | * Enable the debug mode |
| 1133 | 1133 | */ |
| 1134 | - public function enableDebug(){ |
|
| 1134 | + public function enableDebug() { |
|
| 1135 | 1135 | $this->debug = true; |
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | /** |
| 1139 | 1139 | * Disable the debug mode |
| 1140 | 1140 | */ |
| 1141 | - public function disableDebug(){ |
|
| 1141 | + public function disableDebug() { |
|
| 1142 | 1142 | $this->debug = false; |
| 1143 | 1143 | } |
| 1144 | 1144 | |
@@ -1150,9 +1150,9 @@ discard block |
||
| 1150 | 1150 | * @return int|string |
| 1151 | 1151 | */ |
| 1152 | 1152 | public function buildSet($from, $to = null) { |
| 1153 | - $set = (int)$from; |
|
| 1153 | + $set = (int) $from; |
|
| 1154 | 1154 | if ($to !== null) { |
| 1155 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1155 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | return $set; |
| 1158 | 1158 | } |