@@ -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,12 +168,12 @@ 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')) { |
| 175 | 175 | $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw); |
| 176 | - foreach($raw_imap_headers as $key => $values) { |
|
| 176 | + foreach ($raw_imap_headers as $key => $values) { |
|
| 177 | 177 | $key = str_replace("-", "_", $key); |
| 178 | 178 | $imap_headers[$key] = $values; |
| 179 | 179 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | $lines = explode("\r\n", $raw_headers); |
| 183 | 183 | $prev_header = null; |
| 184 | - foreach($lines as $line) { |
|
| 184 | + foreach ($lines as $line) { |
|
| 185 | 185 | if (substr($line, 0, 1) === "\n") { |
| 186 | 186 | $line = substr($line, 1); |
| 187 | 187 | } |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | if (is_array($headers[$prev_header])) { |
| 203 | 203 | $headers[$prev_header][] = $line; |
| 204 | - }else{ |
|
| 204 | + }else { |
|
| 205 | 205 | $headers[$prev_header] .= $line; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | - }else{ |
|
| 208 | + }else { |
|
| 209 | 209 | if (($pos = strpos($line, ":")) > 0) { |
| 210 | 210 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
| 211 | 211 | $key = str_replace("-", "_", $key); |
@@ -217,10 +217,10 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - foreach($headers as $key => $values) { |
|
| 220 | + foreach ($headers as $key => $values) { |
|
| 221 | 221 | if (isset($imap_headers[$key])) continue; |
| 222 | 222 | $value = null; |
| 223 | - switch($key){ |
|
| 223 | + switch ($key) { |
|
| 224 | 224 | case 'from': |
| 225 | 225 | case 'to': |
| 226 | 226 | case 'cc': |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | break; |
| 236 | 236 | default: |
| 237 | 237 | if (is_array($values)) { |
| 238 | - foreach($values as $k => $v) { |
|
| 238 | + foreach ($values as $k => $v) { |
|
| 239 | 239 | if ($v == "") { |
| 240 | 240 | unset($values[$k]); |
| 241 | 241 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $value = implode(" ", $values); |
| 248 | 248 | } elseif ($available_values > 2) { |
| 249 | 249 | $value = array_values($values); |
| 250 | - } else { |
|
| 250 | + }else { |
|
| 251 | 251 | $value = ""; |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | * @return array The decoded elements are returned in an array of objects, where each |
| 268 | 268 | * object has two properties, charset and text. |
| 269 | 269 | */ |
| 270 | - public function mime_header_decode($text){ |
|
| 270 | + public function mime_header_decode($text) { |
|
| 271 | 271 | if (extension_loaded('imap')) { |
| 272 | 272 | return \imap_mime_header_decode($text); |
| 273 | 273 | } |
| 274 | 274 | $charset = $this->getEncoding($text); |
| 275 | - return [(object)[ |
|
| 275 | + return [(object) [ |
|
| 276 | 276 | "charset" => $charset, |
| 277 | 277 | "text" => $this->convertEncoding($text, $charset) |
| 278 | 278 | ]]; |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | try { |
| 327 | 327 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 328 | 328 | return iconv($from, $to, $str); |
| 329 | - } else { |
|
| 329 | + }else { |
|
| 330 | 330 | if (!$from) { |
| 331 | 331 | return mb_convert_encoding($str, $to); |
| 332 | 332 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | if (strstr($from, '-')) { |
| 337 | 337 | $from = str_replace('-', '', $from); |
| 338 | 338 | return $this->convertEncoding($str, $from, $to); |
| 339 | - } else { |
|
| 339 | + }else { |
|
| 340 | 340 | return $str; |
| 341 | 341 | } |
| 342 | 342 | } |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | } |
| 358 | 358 | }elseif (property_exists($structure, 'charset')) { |
| 359 | 359 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 360 | - }elseif (is_string($structure) === true){ |
|
| 360 | + }elseif (is_string($structure) === true) { |
|
| 361 | 361 | return mb_detect_encoding($structure); |
| 362 | 362 | } |
| 363 | 363 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $decoder = $this->config['decoder']['message']; |
| 379 | 379 | |
| 380 | 380 | if ($value !== null) { |
| 381 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 381 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 382 | 382 | $value = \imap_utf8($value); |
| 383 | 383 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
| 384 | 384 | $value = mb_decode_mimeheader($value); |
@@ -386,14 +386,14 @@ discard block |
||
| 386 | 386 | if ($this->notDecoded($original_value, $value)) { |
| 387 | 387 | $decoded_value = $this->mime_header_decode($value); |
| 388 | 388 | if (count($decoded_value) > 0) { |
| 389 | - if(property_exists($decoded_value[0], "text")) { |
|
| 389 | + if (property_exists($decoded_value[0], "text")) { |
|
| 390 | 390 | $value = $decoded_value[0]->text; |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | - }elseif($decoder === 'iconv') { |
|
| 394 | + }elseif ($decoder === 'iconv') { |
|
| 395 | 395 | $value = iconv_mime_decode($value); |
| 396 | - }else{ |
|
| 396 | + }else { |
|
| 397 | 397 | $value = mb_decode_mimeheader($value); |
| 398 | 398 | } |
| 399 | 399 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return array |
| 417 | 417 | */ |
| 418 | 418 | private function decodeArray($values) { |
| 419 | - foreach($values as $key => $value) { |
|
| 419 | + foreach ($values as $key => $value) { |
|
| 420 | 420 | $values[$key] = $this->decode($value); |
| 421 | 421 | } |
| 422 | 422 | return $values; |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | * Try to extract the priority from a given raw header string |
| 427 | 427 | */ |
| 428 | 428 | private function findPriority() { |
| 429 | - if(($priority = $this->get("x_priority")) === null) return; |
|
| 430 | - switch($priority){ |
|
| 429 | + if (($priority = $this->get("x_priority")) === null) return; |
|
| 430 | + switch ($priority) { |
|
| 431 | 431 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 432 | 432 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 433 | 433 | break; |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | */ |
| 460 | 460 | private function decodeAddresses($values) { |
| 461 | 461 | $addresses = []; |
| 462 | - foreach($values as $address) { |
|
| 462 | + foreach ($values as $address) { |
|
| 463 | 463 | $address = trim(rtrim($address)); |
| 464 | 464 | if (strpos($address, ",") == strlen($address) - 1) { |
| 465 | 465 | $address = substr($address, 0, -1); |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
| 469 | 469 | $address, |
| 470 | 470 | $matches |
| 471 | - )){ |
|
| 471 | + )) { |
|
| 472 | 472 | $name = trim(rtrim($matches["name"])); |
| 473 | 473 | $email = trim(rtrim($matches["email"])); |
| 474 | 474 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | * @param object $header |
| 488 | 488 | */ |
| 489 | 489 | private function extractAddresses($header) { |
| 490 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
| 490 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
| 491 | 491 | if (property_exists($header, $key)) { |
| 492 | 492 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
| 493 | 493 | } |
@@ -518,10 +518,10 @@ discard block |
||
| 518 | 518 | } |
| 519 | 519 | if (!property_exists($address, 'personal')) { |
| 520 | 520 | $address->personal = false; |
| 521 | - } else { |
|
| 521 | + }else { |
|
| 522 | 522 | $personalParts = $this->mime_header_decode($address->personal); |
| 523 | 523 | |
| 524 | - if(is_array($personalParts)) { |
|
| 524 | + if (is_array($personalParts)) { |
|
| 525 | 525 | $address->personal = ''; |
| 526 | 526 | foreach ($personalParts as $p) { |
| 527 | 527 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -541,18 +541,18 @@ discard block |
||
| 541 | 541 | /** |
| 542 | 542 | * Search and extract potential header extensions |
| 543 | 543 | */ |
| 544 | - private function extractHeaderExtensions(){ |
|
| 544 | + private function extractHeaderExtensions() { |
|
| 545 | 545 | foreach ($this->attributes as $key => $value) { |
| 546 | 546 | // Only parse strings and don't parse any attributes like the user-agent |
| 547 | 547 | if (is_string($value) === true && in_array($key, ["user_agent"]) === false) { |
| 548 | - if (($pos = strpos($value, ";")) !== false){ |
|
| 548 | + if (($pos = strpos($value, ";")) !== false) { |
|
| 549 | 549 | $original = substr($value, 0, $pos); |
| 550 | 550 | $this->attributes[$key] = trim(rtrim($original)); |
| 551 | 551 | |
| 552 | 552 | // Get all potential extensions |
| 553 | 553 | $extensions = explode(";", substr($value, $pos + 1)); |
| 554 | - foreach($extensions as $extension) { |
|
| 555 | - if (($pos = strpos($extension, "=")) !== false){ |
|
| 554 | + foreach ($extensions as $extension) { |
|
| 555 | + if (($pos = strpos($extension, "=")) !== false) { |
|
| 556 | 556 | $key = substr($extension, 0, $pos); |
| 557 | 557 | $key = trim(rtrim(strtolower($key))); |
| 558 | 558 | |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | $parsed_date = null; |
| 596 | 596 | $date = $header->date; |
| 597 | 597 | |
| 598 | - if(preg_match('/\+0580/', $date)) { |
|
| 598 | + if (preg_match('/\+0580/', $date)) { |
|
| 599 | 599 | $date = str_replace('+0580', '+0530', $date); |
| 600 | 600 | } |
| 601 | 601 | |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | $date = trim(array_pop($array)); |
| 619 | 619 | break; |
| 620 | 620 | } |
| 621 | - try{ |
|
| 621 | + try { |
|
| 622 | 622 | $parsed_date = Carbon::parse($date); |
| 623 | 623 | } catch (\Exception $_e) { |
| 624 | 624 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | if ($prev_header !== null) { |
| 193 | 193 | $headers[$prev_header][] = $line; |
| 194 | 194 | } |
| 195 | - }elseif (substr($line, 0, 1) === " ") { |
|
| 195 | + } elseif (substr($line, 0, 1) === " ") { |
|
| 196 | 196 | $line = substr($line, 1); |
| 197 | 197 | $line = trim(rtrim($line)); |
| 198 | 198 | if ($prev_header !== null) { |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | if (is_array($headers[$prev_header])) { |
| 203 | 203 | $headers[$prev_header][] = $line; |
| 204 | - }else{ |
|
| 204 | + } else{ |
|
| 205 | 205 | $headers[$prev_header] .= $line; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | - }else{ |
|
| 208 | + } else{ |
|
| 209 | 209 | if (($pos = strpos($line, ":")) > 0) { |
| 210 | 210 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
| 211 | 211 | $key = str_replace("-", "_", $key); |
@@ -218,7 +218,9 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | foreach($headers as $key => $values) { |
| 221 | - if (isset($imap_headers[$key])) continue; |
|
| 221 | + if (isset($imap_headers[$key])) { |
|
| 222 | + continue; |
|
| 223 | + } |
|
| 222 | 224 | $value = null; |
| 223 | 225 | switch($key){ |
| 224 | 226 | case 'from': |
@@ -355,9 +357,9 @@ discard block |
||
| 355 | 357 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
| 356 | 358 | } |
| 357 | 359 | } |
| 358 | - }elseif (property_exists($structure, 'charset')) { |
|
| 360 | + } elseif (property_exists($structure, 'charset')) { |
|
| 359 | 361 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 360 | - }elseif (is_string($structure) === true){ |
|
| 362 | + } elseif (is_string($structure) === true){ |
|
| 361 | 363 | return mb_detect_encoding($structure); |
| 362 | 364 | } |
| 363 | 365 | |
@@ -391,9 +393,9 @@ discard block |
||
| 391 | 393 | } |
| 392 | 394 | } |
| 393 | 395 | } |
| 394 | - }elseif($decoder === 'iconv') { |
|
| 396 | + } elseif($decoder === 'iconv') { |
|
| 395 | 397 | $value = iconv_mime_decode($value); |
| 396 | - }else{ |
|
| 398 | + } else{ |
|
| 397 | 399 | $value = mb_decode_mimeheader($value); |
| 398 | 400 | } |
| 399 | 401 | |
@@ -426,7 +428,9 @@ discard block |
||
| 426 | 428 | * Try to extract the priority from a given raw header string |
| 427 | 429 | */ |
| 428 | 430 | private function findPriority() { |
| 429 | - if(($priority = $this->get("x_priority")) === null) return; |
|
| 431 | + if(($priority = $this->get("x_priority")) === null) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 430 | 434 | switch($priority){ |
| 431 | 435 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 432 | 436 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |