@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $this->setDelimiter($delimiter); |
| 125 | 125 | $this->path = $folder_name; |
| 126 | - $this->full_name = $this->decodeName($folder_name); |
|
| 126 | + $this->full_name = $this->decodeName($folder_name); |
|
| 127 | 127 | $this->name = $this->getSimpleName($this->delimiter, $this->full_name); |
| 128 | 128 | |
| 129 | 129 | $this->parseAttributes($attributes); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | public function move(string $new_name, bool $expunge = true): bool { |
| 241 | 241 | $this->client->checkConnection(); |
| 242 | 242 | $status = $this->client->getConnection()->renameFolder($this->full_name, $new_name); |
| 243 | - if($expunge) $this->client->expunge(); |
|
| 243 | + if ($expunge) $this->client->expunge(); |
|
| 244 | 244 | |
| 245 | 245 | $folder = $this->client->getFolder($new_name); |
| 246 | 246 | $event = $this->getEvent("folder", "moved"); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * date string that conforms to the rfc2060 specifications for a date_time value or be a Carbon object. |
| 284 | 284 | */ |
| 285 | 285 | |
| 286 | - if ($internal_date instanceof Carbon){ |
|
| 286 | + if ($internal_date instanceof Carbon) { |
|
| 287 | 287 | $internal_date = $internal_date->format('d-M-Y H:i:s O'); |
| 288 | 288 | } |
| 289 | 289 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | public function delete(bool $expunge = true): bool { |
| 318 | 318 | $status = $this->client->getConnection()->deleteFolder($this->path); |
| 319 | - if($expunge) $this->client->expunge(); |
|
| 319 | + if ($expunge) $this->client->expunge(); |
|
| 320 | 320 | |
| 321 | 321 | $event = $this->getEvent("folder", "deleted"); |
| 322 | 322 | $event::dispatch($this); |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | |
| 382 | 382 | if (($pos = strpos($line, "EXISTS")) !== false) { |
| 383 | 383 | $connection->done(); |
| 384 | - $msgn = (int) substr($line, 2, $pos -2); |
|
| 384 | + $msgn = (int) substr($line, 2, $pos - 2); |
|
| 385 | 385 | |
| 386 | 386 | $this->client->openFolder($this->path, true); |
| 387 | 387 | $message = $this->query()->getMessageByMsgn($msgn); |
@@ -395,13 +395,13 @@ discard block |
||
| 395 | 395 | $connection->done(); |
| 396 | 396 | $connection->idle(); |
| 397 | 397 | } |
| 398 | - }catch (Exceptions\RuntimeException $e) { |
|
| 399 | - if(strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) { |
|
| 398 | + } catch (Exceptions\RuntimeException $e) { |
|
| 399 | + if (strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) { |
|
| 400 | 400 | $connection->done(); |
| 401 | 401 | $connection->idle(); |
| 402 | 402 | continue; |
| 403 | 403 | } |
| 404 | - if(strpos($e->getMessage(), "connection closed") === false) { |
|
| 404 | + if (strpos($e->getMessage(), "connection closed") === false) { |
|
| 405 | 405 | throw $e; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * Set the delimiter |
| 450 | 450 | * @param $delimiter |
| 451 | 451 | */ |
| 452 | - public function setDelimiter($delimiter){ |
|
| 453 | - if(in_array($delimiter, [null, '', ' ', false]) === true) { |
|
| 452 | + public function setDelimiter($delimiter) { |
|
| 453 | + if (in_array($delimiter, [null, '', ' ', false]) === true) { |
|
| 454 | 454 | $delimiter = ClientManager::get('options.delimiter', '/'); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -240,7 +240,9 @@ discard block |
||
| 240 | 240 | public function move(string $new_name, bool $expunge = true): bool { |
| 241 | 241 | $this->client->checkConnection(); |
| 242 | 242 | $status = $this->client->getConnection()->renameFolder($this->full_name, $new_name); |
| 243 | - if($expunge) $this->client->expunge(); |
|
| 243 | + if($expunge) { |
|
| 244 | + $this->client->expunge(); |
|
| 245 | + } |
|
| 244 | 246 | |
| 245 | 247 | $folder = $this->client->getFolder($new_name); |
| 246 | 248 | $event = $this->getEvent("folder", "moved"); |
@@ -316,7 +318,9 @@ discard block |
||
| 316 | 318 | */ |
| 317 | 319 | public function delete(bool $expunge = true): bool { |
| 318 | 320 | $status = $this->client->getConnection()->deleteFolder($this->path); |
| 319 | - if($expunge) $this->client->expunge(); |
|
| 321 | + if($expunge) { |
|
| 322 | + $this->client->expunge(); |
|
| 323 | + } |
|
| 320 | 324 | |
| 321 | 325 | $event = $this->getEvent("folder", "deleted"); |
| 322 | 326 | $event::dispatch($this); |
@@ -395,7 +399,7 @@ discard block |
||
| 395 | 399 | $connection->done(); |
| 396 | 400 | $connection->idle(); |
| 397 | 401 | } |
| 398 | - }catch (Exceptions\RuntimeException $e) { |
|
| 402 | + } catch (Exceptions\RuntimeException $e) { |
|
| 399 | 403 | if(strpos($e->getMessage(), "empty response") >= 0 && $connection->connected()) { |
| 400 | 404 | $connection->done(); |
| 401 | 405 | $connection->idle(); |
@@ -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 = []; |
@@ -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 | } |
@@ -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 | } |