@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | * @throws MethodNotFoundException |
| 74 | 74 | */ |
| 75 | 75 | public function __call($method, $arguments) { |
| 76 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 76 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 77 | 77 | $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3)); |
| 78 | 78 | |
| 79 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 79 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 80 | 80 | return $this->attributes[$name]; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return mixed|null |
| 103 | 103 | */ |
| 104 | 104 | public function get($name) { |
| 105 | - if(isset($this->attributes[$name])) { |
|
| 105 | + if (isset($this->attributes[$name])) { |
|
| 106 | 106 | return $this->attributes[$name]; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function find($pattern) { |
| 119 | 119 | if (preg_match_all($pattern, $this->raw, $matches)) { |
| 120 | 120 | if (isset($matches[1])) { |
| 121 | - if(count($matches[1]) > 0) { |
|
| 121 | + if (count($matches[1]) > 0) { |
|
| 122 | 122 | return $matches[1][0]; |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @throws InvalidMessageDateException |
| 133 | 133 | */ |
| 134 | - protected function parse(){ |
|
| 134 | + protected function parse() { |
|
| 135 | 135 | $header = $this->rfc822_parse_headers($this->raw); |
| 136 | 136 | |
| 137 | 137 | $this->extractAddresses($header); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $this->parseDate($header); |
| 153 | 153 | foreach ($header as $key => $value) { |
| 154 | 154 | $key = trim(rtrim(strtolower($key))); |
| 155 | - if(!isset($this->attributes[$key])){ |
|
| 155 | + if (!isset($this->attributes[$key])) { |
|
| 156 | 156 | $this->attributes[$key] = $value; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return object |
| 170 | 170 | */ |
| 171 | - public function rfc822_parse_headers($raw_headers){ |
|
| 171 | + public function rfc822_parse_headers($raw_headers) { |
|
| 172 | 172 | $headers = []; |
| 173 | 173 | $imap_headers = []; |
| 174 | 174 | if (extension_loaded('imap')) { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $lines = explode("\r\n", $raw_headers); |
| 179 | 179 | $prev_header = null; |
| 180 | - foreach($lines as $line) { |
|
| 180 | + foreach ($lines as $line) { |
|
| 181 | 181 | if (substr($line, 0, 1) === "\n") { |
| 182 | 182 | $line = substr($line, 1); |
| 183 | 183 | } |
@@ -197,11 +197,11 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | if (is_array($headers[$prev_header])) { |
| 199 | 199 | $headers[$prev_header][] = $line; |
| 200 | - }else{ |
|
| 200 | + }else { |
|
| 201 | 201 | $headers[$prev_header] .= $line; |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | - }else{ |
|
| 204 | + }else { |
|
| 205 | 205 | if (($pos = strpos($line, ":")) > 0) { |
| 206 | 206 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
| 207 | 207 | $value = trim(rtrim(substr($line, $pos + 1))); |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - foreach($headers as $key => $values) { |
|
| 214 | + foreach ($headers as $key => $values) { |
|
| 215 | 215 | if (isset($imap_headers[$key])) continue; |
| 216 | 216 | $value = null; |
| 217 | - switch($key){ |
|
| 217 | + switch ($key) { |
|
| 218 | 218 | case 'from': |
| 219 | 219 | case 'to': |
| 220 | 220 | case 'cc': |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | break; |
| 230 | 230 | default: |
| 231 | 231 | if (is_array($values)) { |
| 232 | - foreach($values as $k => $v) { |
|
| 232 | + foreach ($values as $k => $v) { |
|
| 233 | 233 | if ($v == "") { |
| 234 | 234 | unset($values[$k]); |
| 235 | 235 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $value = implode(" ", $values); |
| 242 | 242 | } elseif ($available_values > 2) { |
| 243 | 243 | $value = array_values($values); |
| 244 | - } else { |
|
| 244 | + }else { |
|
| 245 | 245 | $value = ""; |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -261,12 +261,12 @@ discard block |
||
| 261 | 261 | * @return array The decoded elements are returned in an array of objects, where each |
| 262 | 262 | * object has two properties, charset and text. |
| 263 | 263 | */ |
| 264 | - public function mime_header_decode($text){ |
|
| 264 | + public function mime_header_decode($text) { |
|
| 265 | 265 | if (extension_loaded('imap')) { |
| 266 | 266 | return \imap_mime_header_decode($text); |
| 267 | 267 | } |
| 268 | 268 | $charset = $this->getEncoding($text); |
| 269 | - return [(object)[ |
|
| 269 | + return [(object) [ |
|
| 270 | 270 | "charset" => $charset, |
| 271 | 271 | "text" => $this->convertEncoding($text, $charset) |
| 272 | 272 | ]]; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | try { |
| 321 | 321 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 322 | 322 | return iconv($from, $to, $str); |
| 323 | - } else { |
|
| 323 | + }else { |
|
| 324 | 324 | if (!$from) { |
| 325 | 325 | return mb_convert_encoding($str, $to); |
| 326 | 326 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | if (strstr($from, '-')) { |
| 331 | 331 | $from = str_replace('-', '', $from); |
| 332 | 332 | return $this->convertEncoding($str, $from, $to); |
| 333 | - } else { |
|
| 333 | + }else { |
|
| 334 | 334 | return $str; |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | }elseif (property_exists($structure, 'charset')) { |
| 353 | 353 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 354 | - }elseif (is_string($structure) === true){ |
|
| 354 | + }elseif (is_string($structure) === true) { |
|
| 355 | 355 | return mb_detect_encoding($structure); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $decoder = $this->config['decoder']['message']; |
| 370 | 370 | |
| 371 | 371 | if ($value !== null) { |
| 372 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 372 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 373 | 373 | $value = \imap_utf8($value); |
| 374 | 374 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
| 375 | 375 | $value = mb_decode_mimeheader($value); |
@@ -377,14 +377,14 @@ discard block |
||
| 377 | 377 | if ($this->notDecoded($original_value, $value)) { |
| 378 | 378 | $decoded_value = $this->mime_header_decode($value); |
| 379 | 379 | if (count($decoded_value) > 0) { |
| 380 | - if(property_exists($decoded_value[0], "text")) { |
|
| 380 | + if (property_exists($decoded_value[0], "text")) { |
|
| 381 | 381 | $value = $decoded_value[0]->text; |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | - }elseif($decoder === 'iconv') { |
|
| 385 | + }elseif ($decoder === 'iconv') { |
|
| 386 | 386 | $value = iconv_mime_decode($value); |
| 387 | - }else{ |
|
| 387 | + }else { |
|
| 388 | 388 | $value = mb_decode_mimeheader($value); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -404,8 +404,8 @@ discard block |
||
| 404 | 404 | * Try to extract the priority from a given raw header string |
| 405 | 405 | */ |
| 406 | 406 | private function findPriority() { |
| 407 | - if(($priority = $this->get("x-priority")) === null) return; |
|
| 408 | - switch($priority){ |
|
| 407 | + if (($priority = $this->get("x-priority")) === null) return; |
|
| 408 | + switch ($priority) { |
|
| 409 | 409 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 410 | 410 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 411 | 411 | break; |
@@ -437,12 +437,12 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | private function decodeAddresses($values) { |
| 439 | 439 | $addresses = []; |
| 440 | - foreach($values as $address) { |
|
| 440 | + foreach ($values as $address) { |
|
| 441 | 441 | if (preg_match( |
| 442 | 442 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
| 443 | 443 | $address, |
| 444 | 444 | $matches |
| 445 | - )){ |
|
| 445 | + )) { |
|
| 446 | 446 | $name = trim(rtrim($matches["name"])); |
| 447 | 447 | $email = trim(rtrim($matches["email"])); |
| 448 | 448 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @param object $header |
| 462 | 462 | */ |
| 463 | 463 | private function extractAddresses($header) { |
| 464 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
| 464 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
| 465 | 465 | if (property_exists($header, $key)) { |
| 466 | 466 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
| 467 | 467 | } |
@@ -492,10 +492,10 @@ discard block |
||
| 492 | 492 | } |
| 493 | 493 | if (!property_exists($address, 'personal')) { |
| 494 | 494 | $address->personal = false; |
| 495 | - } else { |
|
| 495 | + }else { |
|
| 496 | 496 | $personalParts = $this->mime_header_decode($address->personal); |
| 497 | 497 | |
| 498 | - if(is_array($personalParts)) { |
|
| 498 | + if (is_array($personalParts)) { |
|
| 499 | 499 | $address->personal = ''; |
| 500 | 500 | foreach ($personalParts as $p) { |
| 501 | 501 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -515,18 +515,18 @@ discard block |
||
| 515 | 515 | /** |
| 516 | 516 | * Search and extract potential header extensions |
| 517 | 517 | */ |
| 518 | - private function extractHeaderExtensions(){ |
|
| 518 | + private function extractHeaderExtensions() { |
|
| 519 | 519 | foreach ($this->attributes as $key => $value) { |
| 520 | 520 | // Only parse strings and don't parse any attributes like the user-agent |
| 521 | 521 | if (is_string($value) === true && in_array($key, ["user-agent"]) === false) { |
| 522 | - if (($pos = strpos($value, ";")) !== false){ |
|
| 522 | + if (($pos = strpos($value, ";")) !== false) { |
|
| 523 | 523 | $original = substr($value, 0, $pos); |
| 524 | 524 | $this->attributes[$key] = trim(rtrim($original)); |
| 525 | 525 | |
| 526 | 526 | // Get all potential extensions |
| 527 | 527 | $extensions = explode(";", substr($value, $pos + 1)); |
| 528 | - foreach($extensions as $extension) { |
|
| 529 | - if (($pos = strpos($extension, "=")) !== false){ |
|
| 528 | + foreach ($extensions as $extension) { |
|
| 529 | + if (($pos = strpos($extension, "=")) !== false) { |
|
| 530 | 530 | $key = substr($extension, 0, $pos); |
| 531 | 531 | $key = trim(rtrim(strtolower($key))); |
| 532 | 532 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | $parsed_date = null; |
| 570 | 570 | $date = $header->date; |
| 571 | 571 | |
| 572 | - if(preg_match('/\+0580/', $date)) { |
|
| 572 | + if (preg_match('/\+0580/', $date)) { |
|
| 573 | 573 | $date = str_replace('+0580', '+0530', $date); |
| 574 | 574 | } |
| 575 | 575 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | $date = trim(array_pop($array)); |
| 593 | 593 | break; |
| 594 | 594 | } |
| 595 | - try{ |
|
| 595 | + try { |
|
| 596 | 596 | $parsed_date = Carbon::parse($date); |
| 597 | 597 | } catch (\Exception $_e) { |
| 598 | 598 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |