@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @throws ImapServerErrorException |
| 96 | 96 | * @throws RuntimeException |
| 97 | 97 | */ |
| 98 | - protected function enableStartTls(){ |
|
| 98 | + protected function enableStartTls() { |
|
| 99 | 99 | $response = $this->requestAndResponse('STARTTLS'); |
| 100 | 100 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
| 101 | 101 | if (!$result) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | throw new RuntimeException('empty response'); |
| 119 | 119 | } |
| 120 | 120 | if ($this->debug) echo "<< ".$line."\n"; |
| 121 | - return $line . "\n"; |
|
| 121 | + return $line."\n"; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $stack = []; |
| 172 | 172 | |
| 173 | 173 | // replace any trailing <NL> including spaces with a single space |
| 174 | - $line = rtrim($line) . ' '; |
|
| 174 | + $line = rtrim($line).' '; |
|
| 175 | 175 | while (($pos = strpos($line, ' ')) !== false) { |
| 176 | 176 | $token = substr($line, 0, $pos); |
| 177 | 177 | if (!strlen($token)) { |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | if (strlen($token) > $chars) { |
| 203 | 203 | $line = substr($token, $chars); |
| 204 | 204 | $token = substr($token, 0, $chars); |
| 205 | - } else { |
|
| 205 | + }else { |
|
| 206 | 206 | $line .= $this->nextLine(); |
| 207 | 207 | } |
| 208 | 208 | $tokens[] = $token; |
| 209 | - $line = trim($line) . ' '; |
|
| 209 | + $line = trim($line).' '; |
|
| 210 | 210 | continue; |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $line = $this->nextTaggedLine($tag); // get next tag |
| 257 | 257 | if (!$dontParse) { |
| 258 | 258 | $tokens = $this->decodeLine($line); |
| 259 | - } else { |
|
| 259 | + }else { |
|
| 260 | 260 | $tokens = $line; |
| 261 | 261 | } |
| 262 | 262 | |
@@ -310,20 +310,20 @@ discard block |
||
| 310 | 310 | public function sendRequest(string $command, array $tokens = [], string &$tag = null) { |
| 311 | 311 | if (!$tag) { |
| 312 | 312 | $this->noun++; |
| 313 | - $tag = 'TAG' . $this->noun; |
|
| 313 | + $tag = 'TAG'.$this->noun; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $line = $tag . ' ' . $command; |
|
| 316 | + $line = $tag.' '.$command; |
|
| 317 | 317 | |
| 318 | 318 | foreach ($tokens as $token) { |
| 319 | 319 | if (is_array($token)) { |
| 320 | - $this->write($line . ' ' . $token[0]); |
|
| 320 | + $this->write($line.' '.$token[0]); |
|
| 321 | 321 | if (!$this->assumedNextLine('+ ')) { |
| 322 | 322 | throw new RuntimeException('failed to send literal string'); |
| 323 | 323 | } |
| 324 | 324 | $line = $token[1]; |
| 325 | - } else { |
|
| 326 | - $line .= ' ' . $token; |
|
| 325 | + }else { |
|
| 326 | + $line .= ' '.$token; |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | $this->write($line); |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * @throws RuntimeException |
| 337 | 337 | */ |
| 338 | 338 | public function write(string $data) { |
| 339 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 339 | + if ($this->debug) echo ">> ".$data."\n"; |
|
| 340 | 340 | |
| 341 | - if (fwrite($this->stream, $data . "\r\n") === false) { |
|
| 341 | + if (fwrite($this->stream, $data."\r\n") === false) { |
|
| 342 | 342 | throw new RuntimeException('failed to write - connection closed?'); |
| 343 | 343 | } |
| 344 | 344 | } |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | public function escapeString($string) { |
| 373 | 373 | if (func_num_args() < 2) { |
| 374 | 374 | if (str_contains($string, "\n")) { |
| 375 | - return ['{' . strlen($string) . '}', $string]; |
|
| 376 | - } else { |
|
| 377 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 375 | + return ['{'.strlen($string).'}', $string]; |
|
| 376 | + }else { |
|
| 377 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | $result = []; |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | $result[] = $this->escapeList($v); |
| 401 | 401 | } |
| 402 | - return '(' . implode(' ', $result) . ')'; |
|
| 402 | + return '('.implode(' ', $result).')'; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -445,12 +445,12 @@ discard block |
||
| 445 | 445 | error_log("got an extra server challenge: $response"); |
| 446 | 446 | // respond with an empty response. |
| 447 | 447 | $this->sendRequest(''); |
| 448 | - } else { |
|
| 448 | + }else { |
|
| 449 | 449 | if (preg_match('/^NO /i', $response) || |
| 450 | 450 | preg_match('/^BAD /i', $response)) { |
| 451 | 451 | error_log("got failure response: $response"); |
| 452 | 452 | return false; |
| 453 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 453 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 454 | 454 | return true; |
| 455 | 455 | } |
| 456 | 456 | } |
@@ -535,16 +535,16 @@ discard block |
||
| 535 | 535 | switch ($tokens[1]) { |
| 536 | 536 | case 'EXISTS': |
| 537 | 537 | case 'RECENT': |
| 538 | - $result[strtolower($tokens[1])] = (int)$tokens[0]; |
|
| 538 | + $result[strtolower($tokens[1])] = (int) $tokens[0]; |
|
| 539 | 539 | break; |
| 540 | 540 | case '[UIDVALIDITY': |
| 541 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 541 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 542 | 542 | break; |
| 543 | 543 | case '[UIDNEXT': |
| 544 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 544 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 545 | 545 | break; |
| 546 | 546 | case '[UNSEEN': |
| 547 | - $result['unseen'] = (int)$tokens[2]; |
|
| 547 | + $result['unseen'] = (int) $tokens[2]; |
|
| 548 | 548 | break; |
| 549 | 549 | case '[NONEXISTENT]': |
| 550 | 550 | throw new RuntimeException("folder doesn't exist"); |
@@ -603,14 +603,14 @@ discard block |
||
| 603 | 603 | if (is_array($from)) { |
| 604 | 604 | $set = implode(',', $from); |
| 605 | 605 | } elseif ($to === null) { |
| 606 | - $set = (int)$from; |
|
| 606 | + $set = (int) $from; |
|
| 607 | 607 | } elseif ($to === INF) { |
| 608 | - $set = (int)$from . ':*'; |
|
| 609 | - } else { |
|
| 610 | - $set = (int)$from . ':' . (int)$to; |
|
| 608 | + $set = (int) $from.':*'; |
|
| 609 | + }else { |
|
| 610 | + $set = (int) $from.':'.(int) $to; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - $items = (array)$items; |
|
| 613 | + $items = (array) $items; |
|
| 614 | 614 | $itemList = $this->escapeList($items); |
| 615 | 615 | |
| 616 | 616 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -627,9 +627,9 @@ discard block |
||
| 627 | 627 | $count = count($tokens[2]); |
| 628 | 628 | if ($tokens[2][$count - 2] == 'UID') { |
| 629 | 629 | $uidKey = $count - 1; |
| 630 | - } else if ($tokens[2][0] == 'UID') { |
|
| 630 | + }else if ($tokens[2][0] == 'UID') { |
|
| 631 | 631 | $uidKey = 1; |
| 632 | - } else { |
|
| 632 | + }else { |
|
| 633 | 633 | $found = array_search('UID', $tokens[2]); |
| 634 | 634 | if ($found === false || $found === -1) { |
| 635 | 635 | continue; |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | $data = $tokens[2][1]; |
| 651 | 651 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 652 | 652 | $data = $tokens[2][3]; |
| 653 | - } else { |
|
| 653 | + }else { |
|
| 654 | 654 | $expectedResponse = 0; |
| 655 | 655 | // maybe the server send an other field we didn't wanted |
| 656 | 656 | $count = count($tokens[2]); |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | continue; |
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | - } else { |
|
| 670 | + }else { |
|
| 671 | 671 | $data = []; |
| 672 | 672 | while (key($tokens[2]) !== null) { |
| 673 | 673 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | if ($uid) { |
| 686 | 686 | $result[$tokens[2][$uidKey]] = $data; |
| 687 | - }else{ |
|
| 687 | + }else { |
|
| 688 | 688 | $result[$tokens[0]] = $data; |
| 689 | 689 | } |
| 690 | 690 | } |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | $ids = $this->getUid(); |
| 786 | 786 | foreach ($ids as $k => $v) { |
| 787 | 787 | if ($v == $id) { |
| 788 | - return (int)$k; |
|
| 788 | + return (int) $k; |
|
| 789 | 789 | } |
| 790 | 790 | } |
| 791 | 791 | |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | */ |
| 1119 | 1119 | public function getQuota($username): array { |
| 1120 | 1120 | $command = "GETQUOTA"; |
| 1121 | - $params = ['"#user/' . $username . '"']; |
|
| 1121 | + $params = ['"#user/'.$username.'"']; |
|
| 1122 | 1122 | |
| 1123 | 1123 | return $this->requestAndResponse($command, $params); |
| 1124 | 1124 | } |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | $ids = []; |
| 1211 | 1211 | foreach ($uids as $msgn => $v) { |
| 1212 | 1212 | $id = $uid ? $v : $msgn; |
| 1213 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1213 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1214 | 1214 | $ids[] = $id; |
| 1215 | 1215 | } |
| 1216 | 1216 | } |
@@ -1224,14 +1224,14 @@ discard block |
||
| 1224 | 1224 | /** |
| 1225 | 1225 | * Enable the debug mode |
| 1226 | 1226 | */ |
| 1227 | - public function enableDebug(){ |
|
| 1227 | + public function enableDebug() { |
|
| 1228 | 1228 | $this->debug = true; |
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
| 1232 | 1232 | * Disable the debug mode |
| 1233 | 1233 | */ |
| 1234 | - public function disableDebug(){ |
|
| 1234 | + public function disableDebug() { |
|
| 1235 | 1235 | $this->debug = false; |
| 1236 | 1236 | } |
| 1237 | 1237 | |
@@ -1243,9 +1243,9 @@ discard block |
||
| 1243 | 1243 | * @return int|string |
| 1244 | 1244 | */ |
| 1245 | 1245 | public function buildSet($from, $to = null) { |
| 1246 | - $set = (int)$from; |
|
| 1246 | + $set = (int) $from; |
|
| 1247 | 1247 | if ($to !== null) { |
| 1248 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1248 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | return $set; |
| 1251 | 1251 | } |
@@ -117,7 +117,9 @@ discard block |
||
| 117 | 117 | if ($line === "" && $next_char === false) { |
| 118 | 118 | throw new RuntimeException('empty response'); |
| 119 | 119 | } |
| 120 | - if ($this->debug) echo "<< ".$line."\n"; |
|
| 120 | + if ($this->debug) { |
|
| 121 | + echo "<< ".$line."\n"; |
|
| 122 | + } |
|
| 121 | 123 | return $line . "\n"; |
| 122 | 124 | } |
| 123 | 125 | |
@@ -336,7 +338,9 @@ discard block |
||
| 336 | 338 | * @throws RuntimeException |
| 337 | 339 | */ |
| 338 | 340 | public function write(string $data) { |
| 339 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 341 | + if ($this->debug) { |
|
| 342 | + echo ">> ".$data ."\n"; |
|
| 343 | + } |
|
| 340 | 344 | |
| 341 | 345 | if (fwrite($this->stream, $data . "\r\n") === false) { |
| 342 | 346 | throw new RuntimeException('failed to write - connection closed?'); |
@@ -504,7 +508,9 @@ discard block |
||
| 504 | 508 | public function getCapabilities(): array { |
| 505 | 509 | $response = $this->requestAndResponse('CAPABILITY'); |
| 506 | 510 | |
| 507 | - if (!$response) return []; |
|
| 511 | + if (!$response) { |
|
| 512 | + return []; |
|
| 513 | + } |
|
| 508 | 514 | |
| 509 | 515 | $capabilities = []; |
| 510 | 516 | foreach ($response as $line) { |
@@ -678,13 +684,14 @@ discard block |
||
| 678 | 684 | // if we want only one message we can ignore everything else and just return |
| 679 | 685 | if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) { |
| 680 | 686 | // we still need to read all lines |
| 681 | - while (!$this->readLine($tokens, $tag)) |
|
| 682 | - |
|
| 687 | + while (!$this->readLine($tokens, $tag)) { |
|
| 688 | + |
|
| 683 | 689 | return $data; |
| 690 | + } |
|
| 684 | 691 | } |
| 685 | 692 | if ($uid) { |
| 686 | 693 | $result[$tokens[2][$uidKey]] = $data; |
| 687 | - }else{ |
|
| 694 | + } else{ |
|
| 688 | 695 | $result[$tokens[0]] = $data; |
| 689 | 696 | } |
| 690 | 697 | } |