@@ -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 | } |
@@ -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'; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return bool |
161 | 161 | */ |
162 | - public function connected(){ |
|
162 | + public function connected() { |
|
163 | 163 | return boolval($this->stream); |
164 | 164 | } |
165 | 165 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - public function headers($uids, $rfc = "RFC822", $uid = false){ |
|
234 | + public function headers($uids, $rfc = "RFC822", $uid = false) { |
|
235 | 235 | $result = []; |
236 | 236 | $uids = is_array($uids) ? $uids : [$uids]; |
237 | 237 | foreach ($uids as $id) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return array |
249 | 249 | */ |
250 | - public function flags($uids, $uid = false){ |
|
250 | + public function flags($uids, $uid = false) { |
|
251 | 251 | $result = []; |
252 | 252 | $uids = is_array($uids) ? $uids : [$uids]; |
253 | 253 | foreach ($uids as $id) { |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | $flags = []; |
256 | 256 | if (is_array($raw_flags) && isset($raw_flags[0])) { |
257 | 257 | $raw_flags = (array) $raw_flags[0]; |
258 | - foreach($raw_flags as $flag => $value) { |
|
259 | - if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false){ |
|
258 | + foreach ($raw_flags as $flag => $value) { |
|
259 | + if ($value === 1 && in_array($flag, ["size", "uid", "msgno", "update"]) === false) { |
|
260 | 260 | $flags[] = "\\".ucfirst($flag); |
261 | 261 | } |
262 | 262 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | if ($id === null) { |
278 | 278 | $overview = $this->overview("1:*"); |
279 | 279 | $uids = []; |
280 | - foreach($overview as $set){ |
|
280 | + foreach ($overview as $set) { |
|
281 | 281 | $uids[$set->msgno] = $set->uid; |
282 | 282 | } |
283 | 283 | return $uids; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @return array |
304 | 304 | */ |
305 | 305 | public function overview($sequence, $uid = false) { |
306 | - return \imap_fetch_overview($this->stream, $sequence,$uid ? IMAP::FT_UID : IMAP::NIL); |
|
306 | + return \imap_fetch_overview($this->stream, $sequence, $uid ? IMAP::FT_UID : IMAP::NIL); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | $result = []; |
319 | 319 | |
320 | 320 | $items = \imap_getmailboxes($this->stream, $this->getAddress(), $reference.$folder); |
321 | - if(is_array($items)){ |
|
321 | + if (is_array($items)) { |
|
322 | 322 | foreach ($items as $item) { |
323 | 323 | $name = $this->decodeFolderName($item->name); |
324 | 324 | $result[$name] = ['delimiter' => $item->delimiter, 'flags' => []]; |
325 | 325 | } |
326 | - }else{ |
|
326 | + }else { |
|
327 | 327 | throw new RuntimeException(\imap_last_error()); |
328 | 328 | } |
329 | 329 | |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | public function store(array $flags, $from, $to = null, $mode = null, $silent = true, $uid = false) { |
346 | 346 | $flag = trim(is_array($flags) ? implode(" ", $flags) : $flags); |
347 | 347 | |
348 | - if ($mode == "+"){ |
|
348 | + if ($mode == "+") { |
|
349 | 349 | $status = \imap_setflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL); |
350 | - }else{ |
|
350 | + }else { |
|
351 | 351 | $status = \imap_clearflag_full($this->stream, $from, $flag, $uid ? IMAP::FT_UID : IMAP::NIL); |
352 | 352 | } |
353 | 353 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | */ |
370 | 370 | public function appendMessage($folder, $message, $flags = null, $date = null) { |
371 | 371 | if ($date != null) { |
372 | - if ($date instanceof \Carbon\Carbon){ |
|
372 | + if ($date instanceof \Carbon\Carbon) { |
|
373 | 373 | $date = $date->format('d-M-Y H:i:s O'); |
374 | 374 | } |
375 | 375 | return \imap_append($this->stream, $folder, $message, $flags, $date); |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @return array|bool Tokens if operation successful, false if an error occurred |
402 | 402 | */ |
403 | 403 | public function copyManyMessages($messages, $folder, $uid = false) { |
404 | - foreach($messages as $msg) { |
|
404 | + foreach ($messages as $msg) { |
|
405 | 405 | if ($this->copyMessage($folder, $msg, null, $uid) == false) { |
406 | 406 | return false; |
407 | 407 | } |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * @return array|bool Tokens if operation successful, false if an error occurred |
434 | 434 | */ |
435 | 435 | public function moveManyMessages($messages, $folder, $uid = false) { |
436 | - foreach($messages as $msg) { |
|
436 | + foreach ($messages as $msg) { |
|
437 | 437 | if ($this->moveMessage($folder, $msg, null, $uid) == false) { |
438 | 438 | return false; |
439 | 439 | } |
@@ -542,14 +542,14 @@ discard block |
||
542 | 542 | /** |
543 | 543 | * Enable the debug mode |
544 | 544 | */ |
545 | - public function enableDebug(){ |
|
545 | + public function enableDebug() { |
|
546 | 546 | $this->debug = true; |
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
550 | 550 | * Disable the debug mode |
551 | 551 | */ |
552 | - public function disableDebug(){ |
|
552 | + public function disableDebug() { |
|
553 | 553 | $this->debug = false; |
554 | 554 | } |
555 | 555 |