@@ -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); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $this->parseDate($header); |
| 150 | 150 | foreach ($header as $key => $value) { |
| 151 | 151 | $key = trim(rtrim(strtolower($key))); |
| 152 | - if(!isset($this->attributes[$key])){ |
|
| 152 | + if (!isset($this->attributes[$key])) { |
|
| 153 | 153 | $this->attributes[$key] = $value; |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return object |
| 167 | 167 | */ |
| 168 | - public function rfc822_parse_headers($raw_headers){ |
|
| 168 | + public function rfc822_parse_headers($raw_headers) { |
|
| 169 | 169 | $headers = []; |
| 170 | 170 | $imap_headers = []; |
| 171 | 171 | if (extension_loaded('imap')) { |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $lines = explode("\r\n", $raw_headers); |
| 176 | 176 | $prev_header = null; |
| 177 | - foreach($lines as $line) { |
|
| 177 | + foreach ($lines as $line) { |
|
| 178 | 178 | if (substr($line, 0, 1) === "\t") { |
| 179 | 179 | $line = substr($line, 2); |
| 180 | 180 | if ($prev_header !== null) { |
| 181 | 181 | $headers[$prev_header][] = $line; |
| 182 | 182 | } |
| 183 | - }else{ |
|
| 183 | + }else { |
|
| 184 | 184 | if (($pos = strpos($line, ":")) > 0) { |
| 185 | 185 | $key = strtolower(substr($line, 0, $pos)); |
| 186 | 186 | $value = trim(rtrim(strtolower(substr($line, $pos + 1)))); |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - foreach($headers as $key => $values) { |
|
| 193 | + foreach ($headers as $key => $values) { |
|
| 194 | 194 | if (isset($imap_headers[$key])) continue; |
| 195 | 195 | $value = null; |
| 196 | - switch($key){ |
|
| 196 | + switch ($key) { |
|
| 197 | 197 | case 'from': |
| 198 | 198 | case 'to': |
| 199 | 199 | case 'cc': |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * @return array The decoded elements are returned in an array of objects, where each |
| 222 | 222 | * object has two properties, charset and text. |
| 223 | 223 | */ |
| 224 | - public function mime_header_decode($text){ |
|
| 224 | + public function mime_header_decode($text) { |
|
| 225 | 225 | if (extension_loaded('imap')) { |
| 226 | 226 | return \imap_mime_header_decode($text); |
| 227 | 227 | } |
| 228 | 228 | $charset = $this->getEncoding($text); |
| 229 | - return [(object)[ |
|
| 229 | + return [(object) [ |
|
| 230 | 230 | "charset" => $charset, |
| 231 | 231 | "text" => $this->convertEncoding($text, $charset) |
| 232 | 232 | ]]; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | try { |
| 281 | 281 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 282 | 282 | return iconv($from, $to, $str); |
| 283 | - } else { |
|
| 283 | + }else { |
|
| 284 | 284 | if (!$from) { |
| 285 | 285 | return mb_convert_encoding($str, $to); |
| 286 | 286 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | if (strstr($from, '-')) { |
| 291 | 291 | $from = str_replace('-', '', $from); |
| 292 | 292 | return $this->convertEncoding($str, $from, $to); |
| 293 | - } else { |
|
| 293 | + }else { |
|
| 294 | 294 | return $str; |
| 295 | 295 | } |
| 296 | 296 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | }elseif (property_exists($structure, 'charset')) { |
| 313 | 313 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 314 | - }elseif (is_string($structure) === true){ |
|
| 314 | + }elseif (is_string($structure) === true) { |
|
| 315 | 315 | return mb_detect_encoding($structure); |
| 316 | 316 | } |
| 317 | 317 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $decoder = $this->config['decoder']['message']; |
| 330 | 330 | |
| 331 | 331 | if ($value !== null) { |
| 332 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 332 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 333 | 333 | $value = \imap_utf8($value); |
| 334 | 334 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
| 335 | 335 | $value = mb_decode_mimeheader($value); |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | if ($this->notDecoded($original_value, $value)) { |
| 338 | 338 | $decoded_value = $this->mime_header_decode($value); |
| 339 | 339 | if (count($decoded_value) > 0) { |
| 340 | - if(property_exists($decoded_value[0], "text")) { |
|
| 340 | + if (property_exists($decoded_value[0], "text")) { |
|
| 341 | 341 | $value = $decoded_value[0]->text; |
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | - }elseif($decoder === 'iconv') { |
|
| 345 | + }elseif ($decoder === 'iconv') { |
|
| 346 | 346 | $value = iconv_mime_decode($value); |
| 347 | - }else{ |
|
| 347 | + }else { |
|
| 348 | 348 | $value = mb_decode_mimeheader($value); |
| 349 | 349 | } |
| 350 | 350 | |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | * Try to extract the priority from a given raw header string |
| 365 | 365 | */ |
| 366 | 366 | private function findPriority() { |
| 367 | - if(($priority = $this->get("x-priority")) === null) return; |
|
| 368 | - switch($priority){ |
|
| 367 | + if (($priority = $this->get("x-priority")) === null) return; |
|
| 368 | + switch ($priority) { |
|
| 369 | 369 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 370 | 370 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 371 | 371 | break; |
@@ -397,12 +397,12 @@ discard block |
||
| 397 | 397 | */ |
| 398 | 398 | private function decodeAddresses($values) { |
| 399 | 399 | $addresses = []; |
| 400 | - foreach($values as $address) { |
|
| 400 | + foreach ($values as $address) { |
|
| 401 | 401 | if (preg_match( |
| 402 | 402 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
| 403 | 403 | $address, |
| 404 | 404 | $matches |
| 405 | - )){ |
|
| 405 | + )) { |
|
| 406 | 406 | $name = trim(rtrim($matches["name"])); |
| 407 | 407 | $email = trim(rtrim($matches["email"])); |
| 408 | 408 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * @param object $header |
| 422 | 422 | */ |
| 423 | 423 | private function extractAddresses($header) { |
| 424 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key){ |
|
| 424 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key) { |
|
| 425 | 425 | if (property_exists($header, $key)) { |
| 426 | 426 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
| 427 | 427 | } |
@@ -448,10 +448,10 @@ discard block |
||
| 448 | 448 | } |
| 449 | 449 | if (!property_exists($address, 'personal')) { |
| 450 | 450 | $address->personal = false; |
| 451 | - } else { |
|
| 451 | + }else { |
|
| 452 | 452 | $personalParts = $this->mime_header_decode($address->personal); |
| 453 | 453 | |
| 454 | - if(is_array($personalParts)) { |
|
| 454 | + if (is_array($personalParts)) { |
|
| 455 | 455 | $address->personal = ''; |
| 456 | 456 | foreach ($personalParts as $p) { |
| 457 | 457 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -471,15 +471,15 @@ discard block |
||
| 471 | 471 | /** |
| 472 | 472 | * Search and extract potential header extensions |
| 473 | 473 | */ |
| 474 | - private function extractHeaderExtensions(){ |
|
| 474 | + private function extractHeaderExtensions() { |
|
| 475 | 475 | foreach ($this->attributes as $key => $value) { |
| 476 | 476 | if (is_string($value) === true) { |
| 477 | - if (($pos = strpos($value, ";")) !== false){ |
|
| 477 | + if (($pos = strpos($value, ";")) !== false) { |
|
| 478 | 478 | $original = substr($value, 0, $pos); |
| 479 | 479 | $this->attributes[$key] = trim(rtrim($original)); |
| 480 | 480 | $extensions = explode(";", substr($value, $pos + 1)); |
| 481 | - foreach($extensions as $extension) { |
|
| 482 | - if (($pos = strpos($extension, "=")) !== false){ |
|
| 481 | + foreach ($extensions as $extension) { |
|
| 482 | + if (($pos = strpos($extension, "=")) !== false) { |
|
| 483 | 483 | $key = substr($extension, 0, $pos); |
| 484 | 484 | $value = substr($extension, $pos + 1); |
| 485 | 485 | $value = str_replace('"', "", $value); |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | $parsed_date = null; |
| 517 | 517 | $date = $header->date; |
| 518 | 518 | |
| 519 | - if(preg_match('/\+0580/', $date)) { |
|
| 519 | + if (preg_match('/\+0580/', $date)) { |
|
| 520 | 520 | $date = str_replace('+0580', '+0530', $date); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | $date = trim(array_pop($array)); |
| 540 | 540 | break; |
| 541 | 541 | } |
| 542 | - try{ |
|
| 542 | + try { |
|
| 543 | 543 | $parsed_date = Carbon::parse($date); |
| 544 | 544 | } catch (\Exception $_e) { |
| 545 | 545 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |