@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @throws ConnectionFailedException |
| 89 | 89 | * @throws RuntimeException |
| 90 | 90 | */ |
| 91 | - protected function enableTls(){ |
|
| 91 | + protected function enableTls() { |
|
| 92 | 92 | $response = $this->requestAndResponse('STARTTLS'); |
| 93 | 93 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
| 94 | 94 | if (!$result) { |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $stack = []; |
| 151 | 151 | |
| 152 | 152 | // replace any trailing <NL> including spaces with a single space |
| 153 | - $line = rtrim($line) . ' '; |
|
| 153 | + $line = rtrim($line).' '; |
|
| 154 | 154 | while (($pos = strpos($line, ' ')) !== false) { |
| 155 | 155 | $token = substr($line, 0, $pos); |
| 156 | 156 | if (!strlen($token)) { |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | if (strlen($token) > $chars) { |
| 181 | 181 | $line = substr($token, $chars); |
| 182 | 182 | $token = substr($token, 0, $chars); |
| 183 | - } else { |
|
| 183 | + }else { |
|
| 184 | 184 | $line .= $this->nextLine(); |
| 185 | 185 | } |
| 186 | 186 | $tokens[] = $token; |
| 187 | - $line = trim($line) . ' '; |
|
| 187 | + $line = trim($line).' '; |
|
| 188 | 188 | continue; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | $line = $this->nextTaggedLine($tag); // get next tag |
| 235 | 235 | if (!$dontParse) { |
| 236 | 236 | $tokens = $this->decodeLine($line); |
| 237 | - } else { |
|
| 237 | + }else { |
|
| 238 | 238 | $tokens = $line; |
| 239 | 239 | } |
| 240 | 240 | if ($this->debug) echo "<< ".$line."\n"; |
@@ -284,27 +284,27 @@ discard block |
||
| 284 | 284 | public function sendRequest($command, $tokens = [], &$tag = null) { |
| 285 | 285 | if (!$tag) { |
| 286 | 286 | $this->noun++; |
| 287 | - $tag = 'TAG' . $this->noun; |
|
| 287 | + $tag = 'TAG'.$this->noun; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $line = $tag . ' ' . $command; |
|
| 290 | + $line = $tag.' '.$command; |
|
| 291 | 291 | |
| 292 | 292 | foreach ($tokens as $token) { |
| 293 | 293 | if (is_array($token)) { |
| 294 | - if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) { |
|
| 294 | + if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) { |
|
| 295 | 295 | throw new RuntimeException('failed to write - connection closed?'); |
| 296 | 296 | } |
| 297 | 297 | if (!$this->assumedNextLine('+ ')) { |
| 298 | 298 | throw new RuntimeException('failed to send literal string'); |
| 299 | 299 | } |
| 300 | 300 | $line = $token[1]; |
| 301 | - } else { |
|
| 302 | - $line .= ' ' . $token; |
|
| 301 | + }else { |
|
| 302 | + $line .= ' '.$token; |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | if ($this->debug) echo ">> ".$line."\n"; |
| 306 | 306 | |
| 307 | - if (fwrite($this->stream, $line . "\r\n") === false) { |
|
| 307 | + if (fwrite($this->stream, $line."\r\n") === false) { |
|
| 308 | 308 | throw new RuntimeException('failed to write - connection closed?'); |
| 309 | 309 | } |
| 310 | 310 | } |
@@ -334,9 +334,9 @@ discard block |
||
| 334 | 334 | public function escapeString($string) { |
| 335 | 335 | if (func_num_args() < 2) { |
| 336 | 336 | if (strpos($string, "\n") !== false) { |
| 337 | - return ['{' . strlen($string) . '}', $string]; |
|
| 338 | - } else { |
|
| 339 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 337 | + return ['{'.strlen($string).'}', $string]; |
|
| 338 | + }else { |
|
| 339 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | $result = []; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | $result[] = $this->escapeList($v); |
| 363 | 363 | } |
| 364 | - return '(' . implode(' ', $result) . ')'; |
|
| 364 | + return '('.implode(' ', $result).')'; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -401,12 +401,12 @@ discard block |
||
| 401 | 401 | error_log("got an extra server challenge: $response"); |
| 402 | 402 | // respond with an empty response. |
| 403 | 403 | $this->sendRequest(''); |
| 404 | - } else { |
|
| 404 | + }else { |
|
| 405 | 405 | if (preg_match('/^NO /i', $response) || |
| 406 | 406 | preg_match('/^BAD /i', $response)) { |
| 407 | 407 | error_log("got failure response: $response"); |
| 408 | 408 | return false; |
| 409 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 409 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 410 | 410 | return true; |
| 411 | 411 | } |
| 412 | 412 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | * |
| 440 | 440 | * @return bool |
| 441 | 441 | */ |
| 442 | - public function connected(){ |
|
| 442 | + public function connected() { |
|
| 443 | 443 | return (boolean) $this->stream; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -486,10 +486,10 @@ discard block |
||
| 486 | 486 | $result[strtolower($tokens[1])] = $tokens[0]; |
| 487 | 487 | break; |
| 488 | 488 | case '[UIDVALIDITY': |
| 489 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 489 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 490 | 490 | break; |
| 491 | 491 | case '[UIDNEXT': |
| 492 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 492 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 493 | 493 | break; |
| 494 | 494 | default: |
| 495 | 495 | // ignore |
@@ -543,17 +543,17 @@ discard block |
||
| 543 | 543 | if (is_array($from)) { |
| 544 | 544 | $set = implode(',', $from); |
| 545 | 545 | } elseif ($to === null) { |
| 546 | - $set = (int)$from; |
|
| 546 | + $set = (int) $from; |
|
| 547 | 547 | } elseif ($to === INF) { |
| 548 | - $set = (int)$from . ':*'; |
|
| 549 | - } else { |
|
| 550 | - $set = (int)$from . ':' . (int)$to; |
|
| 548 | + $set = (int) $from.':*'; |
|
| 549 | + }else { |
|
| 550 | + $set = (int) $from.':'.(int) $to; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - $items = (array)$items; |
|
| 553 | + $items = (array) $items; |
|
| 554 | 554 | $itemList = $this->escapeList($items); |
| 555 | 555 | |
| 556 | - $this->sendRequest(($uid ? 'UID ' : '') . 'FETCH', [$set, $itemList], $tag); |
|
| 556 | + $this->sendRequest(($uid ? 'UID ' : '').'FETCH', [$set, $itemList], $tag); |
|
| 557 | 557 | |
| 558 | 558 | $result = []; |
| 559 | 559 | $tokens = null; // define $tokens variable before first use |
@@ -568,9 +568,9 @@ discard block |
||
| 568 | 568 | $count = count($tokens[2]); |
| 569 | 569 | if ($tokens[2][$count - 2] == 'UID') { |
| 570 | 570 | $uidKey = $count - 1; |
| 571 | - } else if ($tokens[2][0] == 'UID') { |
|
| 571 | + }else if ($tokens[2][0] == 'UID') { |
|
| 572 | 572 | $uidKey = 1; |
| 573 | - } else { |
|
| 573 | + }else { |
|
| 574 | 574 | $uidKey = array_search('UID', $tokens[2]) + 1; |
| 575 | 575 | } |
| 576 | 576 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | $data = $tokens[2][1]; |
| 587 | 587 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 588 | 588 | $data = $tokens[2][3]; |
| 589 | - } else { |
|
| 589 | + }else { |
|
| 590 | 590 | // maybe the server send an other field we didn't wanted |
| 591 | 591 | $count = count($tokens[2]); |
| 592 | 592 | // we start with 2, because 0 was already checked |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | break; |
| 599 | 599 | } |
| 600 | 600 | } |
| 601 | - } else { |
|
| 601 | + }else { |
|
| 602 | 602 | $data = []; |
| 603 | 603 | while (key($tokens[2]) !== null) { |
| 604 | 604 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | } |
| 616 | 616 | if ($uid) { |
| 617 | 617 | $result[$tokens[2][$uidKey]] = $data; |
| 618 | - }else{ |
|
| 618 | + }else { |
|
| 619 | 619 | $result[$tokens[0]] = $data; |
| 620 | 620 | } |
| 621 | 621 | } |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | * @return array |
| 650 | 650 | * @throws RuntimeException |
| 651 | 651 | */ |
| 652 | - public function headers($uids, $rfc = "RFC822", $uid = false){ |
|
| 652 | + public function headers($uids, $rfc = "RFC822", $uid = false) { |
|
| 653 | 653 | return $this->fetch(["$rfc.HEADER"], $uids, null, $uid); |
| 654 | 654 | } |
| 655 | 655 | |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | * @return array |
| 662 | 662 | * @throws RuntimeException |
| 663 | 663 | */ |
| 664 | - public function flags($uids, $uid = false){ |
|
| 664 | + public function flags($uids, $uid = false) { |
|
| 665 | 665 | return $this->fetch(["FLAGS"], $uids, null, $uid); |
| 666 | 666 | } |
| 667 | 667 | |
@@ -748,23 +748,23 @@ discard block |
||
| 748 | 748 | public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) { |
| 749 | 749 | $item = 'FLAGS'; |
| 750 | 750 | if ($mode == '+' || $mode == '-') { |
| 751 | - $item = $mode . $item; |
|
| 751 | + $item = $mode.$item; |
|
| 752 | 752 | } |
| 753 | 753 | if ($silent) { |
| 754 | 754 | $item .= '.SILENT'; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | $flags = $this->escapeList($flags); |
| 758 | - $set = (int)$from; |
|
| 758 | + $set = (int) $from; |
|
| 759 | 759 | if ($to !== null) { |
| 760 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 760 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | $command = ($uid ? "UID " : "")."STORE"; |
| 764 | 764 | $result = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
| 765 | 765 | |
| 766 | 766 | if ($silent) { |
| 767 | - return (bool)$result; |
|
| 767 | + return (bool) $result; |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | $tokens = $result; |
@@ -815,9 +815,9 @@ discard block |
||
| 815 | 815 | * @throws RuntimeException |
| 816 | 816 | */ |
| 817 | 817 | public function copyMessage($folder, $from, $to = null, $uid = false) { |
| 818 | - $set = (int)$from; |
|
| 818 | + $set = (int) $from; |
|
| 819 | 819 | if ($to !== null) { |
| 820 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 820 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 821 | 821 | } |
| 822 | 822 | $command = ($uid ? "UID " : "")."COPY"; |
| 823 | 823 | |
@@ -855,9 +855,9 @@ discard block |
||
| 855 | 855 | * @throws RuntimeException |
| 856 | 856 | */ |
| 857 | 857 | public function moveMessage($folder, $from, $to = null, $uid = false) { |
| 858 | - $set = (int)$from; |
|
| 858 | + $set = (int) $from; |
|
| 859 | 859 | if ($to !== null) { |
| 860 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 860 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 861 | 861 | } |
| 862 | 862 | $command = ($uid ? "UID " : "")."MOVE"; |
| 863 | 863 | |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | $ids = []; |
| 1047 | 1047 | foreach ($uids as $msgn => $v) { |
| 1048 | 1048 | $id = $uid ? $v : $msgn; |
| 1049 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1049 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1050 | 1050 | $ids[] = $id; |
| 1051 | 1051 | } |
| 1052 | 1052 | } |
@@ -1060,14 +1060,14 @@ discard block |
||
| 1060 | 1060 | /** |
| 1061 | 1061 | * Enable the debug mode |
| 1062 | 1062 | */ |
| 1063 | - public function enableDebug(){ |
|
| 1063 | + public function enableDebug() { |
|
| 1064 | 1064 | $this->debug = true; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | /** |
| 1068 | 1068 | * Disable the debug mode |
| 1069 | 1069 | */ |
| 1070 | - public function disableDebug(){ |
|
| 1070 | + public function disableDebug() { |
|
| 1071 | 1071 | $this->debug = false; |
| 1072 | 1072 | } |
| 1073 | 1073 | } |