@@ -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) { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $stack = []; |
| 152 | 152 | |
| 153 | 153 | // replace any trailing <NL> including spaces with a single space |
| 154 | - $line = rtrim($line) . ' '; |
|
| 154 | + $line = rtrim($line).' '; |
|
| 155 | 155 | while (($pos = strpos($line, ' ')) !== false) { |
| 156 | 156 | $token = substr($line, 0, $pos); |
| 157 | 157 | if (!strlen($token)) { |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | if (strlen($token) > $chars) { |
| 182 | 182 | $line = substr($token, $chars); |
| 183 | 183 | $token = substr($token, 0, $chars); |
| 184 | - } else { |
|
| 184 | + }else { |
|
| 185 | 185 | $line .= $this->nextLine(); |
| 186 | 186 | } |
| 187 | 187 | $tokens[] = $token; |
| 188 | - $line = trim($line) . ' '; |
|
| 188 | + $line = trim($line).' '; |
|
| 189 | 189 | continue; |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $line = $this->nextTaggedLine($tag); // get next tag |
| 236 | 236 | if (!$dontParse) { |
| 237 | 237 | $tokens = $this->decodeLine($line); |
| 238 | - } else { |
|
| 238 | + }else { |
|
| 239 | 239 | $tokens = $line; |
| 240 | 240 | } |
| 241 | 241 | if ($this->debug) echo "<< ".$line."\n"; |
@@ -286,27 +286,27 @@ discard block |
||
| 286 | 286 | public function sendRequest($command, $tokens = [], &$tag = null) { |
| 287 | 287 | if (!$tag) { |
| 288 | 288 | $this->noun++; |
| 289 | - $tag = 'TAG' . $this->noun; |
|
| 289 | + $tag = 'TAG'.$this->noun; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $line = $tag . ' ' . $command; |
|
| 292 | + $line = $tag.' '.$command; |
|
| 293 | 293 | |
| 294 | 294 | foreach ($tokens as $token) { |
| 295 | 295 | if (is_array($token)) { |
| 296 | - if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) { |
|
| 296 | + if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) { |
|
| 297 | 297 | throw new RuntimeException('failed to write - connection closed?'); |
| 298 | 298 | } |
| 299 | 299 | if (!$this->assumedNextLine('+ ')) { |
| 300 | 300 | throw new RuntimeException('failed to send literal string'); |
| 301 | 301 | } |
| 302 | 302 | $line = $token[1]; |
| 303 | - } else { |
|
| 304 | - $line .= ' ' . $token; |
|
| 303 | + }else { |
|
| 304 | + $line .= ' '.$token; |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | if ($this->debug) echo ">> ".$line."\n"; |
| 308 | 308 | |
| 309 | - if (fwrite($this->stream, $line . "\r\n") === false) { |
|
| 309 | + if (fwrite($this->stream, $line."\r\n") === false) { |
|
| 310 | 310 | throw new RuntimeException('failed to write - connection closed?'); |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | public function escapeString($string) { |
| 337 | 337 | if (func_num_args() < 2) { |
| 338 | 338 | if (strpos($string, "\n") !== false) { |
| 339 | - return ['{' . strlen($string) . '}', $string]; |
|
| 340 | - } else { |
|
| 341 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 339 | + return ['{'.strlen($string).'}', $string]; |
|
| 340 | + }else { |
|
| 341 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | $result = []; |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | } |
| 364 | 364 | $result[] = $this->escapeList($v); |
| 365 | 365 | } |
| 366 | - return '(' . implode(' ', $result) . ')'; |
|
| 366 | + return '('.implode(' ', $result).')'; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -403,12 +403,12 @@ discard block |
||
| 403 | 403 | error_log("got an extra server challenge: $response"); |
| 404 | 404 | // respond with an empty response. |
| 405 | 405 | $this->sendRequest(''); |
| 406 | - } else { |
|
| 406 | + }else { |
|
| 407 | 407 | if (preg_match('/^NO /i', $response) || |
| 408 | 408 | preg_match('/^BAD /i', $response)) { |
| 409 | 409 | error_log("got failure response: $response"); |
| 410 | 410 | return false; |
| 411 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 411 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 412 | 412 | return true; |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | * |
| 444 | 444 | * @return bool |
| 445 | 445 | */ |
| 446 | - public function connected(){ |
|
| 446 | + public function connected() { |
|
| 447 | 447 | return (boolean) $this->stream; |
| 448 | 448 | } |
| 449 | 449 | |
@@ -490,10 +490,10 @@ discard block |
||
| 490 | 490 | $result[strtolower($tokens[1])] = $tokens[0]; |
| 491 | 491 | break; |
| 492 | 492 | case '[UIDVALIDITY': |
| 493 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 493 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 494 | 494 | break; |
| 495 | 495 | case '[UIDNEXT': |
| 496 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 496 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 497 | 497 | break; |
| 498 | 498 | default: |
| 499 | 499 | // ignore |
@@ -550,14 +550,14 @@ discard block |
||
| 550 | 550 | if (is_array($from)) { |
| 551 | 551 | $set = implode(',', $from); |
| 552 | 552 | } elseif ($to === null) { |
| 553 | - $set = (int)$from; |
|
| 553 | + $set = (int) $from; |
|
| 554 | 554 | } elseif ($to === INF) { |
| 555 | - $set = (int)$from . ':*'; |
|
| 556 | - } else { |
|
| 557 | - $set = (int)$from . ':' . (int)$to; |
|
| 555 | + $set = (int) $from.':*'; |
|
| 556 | + }else { |
|
| 557 | + $set = (int) $from.':'.(int) $to; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | - $items = (array)$items; |
|
| 560 | + $items = (array) $items; |
|
| 561 | 561 | $itemList = $this->escapeList($items); |
| 562 | 562 | |
| 563 | 563 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | $count = count($tokens[2]); |
| 575 | 575 | if ($tokens[2][$count - 2] == 'UID') { |
| 576 | 576 | $uidKey = $count - 1; |
| 577 | - } else if ($tokens[2][0] == 'UID') { |
|
| 577 | + }else if ($tokens[2][0] == 'UID') { |
|
| 578 | 578 | $uidKey = 1; |
| 579 | - } else { |
|
| 579 | + }else { |
|
| 580 | 580 | $uidKey = array_search('UID', $tokens[2]) + 1; |
| 581 | 581 | } |
| 582 | 582 | } |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | $data = $tokens[2][1]; |
| 593 | 593 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 594 | 594 | $data = $tokens[2][3]; |
| 595 | - } else { |
|
| 595 | + }else { |
|
| 596 | 596 | // maybe the server send an other field we didn't wanted |
| 597 | 597 | $count = count($tokens[2]); |
| 598 | 598 | // we start with 2, because 0 was already checked |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | break; |
| 605 | 605 | } |
| 606 | 606 | } |
| 607 | - } else { |
|
| 607 | + }else { |
|
| 608 | 608 | $data = []; |
| 609 | 609 | while (key($tokens[2]) !== null) { |
| 610 | 610 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | } |
| 622 | 622 | if ($uid) { |
| 623 | 623 | $result[$tokens[2][$uidKey]] = $data; |
| 624 | - }else{ |
|
| 624 | + }else { |
|
| 625 | 625 | $result[$tokens[0]] = $data; |
| 626 | 626 | } |
| 627 | 627 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | * @return array |
| 658 | 658 | * @throws RuntimeException |
| 659 | 659 | */ |
| 660 | - public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID){ |
|
| 660 | + public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID) { |
|
| 661 | 661 | return $this->fetch(["$rfc.HEADER"], $uids, null, $uid); |
| 662 | 662 | } |
| 663 | 663 | |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * @return array |
| 671 | 671 | * @throws RuntimeException |
| 672 | 672 | */ |
| 673 | - public function flags($uids, $uid = IMAP::ST_UID){ |
|
| 673 | + public function flags($uids, $uid = IMAP::ST_UID) { |
|
| 674 | 674 | return $this->fetch(["FLAGS"], $uids, null, $uid); |
| 675 | 675 | } |
| 676 | 676 | |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | if ($this->enable_uid_cache && $this->uid_cache) { |
| 687 | 687 | $uids = $this->uid_cache; |
| 688 | - } else { |
|
| 688 | + }else { |
|
| 689 | 689 | try { |
| 690 | 690 | $uids = $this->fetch('UID', 1, INF); |
| 691 | 691 | $this->setUidCache($uids); // set cache for this folder |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
| 780 | 780 | |
| 781 | 781 | if ($silent) { |
| 782 | - return (bool)$response; |
|
| 782 | + return (bool) $response; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | $result = []; |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | $ids = []; |
| 1081 | 1081 | foreach ($uids as $msgn => $v) { |
| 1082 | 1082 | $id = $uid ? $v : $msgn; |
| 1083 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1083 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1084 | 1084 | $ids[] = $id; |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
@@ -1094,14 +1094,14 @@ discard block |
||
| 1094 | 1094 | /** |
| 1095 | 1095 | * Enable the debug mode |
| 1096 | 1096 | */ |
| 1097 | - public function enableDebug(){ |
|
| 1097 | + public function enableDebug() { |
|
| 1098 | 1098 | $this->debug = true; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | /** |
| 1102 | 1102 | * Disable the debug mode |
| 1103 | 1103 | */ |
| 1104 | - public function disableDebug(){ |
|
| 1104 | + public function disableDebug() { |
|
| 1105 | 1105 | $this->debug = false; |
| 1106 | 1106 | } |
| 1107 | 1107 | |
@@ -1113,9 +1113,9 @@ discard block |
||
| 1113 | 1113 | * @return int|string |
| 1114 | 1114 | */ |
| 1115 | 1115 | public function buildSet($from, $to = null) { |
| 1116 | - $set = (int)$from; |
|
| 1116 | + $set = (int) $from; |
|
| 1117 | 1117 | if ($to !== null) { |
| 1118 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1118 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | return $set; |
| 1121 | 1121 | } |
@@ -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'; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return bool |
| 162 | 162 | */ |
| 163 | - public function connected(){ |
|
| 163 | + public function connected() { |
|
| 164 | 164 | return boolval($this->stream); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @return array |
| 235 | 235 | */ |
| 236 | - public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID){ |
|
| 236 | + public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID) { |
|
| 237 | 237 | $result = []; |
| 238 | 238 | $uids = is_array($uids) ? $uids : [$uids]; |
| 239 | 239 | foreach ($uids as $id) { |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | - public function flags($uids, $uid = IMAP::ST_UID){ |
|
| 252 | + public function flags($uids, $uid = IMAP::ST_UID) { |
|
| 253 | 253 | $result = []; |
| 254 | 254 | $uids = is_array($uids) ? $uids : [$uids]; |
| 255 | 255 | foreach ($uids as $id) { |
@@ -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($sequence, $uid = IMAP::ST_UID) { |
| 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 | |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = IMAP::ST_UID) { |
| 355 | 355 | $flag = trim(is_array($flags) ? implode(" ", $flags) : $flags); |
| 356 | 356 | |
| 357 | - if ($mode == "+"){ |
|
| 357 | + if ($mode == "+") { |
|
| 358 | 358 | $status = \imap_setflag_full($this->stream, $from, $flag, $uid ? IMAP::ST_UID : IMAP::NIL); |
| 359 | - }else{ |
|
| 359 | + }else { |
|
| 360 | 360 | $status = \imap_clearflag_full($this->stream, $from, $flag, $uid ? IMAP::ST_UID : IMAP::NIL); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function appendMessage($folder, $message, $flags = null, $date = null) { |
| 380 | 380 | if ($date != null) { |
| 381 | - if ($date instanceof \Carbon\Carbon){ |
|
| 381 | + if ($date instanceof \Carbon\Carbon) { |
|
| 382 | 382 | $date = $date->format('d-M-Y H:i:s O'); |
| 383 | 383 | } |
| 384 | 384 | return \imap_append($this->stream, $folder, $message, $flags, $date); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | * @return array|bool Tokens if operation successful, false if an error occurred |
| 411 | 411 | */ |
| 412 | 412 | public function copyManyMessages($messages, $folder, $uid = IMAP::ST_UID) { |
| 413 | - foreach($messages as $msg) { |
|
| 413 | + foreach ($messages as $msg) { |
|
| 414 | 414 | if ($this->copyMessage($folder, $msg, null, $uid) == false) { |
| 415 | 415 | return false; |
| 416 | 416 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | * @return array|bool Tokens if operation successful, false if an error occurred |
| 443 | 443 | */ |
| 444 | 444 | public function moveManyMessages($messages, $folder, $uid = IMAP::ST_UID) { |
| 445 | - foreach($messages as $msg) { |
|
| 445 | + foreach ($messages as $msg) { |
|
| 446 | 446 | if ($this->moveMessage($folder, $msg, null, $uid) == false) { |
| 447 | 447 | return false; |
| 448 | 448 | } |
@@ -565,14 +565,14 @@ discard block |
||
| 565 | 565 | /** |
| 566 | 566 | * Enable the debug mode |
| 567 | 567 | */ |
| 568 | - public function enableDebug(){ |
|
| 568 | + public function enableDebug() { |
|
| 569 | 569 | $this->debug = true; |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
| 573 | 573 | * Disable the debug mode |
| 574 | 574 | */ |
| 575 | - public function disableDebug(){ |
|
| 575 | + public function disableDebug() { |
|
| 576 | 576 | $this->debug = false; |
| 577 | 577 | } |
| 578 | 578 | |