@@ -111,7 +111,9 @@ discard block |
||
| 111 | 111 | if ($line === "") { |
| 112 | 112 | throw new RuntimeException('empty response'); |
| 113 | 113 | } |
| 114 | - if ($this->debug) echo "<< ".$line."\n"; |
|
| 114 | + if ($this->debug) { |
|
| 115 | + echo "<< ".$line."\n"; |
|
| 116 | + } |
|
| 115 | 117 | return $line . "\n"; |
| 116 | 118 | } |
| 117 | 119 | |
@@ -326,7 +328,9 @@ discard block |
||
| 326 | 328 | * @throws RuntimeException |
| 327 | 329 | */ |
| 328 | 330 | public function write(string $data) { |
| 329 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 331 | + if ($this->debug) { |
|
| 332 | + echo ">> ".$data ."\n"; |
|
| 333 | + } |
|
| 330 | 334 | |
| 331 | 335 | if (fwrite($this->stream, $data . "\r\n") === false) { |
| 332 | 336 | throw new RuntimeException('failed to write - connection closed?'); |
@@ -478,7 +482,9 @@ discard block |
||
| 478 | 482 | public function getCapabilities(): array { |
| 479 | 483 | $response = $this->requestAndResponse('CAPABILITY'); |
| 480 | 484 | |
| 481 | - if (!$response) return []; |
|
| 485 | + if (!$response) { |
|
| 486 | + return []; |
|
| 487 | + } |
|
| 482 | 488 | |
| 483 | 489 | $capabilities = []; |
| 484 | 490 | foreach ($response as $line) { |
@@ -638,13 +644,14 @@ discard block |
||
| 638 | 644 | // if we want only one message we can ignore everything else and just return |
| 639 | 645 | if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) { |
| 640 | 646 | // we still need to read all lines |
| 641 | - while (!$this->readLine($tokens, $tag)) |
|
| 642 | - |
|
| 647 | + while (!$this->readLine($tokens, $tag)) { |
|
| 648 | + |
|
| 643 | 649 | return $data; |
| 650 | + } |
|
| 644 | 651 | } |
| 645 | 652 | if ($uid) { |
| 646 | 653 | $result[$tokens[2][$uidKey]] = $data; |
| 647 | - }else{ |
|
| 654 | + } else{ |
|
| 648 | 655 | $result[$tokens[0]] = $data; |
| 649 | 656 | } |
| 650 | 657 | } |
@@ -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)) { |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | if (strlen($token) > $chars) { |
| 202 | 202 | $line = substr($token, $chars); |
| 203 | 203 | $token = substr($token, 0, $chars); |
| 204 | - } else { |
|
| 204 | + }else { |
|
| 205 | 205 | $line .= $this->nextLine(); |
| 206 | 206 | } |
| 207 | 207 | $tokens[] = $token; |
| 208 | - $line = trim($line) . ' '; |
|
| 208 | + $line = trim($line).' '; |
|
| 209 | 209 | continue; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $line = $this->nextTaggedLine($tag); // get next tag |
| 256 | 256 | if (!$dontParse) { |
| 257 | 257 | $tokens = $this->decodeLine($line); |
| 258 | - } else { |
|
| 258 | + }else { |
|
| 259 | 259 | $tokens = $line; |
| 260 | 260 | } |
| 261 | 261 | |
@@ -309,20 +309,20 @@ discard block |
||
| 309 | 309 | public function sendRequest(string $command, array $tokens = [], string &$tag = null) { |
| 310 | 310 | if (!$tag) { |
| 311 | 311 | $this->noun++; |
| 312 | - $tag = 'TAG' . $this->noun; |
|
| 312 | + $tag = 'TAG'.$this->noun; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - $line = $tag . ' ' . $command; |
|
| 315 | + $line = $tag.' '.$command; |
|
| 316 | 316 | |
| 317 | 317 | foreach ($tokens as $token) { |
| 318 | 318 | if (is_array($token)) { |
| 319 | - $this->write($line . ' ' . $token[0]); |
|
| 319 | + $this->write($line.' '.$token[0]); |
|
| 320 | 320 | if (!$this->assumedNextLine('+ ')) { |
| 321 | 321 | throw new RuntimeException('failed to send literal string'); |
| 322 | 322 | } |
| 323 | 323 | $line = $token[1]; |
| 324 | - } else { |
|
| 325 | - $line .= ' ' . $token; |
|
| 324 | + }else { |
|
| 325 | + $line .= ' '.$token; |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | $this->write($line); |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | * @throws RuntimeException |
| 336 | 336 | */ |
| 337 | 337 | public function write(string $data) { |
| 338 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 338 | + if ($this->debug) echo ">> ".$data."\n"; |
|
| 339 | 339 | |
| 340 | - if (fwrite($this->stream, $data . "\r\n") === false) { |
|
| 340 | + if (fwrite($this->stream, $data."\r\n") === false) { |
|
| 341 | 341 | throw new RuntimeException('failed to write - connection closed?'); |
| 342 | 342 | } |
| 343 | 343 | } |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | public function escapeString($string) { |
| 372 | 372 | if (func_num_args() < 2) { |
| 373 | 373 | if (str_contains($string, "\n")) { |
| 374 | - return ['{' . strlen($string) . '}', $string]; |
|
| 375 | - } else { |
|
| 376 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 374 | + return ['{'.strlen($string).'}', $string]; |
|
| 375 | + }else { |
|
| 376 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | $result = []; |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | } |
| 399 | 399 | $result[] = $this->escapeList($v); |
| 400 | 400 | } |
| 401 | - return '(' . implode(' ', $result) . ')'; |
|
| 401 | + return '('.implode(' ', $result).')'; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -444,12 +444,12 @@ discard block |
||
| 444 | 444 | error_log("got an extra server challenge: $response"); |
| 445 | 445 | // respond with an empty response. |
| 446 | 446 | $this->sendRequest(''); |
| 447 | - } else { |
|
| 447 | + }else { |
|
| 448 | 448 | if (preg_match('/^NO /i', $response) || |
| 449 | 449 | preg_match('/^BAD /i', $response)) { |
| 450 | 450 | error_log("got failure response: $response"); |
| 451 | 451 | return false; |
| 452 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 452 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 453 | 453 | return true; |
| 454 | 454 | } |
| 455 | 455 | } |
@@ -537,10 +537,10 @@ discard block |
||
| 537 | 537 | $result[strtolower($tokens[1])] = $tokens[0]; |
| 538 | 538 | break; |
| 539 | 539 | case '[UIDVALIDITY': |
| 540 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 540 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 541 | 541 | break; |
| 542 | 542 | case '[UIDNEXT': |
| 543 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 543 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 544 | 544 | break; |
| 545 | 545 | case '[NONEXISTENT]': |
| 546 | 546 | throw new RuntimeException("folder doesn't exist"); |
@@ -599,14 +599,14 @@ discard block |
||
| 599 | 599 | if (is_array($from)) { |
| 600 | 600 | $set = implode(',', $from); |
| 601 | 601 | } elseif ($to === null) { |
| 602 | - $set = (int)$from; |
|
| 602 | + $set = (int) $from; |
|
| 603 | 603 | } elseif ($to === INF) { |
| 604 | - $set = (int)$from . ':*'; |
|
| 605 | - } else { |
|
| 606 | - $set = (int)$from . ':' . (int)$to; |
|
| 604 | + $set = (int) $from.':*'; |
|
| 605 | + }else { |
|
| 606 | + $set = (int) $from.':'.(int) $to; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - $items = (array)$items; |
|
| 609 | + $items = (array) $items; |
|
| 610 | 610 | $itemList = $this->escapeList($items); |
| 611 | 611 | |
| 612 | 612 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | $count = count($tokens[2]); |
| 624 | 624 | if ($tokens[2][$count - 2] == 'UID') { |
| 625 | 625 | $uidKey = $count - 1; |
| 626 | - } else if ($tokens[2][0] == 'UID') { |
|
| 626 | + }else if ($tokens[2][0] == 'UID') { |
|
| 627 | 627 | $uidKey = 1; |
| 628 | - } else { |
|
| 628 | + }else { |
|
| 629 | 629 | $found = array_search('UID', $tokens[2]); |
| 630 | 630 | if ($found === false || $found === -1) { |
| 631 | 631 | continue; |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $data = $tokens[2][1]; |
| 648 | 648 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 649 | 649 | $data = $tokens[2][3]; |
| 650 | - } else { |
|
| 650 | + }else { |
|
| 651 | 651 | // maybe the server send an other field we didn't wanted |
| 652 | 652 | $count = count($tokens[2]); |
| 653 | 653 | // we start with 2, because 0 was already checked |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | break; |
| 660 | 660 | } |
| 661 | 661 | } |
| 662 | - } else { |
|
| 662 | + }else { |
|
| 663 | 663 | $data = []; |
| 664 | 664 | while (key($tokens[2]) !== null) { |
| 665 | 665 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | } |
| 677 | 677 | if ($uid) { |
| 678 | 678 | $result[$tokens[2][$uidKey]] = $data; |
| 679 | - }else{ |
|
| 679 | + }else { |
|
| 680 | 680 | $result[$tokens[0]] = $data; |
| 681 | 681 | } |
| 682 | 682 | } |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | $ids = $this->getUid(); |
| 778 | 778 | foreach ($ids as $k => $v) { |
| 779 | 779 | if ($v == $id) { |
| 780 | - return (int)$k; |
|
| 780 | + return (int) $k; |
|
| 781 | 781 | } |
| 782 | 782 | } |
| 783 | 783 | |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | */ |
| 1111 | 1111 | public function getQuota($username): array { |
| 1112 | 1112 | $command = "GETQUOTA"; |
| 1113 | - $params = ['"#user/' . $username . '"']; |
|
| 1113 | + $params = ['"#user/'.$username.'"']; |
|
| 1114 | 1114 | |
| 1115 | 1115 | return $this->requestAndResponse($command, $params); |
| 1116 | 1116 | } |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | $ids = []; |
| 1203 | 1203 | foreach ($uids as $msgn => $v) { |
| 1204 | 1204 | $id = $uid ? $v : $msgn; |
| 1205 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1205 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1206 | 1206 | $ids[] = $id; |
| 1207 | 1207 | } |
| 1208 | 1208 | } |
@@ -1216,14 +1216,14 @@ discard block |
||
| 1216 | 1216 | /** |
| 1217 | 1217 | * Enable the debug mode |
| 1218 | 1218 | */ |
| 1219 | - public function enableDebug(){ |
|
| 1219 | + public function enableDebug() { |
|
| 1220 | 1220 | $this->debug = true; |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | /** |
| 1224 | 1224 | * Disable the debug mode |
| 1225 | 1225 | */ |
| 1226 | - public function disableDebug(){ |
|
| 1226 | + public function disableDebug() { |
|
| 1227 | 1227 | $this->debug = false; |
| 1228 | 1228 | } |
| 1229 | 1229 | |
@@ -1235,9 +1235,9 @@ discard block |
||
| 1235 | 1235 | * @return int|string |
| 1236 | 1236 | */ |
| 1237 | 1237 | public function buildSet($from, $to = null) { |
| 1238 | - $set = (int)$from; |
|
| 1238 | + $set = (int) $from; |
|
| 1239 | 1239 | if ($to !== null) { |
| 1240 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1240 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1241 | 1241 | } |
| 1242 | 1242 | return $set; |
| 1243 | 1243 | } |