@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | throw new AuthFailedException($message); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if(!$this->stream) { |
|
| 92 | + if (!$this->stream) { |
|
| 93 | 93 | $errors = \imap_errors(); |
| 94 | 94 | $message = implode("; ", (is_array($errors) ? $errors : array())); |
| 95 | 95 | throw new AuthFailedException($message); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $errors = \imap_errors(); |
| 99 | - if(is_array($errors)) { |
|
| 99 | + if (is_array($errors)) { |
|
| 100 | 100 | $status = $this->examineFolder(); |
| 101 | - if($status['exists'] !== 0) { |
|
| 101 | + if ($status['exists'] !== 0) { |
|
| 102 | 102 | $message = implode("; ", (is_array($errors) ? $errors : array())); |
| 103 | 103 | throw new RuntimeException($message); |
| 104 | 104 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | if (!$this->cert_validation) { |
| 130 | 130 | $address .= '/novalidate-cert'; |
| 131 | 131 | } |
| 132 | - if (in_array($this->encryption,['tls', 'notls', 'ssl'])) { |
|
| 132 | + if (in_array($this->encryption, ['tls', 'notls', 'ssl'])) { |
|
| 133 | 133 | $address .= '/'.$this->encryption; |
| 134 | 134 | } elseif ($this->encryption === "starttls") { |
| 135 | 135 | $address .= '/tls'; |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | $flags = []; |
| 258 | 258 | if (is_array($raw_flags) && isset($raw_flags[0])) { |
| 259 | 259 | $raw_flags = (array) $raw_flags[0]; |
| 260 | - foreach($raw_flags as $flag => $value) { |
|
| 261 | - if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false){ |
|
| 260 | + foreach ($raw_flags as $flag => $value) { |
|
| 261 | + if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false) { |
|
| 262 | 262 | $flags[] = "\\".ucfirst($flag); |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | $overview = $this->overview("1:*"); |
| 285 | 285 | $uids = []; |
| 286 | - foreach($overview as $set){ |
|
| 286 | + foreach ($overview as $set) { |
|
| 287 | 287 | $uids[$set->msgno] = $set->uid; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | 314 | public function overview(string $sequence, $uid = IMAP::ST_UID): array { |
| 315 | - return \imap_fetch_overview($this->stream, $sequence,$uid ? IMAP::ST_UID : IMAP::NIL); |
|
| 315 | + return \imap_fetch_overview($this->stream, $sequence, $uid ? IMAP::ST_UID : IMAP::NIL); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -327,12 +327,12 @@ discard block |
||
| 327 | 327 | $result = []; |
| 328 | 328 | |
| 329 | 329 | $items = \imap_getmailboxes($this->stream, $this->getAddress(), $reference.$folder); |
| 330 | - if(is_array($items)){ |
|
| 330 | + if (is_array($items)) { |
|
| 331 | 331 | foreach ($items as $item) { |
| 332 | 332 | $name = $this->decodeFolderName($item->name); |
| 333 | 333 | $result[$name] = ['delimiter' => $item->delimiter, 'flags' => []]; |
| 334 | 334 | } |
| 335 | - }else{ |
|
| 335 | + }else { |
|
| 336 | 336 | throw new RuntimeException(\imap_last_error()); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -355,9 +355,9 @@ discard block |
||
| 355 | 355 | public function store(array $flags, int $from, $to = null, $mode = null, bool $silent = true, $uid = IMAP::ST_UID, $item = null) { |
| 356 | 356 | $flag = trim(is_array($flags) ? implode(" ", $flags) : $flags); |
| 357 | 357 | |
| 358 | - if ($mode == "+"){ |
|
| 358 | + if ($mode == "+") { |
|
| 359 | 359 | $status = \imap_setflag_full($this->stream, $from, $flag, $uid ? IMAP::ST_UID : IMAP::NIL); |
| 360 | - }else{ |
|
| 360 | + }else { |
|
| 361 | 361 | $status = \imap_clearflag_full($this->stream, $from, $flag, $uid ? IMAP::ST_UID : IMAP::NIL); |
| 362 | 362 | } |
| 363 | 363 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function appendMessage(string $folder, string $message, $flags = null, $date = null): bool { |
| 381 | 381 | if ($date != null) { |
| 382 | - if ($date instanceof \Carbon\Carbon){ |
|
| 382 | + if ($date instanceof \Carbon\Carbon) { |
|
| 383 | 383 | $date = $date->format('d-M-Y H:i:s O'); |
| 384 | 384 | } |
| 385 | 385 | return \imap_append($this->stream, $folder, $message, $flags, $date); |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @return array|bool Tokens if operation successful, false if an error occurred |
| 412 | 412 | */ |
| 413 | 413 | public function copyManyMessages(array $messages, string $folder, $uid = IMAP::ST_UID) { |
| 414 | - foreach($messages as $msg) { |
|
| 414 | + foreach ($messages as $msg) { |
|
| 415 | 415 | if (!$this->copyMessage($folder, $msg, null, $uid)) { |
| 416 | 416 | return false; |
| 417 | 417 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | * @return array|bool Tokens if operation successful, false if an error occurred |
| 444 | 444 | */ |
| 445 | 445 | public function moveManyMessages(array $messages, string $folder, $uid = IMAP::ST_UID) { |
| 446 | - foreach($messages as $msg) { |
|
| 446 | + foreach ($messages as $msg) { |
|
| 447 | 447 | if (!$this->moveMessage($folder, $msg, null, $uid)) { |
| 448 | 448 | return false; |
| 449 | 449 | } |
@@ -570,14 +570,14 @@ discard block |
||
| 570 | 570 | /** |
| 571 | 571 | * Enable the debug mode |
| 572 | 572 | */ |
| 573 | - public function enableDebug(){ |
|
| 573 | + public function enableDebug() { |
|
| 574 | 574 | $this->debug = true; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
| 578 | 578 | * Disable the debug mode |
| 579 | 579 | */ |
| 580 | - public function disableDebug(){ |
|
| 580 | + public function disableDebug() { |
|
| 581 | 581 | $this->debug = false; |
| 582 | 582 | } |
| 583 | 583 | |
@@ -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) { |
@@ -112,7 +112,7 @@ discard block |
||
| 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 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $stack = []; |
| 167 | 167 | |
| 168 | 168 | // replace any trailing <NL> including spaces with a single space |
| 169 | - $line = rtrim($line) . ' '; |
|
| 169 | + $line = rtrim($line).' '; |
|
| 170 | 170 | while (($pos = strpos($line, ' ')) !== false) { |
| 171 | 171 | $token = substr($line, 0, $pos); |
| 172 | 172 | if (!strlen($token)) { |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | if (strlen($token) > $chars) { |
| 197 | 197 | $line = substr($token, $chars); |
| 198 | 198 | $token = substr($token, 0, $chars); |
| 199 | - } else { |
|
| 199 | + }else { |
|
| 200 | 200 | $line .= $this->nextLine(); |
| 201 | 201 | } |
| 202 | 202 | $tokens[] = $token; |
| 203 | - $line = trim($line) . ' '; |
|
| 203 | + $line = trim($line).' '; |
|
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $line = $this->nextTaggedLine($tag); // get next tag |
| 251 | 251 | if (!$dontParse) { |
| 252 | 252 | $tokens = $this->decodeLine($line); |
| 253 | - } else { |
|
| 253 | + }else { |
|
| 254 | 254 | $tokens = $line; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -300,20 +300,20 @@ discard block |
||
| 300 | 300 | public function sendRequest(string $command, array $tokens = [], string &$tag = null) { |
| 301 | 301 | if (!$tag) { |
| 302 | 302 | $this->noun++; |
| 303 | - $tag = 'TAG' . $this->noun; |
|
| 303 | + $tag = 'TAG'.$this->noun; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - $line = $tag . ' ' . $command; |
|
| 306 | + $line = $tag.' '.$command; |
|
| 307 | 307 | |
| 308 | 308 | foreach ($tokens as $token) { |
| 309 | 309 | if (is_array($token)) { |
| 310 | - $this->write($line . ' ' . $token[0]); |
|
| 310 | + $this->write($line.' '.$token[0]); |
|
| 311 | 311 | if (!$this->assumedNextLine('+ ')) { |
| 312 | 312 | throw new RuntimeException('failed to send literal string'); |
| 313 | 313 | } |
| 314 | 314 | $line = $token[1]; |
| 315 | - } else { |
|
| 316 | - $line .= ' ' . $token; |
|
| 315 | + }else { |
|
| 316 | + $line .= ' '.$token; |
|
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | $this->write($line); |
@@ -326,9 +326,9 @@ discard block |
||
| 326 | 326 | * @throws RuntimeException |
| 327 | 327 | */ |
| 328 | 328 | public function write(string $data) { |
| 329 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 329 | + if ($this->debug) echo ">> ".$data."\n"; |
|
| 330 | 330 | |
| 331 | - if (fwrite($this->stream, $data . "\r\n") === false) { |
|
| 331 | + if (fwrite($this->stream, $data."\r\n") === false) { |
|
| 332 | 332 | throw new RuntimeException('failed to write - connection closed?'); |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -358,9 +358,9 @@ discard block |
||
| 358 | 358 | public function escapeString($string) { |
| 359 | 359 | if (func_num_args() < 2) { |
| 360 | 360 | if (strpos($string, "\n") !== false) { |
| 361 | - return ['{' . strlen($string) . '}', $string]; |
|
| 362 | - } else { |
|
| 363 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 361 | + return ['{'.strlen($string).'}', $string]; |
|
| 362 | + }else { |
|
| 363 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | $result = []; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | } |
| 386 | 386 | $result[] = $this->escapeList($v); |
| 387 | 387 | } |
| 388 | - return '(' . implode(' ', $result) . ')'; |
|
| 388 | + return '('.implode(' ', $result).')'; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -426,12 +426,12 @@ discard block |
||
| 426 | 426 | error_log("got an extra server challenge: $response"); |
| 427 | 427 | // respond with an empty response. |
| 428 | 428 | $this->sendRequest(''); |
| 429 | - } else { |
|
| 429 | + }else { |
|
| 430 | 430 | if (preg_match('/^NO /i', $response) || |
| 431 | 431 | preg_match('/^BAD /i', $response)) { |
| 432 | 432 | error_log("got failure response: $response"); |
| 433 | 433 | return false; |
| 434 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 434 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 435 | 435 | return true; |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -512,10 +512,10 @@ discard block |
||
| 512 | 512 | $result[strtolower($tokens[1])] = $tokens[0]; |
| 513 | 513 | break; |
| 514 | 514 | case '[UIDVALIDITY': |
| 515 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 515 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 516 | 516 | break; |
| 517 | 517 | case '[UIDNEXT': |
| 518 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 518 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 519 | 519 | break; |
| 520 | 520 | default: |
| 521 | 521 | // ignore |
@@ -572,14 +572,14 @@ discard block |
||
| 572 | 572 | if (is_array($from)) { |
| 573 | 573 | $set = implode(',', $from); |
| 574 | 574 | } elseif ($to === null) { |
| 575 | - $set = (int)$from; |
|
| 575 | + $set = (int) $from; |
|
| 576 | 576 | } elseif ($to === INF) { |
| 577 | - $set = (int)$from . ':*'; |
|
| 578 | - } else { |
|
| 579 | - $set = (int)$from . ':' . (int)$to; |
|
| 577 | + $set = (int) $from.':*'; |
|
| 578 | + }else { |
|
| 579 | + $set = (int) $from.':'.(int) $to; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - $items = (array)$items; |
|
| 582 | + $items = (array) $items; |
|
| 583 | 583 | $itemList = $this->escapeList($items); |
| 584 | 584 | |
| 585 | 585 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -596,9 +596,9 @@ discard block |
||
| 596 | 596 | $count = count($tokens[2]); |
| 597 | 597 | if ($tokens[2][$count - 2] == 'UID') { |
| 598 | 598 | $uidKey = $count - 1; |
| 599 | - } else if ($tokens[2][0] == 'UID') { |
|
| 599 | + }else if ($tokens[2][0] == 'UID') { |
|
| 600 | 600 | $uidKey = 1; |
| 601 | - } else { |
|
| 601 | + }else { |
|
| 602 | 602 | $uidKey = array_search('UID', $tokens[2]) + 1; |
| 603 | 603 | } |
| 604 | 604 | } |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | $data = $tokens[2][1]; |
| 616 | 616 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 617 | 617 | $data = $tokens[2][3]; |
| 618 | - } else { |
|
| 618 | + }else { |
|
| 619 | 619 | // maybe the server send an other field we didn't wanted |
| 620 | 620 | $count = count($tokens[2]); |
| 621 | 621 | // we start with 2, because 0 was already checked |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | break; |
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | - } else { |
|
| 630 | + }else { |
|
| 631 | 631 | $data = []; |
| 632 | 632 | while (key($tokens[2]) !== null) { |
| 633 | 633 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | if ($uid) { |
| 646 | 646 | $result[$tokens[2][$uidKey]] = $data; |
| 647 | - }else{ |
|
| 647 | + }else { |
|
| 648 | 648 | $result[$tokens[0]] = $data; |
| 649 | 649 | } |
| 650 | 650 | } |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
| 800 | 800 | |
| 801 | 801 | if ($silent) { |
| 802 | - return (bool)$response; |
|
| 802 | + return (bool) $response; |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | $result = []; |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | $set = $this->buildSet($from, $to); |
| 892 | 892 | $command = $this->buildUIDCommand("MOVE", $uid); |
| 893 | 893 | |
| 894 | - return (bool)$this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 894 | + return (bool) $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | * @throws RuntimeException |
| 944 | 944 | */ |
| 945 | 945 | public function createFolder(string $folder): bool { |
| 946 | - return (bool)$this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 946 | + return (bool) $this->requestAndResponse('CREATE', [$this->escapeString($folder)], true); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | /** |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * @throws RuntimeException |
| 956 | 956 | */ |
| 957 | 957 | public function renameFolder(string $old, string $new): bool { |
| 958 | - return (bool)$this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 958 | + return (bool) $this->requestAndResponse('RENAME', $this->escapeString($old, $new), true); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | * @throws RuntimeException |
| 967 | 967 | */ |
| 968 | 968 | public function deleteFolder(string $folder): bool { |
| 969 | - return (bool)$this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 969 | + return (bool) $this->requestAndResponse('DELETE', [$this->escapeString($folder)], true); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * @throws RuntimeException |
| 978 | 978 | */ |
| 979 | 979 | public function subscribeFolder(string $folder): bool { |
| 980 | - return (bool)$this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 980 | + return (bool) $this->requestAndResponse('SUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | * @throws RuntimeException |
| 989 | 989 | */ |
| 990 | 990 | public function unsubscribeFolder(string $folder): bool { |
| 991 | - return (bool)$this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 991 | + return (bool) $this->requestAndResponse('UNSUBSCRIBE', [$this->escapeString($folder)], true); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | * @throws RuntimeException |
| 999 | 999 | */ |
| 1000 | 1000 | public function expunge(): bool { |
| 1001 | - return (bool)$this->requestAndResponse('EXPUNGE'); |
|
| 1001 | + return (bool) $this->requestAndResponse('EXPUNGE'); |
|
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | /** |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | * @throws RuntimeException |
| 1009 | 1009 | */ |
| 1010 | 1010 | public function noop(): bool { |
| 1011 | - return (bool)$this->requestAndResponse('NOOP'); |
|
| 1011 | + return (bool) $this->requestAndResponse('NOOP'); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1101,7 +1101,7 @@ discard block |
||
| 1101 | 1101 | $ids = []; |
| 1102 | 1102 | foreach ($uids as $msgn => $v) { |
| 1103 | 1103 | $id = $uid ? $v : $msgn; |
| 1104 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1104 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1105 | 1105 | $ids[] = $id; |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
@@ -1115,14 +1115,14 @@ discard block |
||
| 1115 | 1115 | /** |
| 1116 | 1116 | * Enable the debug mode |
| 1117 | 1117 | */ |
| 1118 | - public function enableDebug(){ |
|
| 1118 | + public function enableDebug() { |
|
| 1119 | 1119 | $this->debug = true; |
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
| 1123 | 1123 | * Disable the debug mode |
| 1124 | 1124 | */ |
| 1125 | - public function disableDebug(){ |
|
| 1125 | + public function disableDebug() { |
|
| 1126 | 1126 | $this->debug = false; |
| 1127 | 1127 | } |
| 1128 | 1128 | |
@@ -1134,9 +1134,9 @@ discard block |
||
| 1134 | 1134 | * @return int|string |
| 1135 | 1135 | */ |
| 1136 | 1136 | public function buildSet($from, $to = null) { |
| 1137 | - $set = (int)$from; |
|
| 1137 | + $set = (int) $from; |
|
| 1138 | 1138 | if ($to !== null) { |
| 1139 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1139 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | return $set; |
| 1142 | 1142 | } |