@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @throws ConnectionFailedException |
85 | 85 | * @throws RuntimeException |
86 | 86 | */ |
87 | - protected function enableTls(){ |
|
87 | + protected function enableTls() { |
|
88 | 88 | $response = $this->requestAndResponse('STARTTLS'); |
89 | 89 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
90 | 90 | if (!$result) { |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $stack = []; |
147 | 147 | |
148 | 148 | // replace any trailing <NL> including spaces with a single space |
149 | - $line = rtrim($line) . ' '; |
|
149 | + $line = rtrim($line).' '; |
|
150 | 150 | while (($pos = strpos($line, ' ')) !== false) { |
151 | 151 | $token = substr($line, 0, $pos); |
152 | 152 | if (!strlen($token)) { |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | if (strlen($token) > $chars) { |
177 | 177 | $line = substr($token, $chars); |
178 | 178 | $token = substr($token, 0, $chars); |
179 | - } else { |
|
179 | + }else { |
|
180 | 180 | $line .= $this->nextLine(); |
181 | 181 | } |
182 | 182 | $tokens[] = $token; |
183 | - $line = trim($line) . ' '; |
|
183 | + $line = trim($line).' '; |
|
184 | 184 | continue; |
185 | 185 | } |
186 | 186 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $line = $this->nextTaggedLine($tag); // get next tag |
231 | 231 | if (!$dontParse) { |
232 | 232 | $tokens = $this->decodeLine($line); |
233 | - } else { |
|
233 | + }else { |
|
234 | 234 | $tokens = $line; |
235 | 235 | } |
236 | 236 | if ($this->debug) echo "<< ".$line."\n"; |
@@ -280,27 +280,27 @@ discard block |
||
280 | 280 | public function sendRequest($command, $tokens = [], &$tag = null) { |
281 | 281 | if (!$tag) { |
282 | 282 | $this->noun++; |
283 | - $tag = 'TAG' . $this->noun; |
|
283 | + $tag = 'TAG'.$this->noun; |
|
284 | 284 | } |
285 | 285 | |
286 | - $line = $tag . ' ' . $command; |
|
286 | + $line = $tag.' '.$command; |
|
287 | 287 | |
288 | 288 | foreach ($tokens as $token) { |
289 | 289 | if (is_array($token)) { |
290 | - if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) { |
|
290 | + if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) { |
|
291 | 291 | throw new RuntimeException('failed to write - connection closed?'); |
292 | 292 | } |
293 | 293 | if (!$this->assumedNextLine('+ ')) { |
294 | 294 | throw new RuntimeException('failed to send literal string'); |
295 | 295 | } |
296 | 296 | $line = $token[1]; |
297 | - } else { |
|
298 | - $line .= ' ' . $token; |
|
297 | + }else { |
|
298 | + $line .= ' '.$token; |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | if ($this->debug) echo ">> ".$line."\n"; |
302 | 302 | |
303 | - if (fwrite($this->stream, $line . "\r\n") === false) { |
|
303 | + if (fwrite($this->stream, $line."\r\n") === false) { |
|
304 | 304 | throw new RuntimeException('failed to write - connection closed?'); |
305 | 305 | } |
306 | 306 | } |
@@ -330,9 +330,9 @@ discard block |
||
330 | 330 | public function escapeString($string) { |
331 | 331 | if (func_num_args() < 2) { |
332 | 332 | if (strpos($string, "\n") !== false) { |
333 | - return ['{' . strlen($string) . '}', $string]; |
|
334 | - } else { |
|
335 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
333 | + return ['{'.strlen($string).'}', $string]; |
|
334 | + }else { |
|
335 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | $result = []; |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | } |
358 | 358 | $result[] = $this->escapeList($v); |
359 | 359 | } |
360 | - return '(' . implode(' ', $result) . ')'; |
|
360 | + return '('.implode(' ', $result).')'; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -397,12 +397,12 @@ discard block |
||
397 | 397 | error_log("got an extra server challenge: $response"); |
398 | 398 | // respond with an empty response. |
399 | 399 | $this->sendRequest(''); |
400 | - } else { |
|
400 | + }else { |
|
401 | 401 | if (preg_match('/^NO /i', $response) || |
402 | 402 | preg_match('/^BAD /i', $response)) { |
403 | 403 | error_log("got failure response: $response"); |
404 | 404 | return false; |
405 | - } else if (preg_match("/^OK /i", $response)) { |
|
405 | + }else if (preg_match("/^OK /i", $response)) { |
|
406 | 406 | return true; |
407 | 407 | } |
408 | 408 | } |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * |
436 | 436 | * @return bool |
437 | 437 | */ |
438 | - public function connected(){ |
|
438 | + public function connected() { |
|
439 | 439 | return (boolean) $this->stream; |
440 | 440 | } |
441 | 441 | |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | $result[strtolower($tokens[1])] = $tokens[0]; |
483 | 483 | break; |
484 | 484 | case '[UIDVALIDITY': |
485 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
485 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
486 | 486 | break; |
487 | 487 | case '[UIDNEXT': |
488 | - $result['uidnext'] = (int)$tokens[2]; |
|
488 | + $result['uidnext'] = (int) $tokens[2]; |
|
489 | 489 | break; |
490 | 490 | default: |
491 | 491 | // ignore |
@@ -539,17 +539,17 @@ discard block |
||
539 | 539 | if (is_array($from)) { |
540 | 540 | $set = implode(',', $from); |
541 | 541 | } elseif ($to === null) { |
542 | - $set = (int)$from; |
|
542 | + $set = (int) $from; |
|
543 | 543 | } elseif ($to === INF) { |
544 | - $set = (int)$from . ':*'; |
|
545 | - } else { |
|
546 | - $set = (int)$from . ':' . (int)$to; |
|
544 | + $set = (int) $from.':*'; |
|
545 | + }else { |
|
546 | + $set = (int) $from.':'.(int) $to; |
|
547 | 547 | } |
548 | 548 | |
549 | - $items = (array)$items; |
|
549 | + $items = (array) $items; |
|
550 | 550 | $itemList = $this->escapeList($items); |
551 | 551 | |
552 | - $this->sendRequest(($uid ? 'UID ' : '') . 'FETCH', [$set, $itemList], $tag); |
|
552 | + $this->sendRequest(($uid ? 'UID ' : '').'FETCH', [$set, $itemList], $tag); |
|
553 | 553 | |
554 | 554 | $result = []; |
555 | 555 | $tokens = null; // define $tokens variable before first use |
@@ -564,9 +564,9 @@ discard block |
||
564 | 564 | $count = count($tokens[2]); |
565 | 565 | if ($tokens[2][$count - 2] == 'UID') { |
566 | 566 | $uidKey = $count - 1; |
567 | - } else if ($tokens[2][0] == 'UID') { |
|
567 | + }else if ($tokens[2][0] == 'UID') { |
|
568 | 568 | $uidKey = 1; |
569 | - } else { |
|
569 | + }else { |
|
570 | 570 | $uidKey = array_search('UID', $tokens[2]) + 1; |
571 | 571 | } |
572 | 572 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | $data = $tokens[2][1]; |
583 | 583 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
584 | 584 | $data = $tokens[2][3]; |
585 | - } else { |
|
585 | + }else { |
|
586 | 586 | // maybe the server send an other field we didn't wanted |
587 | 587 | $count = count($tokens[2]); |
588 | 588 | // we start with 2, because 0 was already checked |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | break; |
595 | 595 | } |
596 | 596 | } |
597 | - } else { |
|
597 | + }else { |
|
598 | 598 | $data = []; |
599 | 599 | while (key($tokens[2]) !== null) { |
600 | 600 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | } |
612 | 612 | if ($uid) { |
613 | 613 | $result[$tokens[2][$uidKey]] = $data; |
614 | - }else{ |
|
614 | + }else { |
|
615 | 615 | $result[$tokens[0]] = $data; |
616 | 616 | } |
617 | 617 | } |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | * @return array |
646 | 646 | * @throws RuntimeException |
647 | 647 | */ |
648 | - public function headers($uids, $rfc = "RFC822", $uid = false){ |
|
648 | + public function headers($uids, $rfc = "RFC822", $uid = false) { |
|
649 | 649 | return $this->fetch(["$rfc.HEADER"], $uids, null, $uid); |
650 | 650 | } |
651 | 651 | |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | * @return array |
658 | 658 | * @throws RuntimeException |
659 | 659 | */ |
660 | - public function flags($uids, $uid = false){ |
|
660 | + public function flags($uids, $uid = false) { |
|
661 | 661 | return $this->fetch(["FLAGS"], $uids, null, $uid); |
662 | 662 | } |
663 | 663 | |
@@ -742,23 +742,23 @@ discard block |
||
742 | 742 | public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) { |
743 | 743 | $item = 'FLAGS'; |
744 | 744 | if ($mode == '+' || $mode == '-') { |
745 | - $item = $mode . $item; |
|
745 | + $item = $mode.$item; |
|
746 | 746 | } |
747 | 747 | if ($silent) { |
748 | 748 | $item .= '.SILENT'; |
749 | 749 | } |
750 | 750 | |
751 | 751 | $flags = $this->escapeList($flags); |
752 | - $set = (int)$from; |
|
752 | + $set = (int) $from; |
|
753 | 753 | if ($to !== null) { |
754 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
754 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | $command = ($uid ? "UID " : "")."STORE"; |
758 | 758 | $result = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
759 | 759 | |
760 | 760 | if ($silent) { |
761 | - return (bool)$result; |
|
761 | + return (bool) $result; |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | $tokens = $result; |
@@ -809,9 +809,9 @@ discard block |
||
809 | 809 | * @throws RuntimeException |
810 | 810 | */ |
811 | 811 | public function copyMessage($folder, $from, $to = null, $uid = false) { |
812 | - $set = (int)$from; |
|
812 | + $set = (int) $from; |
|
813 | 813 | if ($to !== null) { |
814 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
814 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
815 | 815 | } |
816 | 816 | $command = ($uid ? "UID " : "")."COPY"; |
817 | 817 | |
@@ -830,9 +830,9 @@ discard block |
||
830 | 830 | * @throws RuntimeException |
831 | 831 | */ |
832 | 832 | public function moveMessage($folder, $from, $to = null, $uid = false) { |
833 | - $set = (int)$from; |
|
833 | + $set = (int) $from; |
|
834 | 834 | if ($to !== null) { |
835 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
835 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
836 | 836 | } |
837 | 837 | $command = ($uid ? "UID " : "")."MOVE"; |
838 | 838 | |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | $ids = []; |
1003 | 1003 | foreach ($uids as $msgn => $v) { |
1004 | 1004 | $id = $uid ? $v : $msgn; |
1005 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
1005 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
1006 | 1006 | $ids[] = $id; |
1007 | 1007 | } |
1008 | 1008 | } |
@@ -1016,14 +1016,14 @@ discard block |
||
1016 | 1016 | /** |
1017 | 1017 | * Enable the debug mode |
1018 | 1018 | */ |
1019 | - public function enableDebug(){ |
|
1019 | + public function enableDebug() { |
|
1020 | 1020 | $this->debug = true; |
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
1024 | 1024 | * Disable the debug mode |
1025 | 1025 | */ |
1026 | - public function disableDebug(){ |
|
1026 | + public function disableDebug() { |
|
1027 | 1027 | $this->debug = false; |
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | \ No newline at end of file |
@@ -233,7 +233,9 @@ discard block |
||
233 | 233 | } else { |
234 | 234 | $tokens = $line; |
235 | 235 | } |
236 | - if ($this->debug) echo "<< ".$line."\n"; |
|
236 | + if ($this->debug) { |
|
237 | + echo "<< ".$line."\n"; |
|
238 | + } |
|
237 | 239 | |
238 | 240 | // if tag is wanted tag we might be at the end of a multiline response |
239 | 241 | return $tag == $wantedTag; |
@@ -298,7 +300,9 @@ discard block |
||
298 | 300 | $line .= ' ' . $token; |
299 | 301 | } |
300 | 302 | } |
301 | - if ($this->debug) echo ">> ".$line."\n"; |
|
303 | + if ($this->debug) { |
|
304 | + echo ">> ".$line."\n"; |
|
305 | + } |
|
302 | 306 | |
303 | 307 | if (fwrite($this->stream, $line . "\r\n") === false) { |
304 | 308 | throw new RuntimeException('failed to write - connection closed?'); |
@@ -448,7 +452,9 @@ discard block |
||
448 | 452 | public function getCapabilities() { |
449 | 453 | $response = $this->requestAndResponse('CAPABILITY'); |
450 | 454 | |
451 | - if (!$response) return []; |
|
455 | + if (!$response) { |
|
456 | + return []; |
|
457 | + } |
|
452 | 458 | |
453 | 459 | $capabilities = []; |
454 | 460 | foreach ($response as $line) { |
@@ -605,13 +611,14 @@ discard block |
||
605 | 611 | // if we want only one message we can ignore everything else and just return |
606 | 612 | if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) { |
607 | 613 | // we still need to read all lines |
608 | - while (!$this->readLine($tokens, $tag)) |
|
609 | - |
|
614 | + while (!$this->readLine($tokens, $tag)) { |
|
615 | + |
|
610 | 616 | return $data; |
617 | + } |
|
611 | 618 | } |
612 | 619 | if ($uid) { |
613 | 620 | $result[$tokens[2][$uidKey]] = $data; |
614 | - }else{ |
|
621 | + } else{ |
|
615 | 622 | $result[$tokens[0]] = $data; |
616 | 623 | } |
617 | 624 | } |