@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $this->part_number = $part->part_number; |
| 104 | 104 | |
| 105 | 105 | $default_mask = $this->oMessage->getClient()->getDefaultAttachmentMask(); |
| 106 | - if($default_mask != null) { |
|
| 106 | + if ($default_mask != null) { |
|
| 107 | 107 | $this->mask = $default_mask; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * @throws MethodNotFoundException |
| 121 | 121 | */ |
| 122 | 122 | public function __call(string $method, array $arguments) { |
| 123 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 123 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 124 | 124 | $name = Str::snake(substr($method, 3)); |
| 125 | 125 | |
| 126 | - if(isset($this->attributes[$name])) { |
|
| 126 | + if (isset($this->attributes[$name])) { |
|
| 127 | 127 | return $this->attributes[$name]; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @return mixed|null |
| 160 | 160 | */ |
| 161 | 161 | public function __get($name) { |
| 162 | - if(isset($this->attributes[$name])) { |
|
| 162 | + if (isset($this->attributes[$name])) { |
|
| 163 | 163 | return $this->attributes[$name]; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | if (($id = $this->part->id) !== null) { |
| 215 | 215 | $this->id = str_replace(['<', '>'], '', $id); |
| 216 | - }else{ |
|
| 217 | - $this->id = hash("sha256", (string)microtime(true)); |
|
| 216 | + }else { |
|
| 217 | + $this->id = hash("sha256", (string) microtime(true)); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | $this->size = $this->part->bytes; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | if (IMAP::ATTACHMENT_TYPE_MESSAGE == $this->part->type) { |
| 232 | 232 | if ($this->part->ifdescription) { |
| 233 | 233 | $this->setName($this->part->description); |
| 234 | - } else { |
|
| 234 | + }else { |
|
| 235 | 235 | $this->setName($this->part->subtype); |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | public function setName($name) { |
| 258 | 258 | $decoder = $this->config['decoder']['attachment']; |
| 259 | 259 | if ($name !== null) { |
| 260 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 260 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 261 | 261 | $this->name = \imap_utf8($name); |
| 262 | - }else{ |
|
| 262 | + }else { |
|
| 263 | 263 | $this->name = mb_decode_mimeheader($name); |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return string|null |
| 272 | 272 | */ |
| 273 | - public function getMimeType(){ |
|
| 273 | + public function getMimeType() { |
|
| 274 | 274 | return (new \finfo())->buffer($this->getContent(), FILEINFO_MIME_TYPE); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return string|null |
| 281 | 281 | */ |
| 282 | - public function getExtension(){ |
|
| 282 | + public function getExtension() { |
|
| 283 | 283 | $guesser = "\Symfony\Component\Mime\MimeTypes"; |
| 284 | 284 | if (class_exists($guesser) !== false) { |
| 285 | 285 | /** @var Symfony\Component\Mime\MimeTypes $guesser */ |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $deprecated_guesser = "\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser"; |
| 291 | - if (class_exists($deprecated_guesser) !== false){ |
|
| 291 | + if (class_exists($deprecated_guesser) !== false) { |
|
| 292 | 292 | /** @var \Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser $deprecated_guesser */ |
| 293 | 293 | return $deprecated_guesser::getInstance()->guess($this->getMimeType()); |
| 294 | 294 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @return $this |
| 320 | 320 | */ |
| 321 | 321 | public function setMask($mask): Attachment { |
| 322 | - if(class_exists($mask)){ |
|
| 322 | + if (class_exists($mask)) { |
|
| 323 | 323 | $this->mask = $mask; |
| 324 | 324 | } |
| 325 | 325 | |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | * @return mixed |
| 343 | 343 | * @throws MaskNotFoundException |
| 344 | 344 | */ |
| 345 | - public function mask($mask = null){ |
|
| 345 | + public function mask($mask = null) { |
|
| 346 | 346 | $mask = $mask !== null ? $mask : $this->mask; |
| 347 | - if(class_exists($mask)){ |
|
| 347 | + if (class_exists($mask)) { |
|
| 348 | 348 | return new $mask($this); |
| 349 | 349 | } |
| 350 | 350 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return null; |
| 131 | - }elseif (strtolower(substr($method, 0, 3)) === 'set') { |
|
| 131 | + } elseif (strtolower(substr($method, 0, 3)) === 'set') { |
|
| 132 | 132 | $name = Str::snake(substr($method, 3)); |
| 133 | 133 | |
| 134 | 134 | $this->attributes[$name] = array_pop($arguments); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | if (($id = $this->part->id) !== null) { |
| 215 | 215 | $this->id = str_replace(['<', '>'], '', $id); |
| 216 | - }else{ |
|
| 216 | + } else{ |
|
| 217 | 217 | $this->id = hash("sha256", (string)microtime(true)); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $this->setName($filename); |
| 225 | 225 | } elseif (($name = $this->part->name) !== null) { |
| 226 | 226 | $this->setName($name); |
| 227 | - }else { |
|
| 227 | + } else { |
|
| 228 | 228 | $this->setName("undefined"); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | if ($name !== null) { |
| 260 | 260 | if($decoder === 'utf-8' && extension_loaded('imap')) { |
| 261 | 261 | $this->name = \imap_utf8($name); |
| 262 | - }else{ |
|
| 262 | + } else{ |
|
| 263 | 263 | $this->name = mb_decode_mimeheader($name); |
| 264 | 264 | } |
| 265 | 265 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @throws ImapServerErrorException |
| 96 | 96 | * @throws RuntimeException |
| 97 | 97 | */ |
| 98 | - protected function enableStartTls(){ |
|
| 98 | + protected function enableStartTls() { |
|
| 99 | 99 | $response = $this->requestAndResponse('STARTTLS'); |
| 100 | 100 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
| 101 | 101 | if (!$result) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | throw new RuntimeException('empty response'); |
| 119 | 119 | } |
| 120 | 120 | if ($this->debug) echo "<< ".$line."\n"; |
| 121 | - return $line . "\n"; |
|
| 121 | + return $line."\n"; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $stack = []; |
| 172 | 172 | |
| 173 | 173 | // replace any trailing <NL> including spaces with a single space |
| 174 | - $line = rtrim($line) . ' '; |
|
| 174 | + $line = rtrim($line).' '; |
|
| 175 | 175 | while (($pos = strpos($line, ' ')) !== false) { |
| 176 | 176 | $token = substr($line, 0, $pos); |
| 177 | 177 | if (!strlen($token)) { |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | if (strlen($token) > $chars) { |
| 203 | 203 | $line = substr($token, $chars); |
| 204 | 204 | $token = substr($token, 0, $chars); |
| 205 | - } else { |
|
| 205 | + }else { |
|
| 206 | 206 | $line .= $this->nextLine(); |
| 207 | 207 | } |
| 208 | 208 | $tokens[] = $token; |
| 209 | - $line = trim($line) . ' '; |
|
| 209 | + $line = trim($line).' '; |
|
| 210 | 210 | continue; |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $line = $this->nextTaggedLine($tag); // get next tag |
| 257 | 257 | if (!$dontParse) { |
| 258 | 258 | $tokens = $this->decodeLine($line); |
| 259 | - } else { |
|
| 259 | + }else { |
|
| 260 | 260 | $tokens = $line; |
| 261 | 261 | } |
| 262 | 262 | |
@@ -310,20 +310,20 @@ discard block |
||
| 310 | 310 | public function sendRequest(string $command, array $tokens = [], string &$tag = null) { |
| 311 | 311 | if (!$tag) { |
| 312 | 312 | $this->noun++; |
| 313 | - $tag = 'TAG' . $this->noun; |
|
| 313 | + $tag = 'TAG'.$this->noun; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $line = $tag . ' ' . $command; |
|
| 316 | + $line = $tag.' '.$command; |
|
| 317 | 317 | |
| 318 | 318 | foreach ($tokens as $token) { |
| 319 | 319 | if (is_array($token)) { |
| 320 | - $this->write($line . ' ' . $token[0]); |
|
| 320 | + $this->write($line.' '.$token[0]); |
|
| 321 | 321 | if (!$this->assumedNextLine('+ ')) { |
| 322 | 322 | throw new RuntimeException('failed to send literal string'); |
| 323 | 323 | } |
| 324 | 324 | $line = $token[1]; |
| 325 | - } else { |
|
| 326 | - $line .= ' ' . $token; |
|
| 325 | + }else { |
|
| 326 | + $line .= ' '.$token; |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | $this->write($line); |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | * @throws RuntimeException |
| 337 | 337 | */ |
| 338 | 338 | public function write(string $data) { |
| 339 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 339 | + if ($this->debug) echo ">> ".$data."\n"; |
|
| 340 | 340 | |
| 341 | - if (fwrite($this->stream, $data . "\r\n") === false) { |
|
| 341 | + if (fwrite($this->stream, $data."\r\n") === false) { |
|
| 342 | 342 | throw new RuntimeException('failed to write - connection closed?'); |
| 343 | 343 | } |
| 344 | 344 | } |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | public function escapeString($string) { |
| 373 | 373 | if (func_num_args() < 2) { |
| 374 | 374 | if (str_contains($string, "\n")) { |
| 375 | - return ['{' . strlen($string) . '}', $string]; |
|
| 376 | - } else { |
|
| 377 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
| 375 | + return ['{'.strlen($string).'}', $string]; |
|
| 376 | + }else { |
|
| 377 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | $result = []; |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | $result[] = $this->escapeList($v); |
| 401 | 401 | } |
| 402 | - return '(' . implode(' ', $result) . ')'; |
|
| 402 | + return '('.implode(' ', $result).')'; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -445,12 +445,12 @@ discard block |
||
| 445 | 445 | error_log("got an extra server challenge: $response"); |
| 446 | 446 | // respond with an empty response. |
| 447 | 447 | $this->sendRequest(''); |
| 448 | - } else { |
|
| 448 | + }else { |
|
| 449 | 449 | if (preg_match('/^NO /i', $response) || |
| 450 | 450 | preg_match('/^BAD /i', $response)) { |
| 451 | 451 | error_log("got failure response: $response"); |
| 452 | 452 | return false; |
| 453 | - } else if (preg_match("/^OK /i", $response)) { |
|
| 453 | + }else if (preg_match("/^OK /i", $response)) { |
|
| 454 | 454 | return true; |
| 455 | 455 | } |
| 456 | 456 | } |
@@ -535,16 +535,16 @@ discard block |
||
| 535 | 535 | switch ($tokens[1]) { |
| 536 | 536 | case 'EXISTS': |
| 537 | 537 | case 'RECENT': |
| 538 | - $result[strtolower($tokens[1])] = (int)$tokens[0]; |
|
| 538 | + $result[strtolower($tokens[1])] = (int) $tokens[0]; |
|
| 539 | 539 | break; |
| 540 | 540 | case '[UIDVALIDITY': |
| 541 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
| 541 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
| 542 | 542 | break; |
| 543 | 543 | case '[UIDNEXT': |
| 544 | - $result['uidnext'] = (int)$tokens[2]; |
|
| 544 | + $result['uidnext'] = (int) $tokens[2]; |
|
| 545 | 545 | break; |
| 546 | 546 | case '[UNSEEN': |
| 547 | - $result['unseen'] = (int)$tokens[2]; |
|
| 547 | + $result['unseen'] = (int) $tokens[2]; |
|
| 548 | 548 | break; |
| 549 | 549 | case '[NONEXISTENT]': |
| 550 | 550 | throw new RuntimeException("folder doesn't exist"); |
@@ -603,14 +603,14 @@ discard block |
||
| 603 | 603 | if (is_array($from)) { |
| 604 | 604 | $set = implode(',', $from); |
| 605 | 605 | } elseif ($to === null) { |
| 606 | - $set = (int)$from; |
|
| 606 | + $set = (int) $from; |
|
| 607 | 607 | } elseif ($to === INF) { |
| 608 | - $set = (int)$from . ':*'; |
|
| 609 | - } else { |
|
| 610 | - $set = (int)$from . ':' . (int)$to; |
|
| 608 | + $set = (int) $from.':*'; |
|
| 609 | + }else { |
|
| 610 | + $set = (int) $from.':'.(int) $to; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - $items = (array)$items; |
|
| 613 | + $items = (array) $items; |
|
| 614 | 614 | $itemList = $this->escapeList($items); |
| 615 | 615 | |
| 616 | 616 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -627,9 +627,9 @@ discard block |
||
| 627 | 627 | $count = count($tokens[2]); |
| 628 | 628 | if ($tokens[2][$count - 2] == 'UID') { |
| 629 | 629 | $uidKey = $count - 1; |
| 630 | - } else if ($tokens[2][0] == 'UID') { |
|
| 630 | + }else if ($tokens[2][0] == 'UID') { |
|
| 631 | 631 | $uidKey = 1; |
| 632 | - } else { |
|
| 632 | + }else { |
|
| 633 | 633 | $found = array_search('UID', $tokens[2]); |
| 634 | 634 | if ($found === false || $found === -1) { |
| 635 | 635 | continue; |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | $data = $tokens[2][1]; |
| 651 | 651 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
| 652 | 652 | $data = $tokens[2][3]; |
| 653 | - } else { |
|
| 653 | + }else { |
|
| 654 | 654 | $expectedResponse = 0; |
| 655 | 655 | // maybe the server send an other field we didn't wanted |
| 656 | 656 | $count = count($tokens[2]); |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | continue; |
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | - } else { |
|
| 670 | + }else { |
|
| 671 | 671 | $data = []; |
| 672 | 672 | while (key($tokens[2]) !== null) { |
| 673 | 673 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | if ($uid) { |
| 686 | 686 | $result[$tokens[2][$uidKey]] = $data; |
| 687 | - }else{ |
|
| 687 | + }else { |
|
| 688 | 688 | $result[$tokens[0]] = $data; |
| 689 | 689 | } |
| 690 | 690 | } |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | $ids = $this->getUid(); |
| 786 | 786 | foreach ($ids as $k => $v) { |
| 787 | 787 | if ($v == $id) { |
| 788 | - return (int)$k; |
|
| 788 | + return (int) $k; |
|
| 789 | 789 | } |
| 790 | 790 | } |
| 791 | 791 | |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | */ |
| 1119 | 1119 | public function getQuota($username): array { |
| 1120 | 1120 | $command = "GETQUOTA"; |
| 1121 | - $params = ['"#user/' . $username . '"']; |
|
| 1121 | + $params = ['"#user/'.$username.'"']; |
|
| 1122 | 1122 | |
| 1123 | 1123 | return $this->requestAndResponse($command, $params); |
| 1124 | 1124 | } |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | $ids = []; |
| 1211 | 1211 | foreach ($uids as $msgn => $v) { |
| 1212 | 1212 | $id = $uid ? $v : $msgn; |
| 1213 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
| 1213 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
| 1214 | 1214 | $ids[] = $id; |
| 1215 | 1215 | } |
| 1216 | 1216 | } |
@@ -1224,14 +1224,14 @@ discard block |
||
| 1224 | 1224 | /** |
| 1225 | 1225 | * Enable the debug mode |
| 1226 | 1226 | */ |
| 1227 | - public function enableDebug(){ |
|
| 1227 | + public function enableDebug() { |
|
| 1228 | 1228 | $this->debug = true; |
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
| 1232 | 1232 | * Disable the debug mode |
| 1233 | 1233 | */ |
| 1234 | - public function disableDebug(){ |
|
| 1234 | + public function disableDebug() { |
|
| 1235 | 1235 | $this->debug = false; |
| 1236 | 1236 | } |
| 1237 | 1237 | |
@@ -1243,9 +1243,9 @@ discard block |
||
| 1243 | 1243 | * @return int|string |
| 1244 | 1244 | */ |
| 1245 | 1245 | public function buildSet($from, $to = null) { |
| 1246 | - $set = (int)$from; |
|
| 1246 | + $set = (int) $from; |
|
| 1247 | 1247 | if ($to !== null) { |
| 1248 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
| 1248 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | return $set; |
| 1251 | 1251 | } |
@@ -117,7 +117,9 @@ discard block |
||
| 117 | 117 | if ($line === "" && $next_char === false) { |
| 118 | 118 | throw new RuntimeException('empty response'); |
| 119 | 119 | } |
| 120 | - if ($this->debug) echo "<< ".$line."\n"; |
|
| 120 | + if ($this->debug) { |
|
| 121 | + echo "<< ".$line."\n"; |
|
| 122 | + } |
|
| 121 | 123 | return $line . "\n"; |
| 122 | 124 | } |
| 123 | 125 | |
@@ -336,7 +338,9 @@ discard block |
||
| 336 | 338 | * @throws RuntimeException |
| 337 | 339 | */ |
| 338 | 340 | public function write(string $data) { |
| 339 | - if ($this->debug) echo ">> ".$data ."\n"; |
|
| 341 | + if ($this->debug) { |
|
| 342 | + echo ">> ".$data ."\n"; |
|
| 343 | + } |
|
| 340 | 344 | |
| 341 | 345 | if (fwrite($this->stream, $data . "\r\n") === false) { |
| 342 | 346 | throw new RuntimeException('failed to write - connection closed?'); |
@@ -504,7 +508,9 @@ discard block |
||
| 504 | 508 | public function getCapabilities(): array { |
| 505 | 509 | $response = $this->requestAndResponse('CAPABILITY'); |
| 506 | 510 | |
| 507 | - if (!$response) return []; |
|
| 511 | + if (!$response) { |
|
| 512 | + return []; |
|
| 513 | + } |
|
| 508 | 514 | |
| 509 | 515 | $capabilities = []; |
| 510 | 516 | foreach ($response as $line) { |
@@ -678,13 +684,14 @@ discard block |
||
| 678 | 684 | // if we want only one message we can ignore everything else and just return |
| 679 | 685 | if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) { |
| 680 | 686 | // we still need to read all lines |
| 681 | - while (!$this->readLine($tokens, $tag)) |
|
| 682 | - |
|
| 687 | + while (!$this->readLine($tokens, $tag)) { |
|
| 688 | + |
|
| 683 | 689 | return $data; |
| 690 | + } |
|
| 684 | 691 | } |
| 685 | 692 | if ($uid) { |
| 686 | 693 | $result[$tokens[2][$uidKey]] = $data; |
| 687 | - }else{ |
|
| 694 | + } else{ |
|
| 688 | 695 | $result[$tokens[0]] = $data; |
| 689 | 696 | } |
| 690 | 697 | } |