@@ -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,19 +201,19 @@ 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); |
| 212 | 212 | |
| 213 | 213 | $value = trim(rtrim(substr($line, $pos + 1))); |
| 214 | 214 | if (isset($headers[$key])) { |
| 215 | - $headers[$key][] = $value; |
|
| 216 | - }else{ |
|
| 215 | + $headers[$key][] = $value; |
|
| 216 | + }else { |
|
| 217 | 217 | $headers[$key] = [$value]; |
| 218 | 218 | } |
| 219 | 219 | $prev_header = $key; |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - foreach($headers as $key => $values) { |
|
| 224 | + foreach ($headers as $key => $values) { |
|
| 225 | 225 | if (isset($imap_headers[$key])) continue; |
| 226 | 226 | $value = null; |
| 227 | - switch($key){ |
|
| 227 | + switch ($key) { |
|
| 228 | 228 | case 'from': |
| 229 | 229 | case 'to': |
| 230 | 230 | case 'cc': |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | break; |
| 240 | 240 | default: |
| 241 | 241 | if (is_array($values)) { |
| 242 | - foreach($values as $k => $v) { |
|
| 242 | + foreach ($values as $k => $v) { |
|
| 243 | 243 | if ($v == "") { |
| 244 | 244 | unset($values[$k]); |
| 245 | 245 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | $value = implode(" ", $values); |
| 252 | 252 | } elseif ($available_values > 2) { |
| 253 | 253 | $value = array_values($values); |
| 254 | - } else { |
|
| 254 | + }else { |
|
| 255 | 255 | $value = ""; |
| 256 | 256 | } |
| 257 | 257 | } |
@@ -271,12 +271,12 @@ discard block |
||
| 271 | 271 | * @return array The decoded elements are returned in an array of objects, where each |
| 272 | 272 | * object has two properties, charset and text. |
| 273 | 273 | */ |
| 274 | - public function mime_header_decode($text){ |
|
| 274 | + public function mime_header_decode($text) { |
|
| 275 | 275 | if (extension_loaded('imap')) { |
| 276 | 276 | return \imap_mime_header_decode($text); |
| 277 | 277 | } |
| 278 | 278 | $charset = $this->getEncoding($text); |
| 279 | - return [(object)[ |
|
| 279 | + return [(object) [ |
|
| 280 | 280 | "charset" => $charset, |
| 281 | 281 | "text" => $this->convertEncoding($text, $charset) |
| 282 | 282 | ]]; |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | try { |
| 331 | 331 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 332 | 332 | return iconv($from, $to, $str); |
| 333 | - } else { |
|
| 333 | + }else { |
|
| 334 | 334 | if (!$from) { |
| 335 | 335 | return mb_convert_encoding($str, $to); |
| 336 | 336 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | if (strstr($from, '-')) { |
| 341 | 341 | $from = str_replace('-', '', $from); |
| 342 | 342 | return $this->convertEncoding($str, $from, $to); |
| 343 | - } else { |
|
| 343 | + }else { |
|
| 344 | 344 | return $str; |
| 345 | 345 | } |
| 346 | 346 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | }elseif (property_exists($structure, 'charset')) { |
| 363 | 363 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 364 | - }elseif (is_string($structure) === true){ |
|
| 364 | + }elseif (is_string($structure) === true) { |
|
| 365 | 365 | return mb_detect_encoding($structure); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | $decoder = $this->config['decoder']['message']; |
| 383 | 383 | |
| 384 | 384 | if ($value !== null) { |
| 385 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 385 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 386 | 386 | $value = \imap_utf8($value); |
| 387 | 387 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
| 388 | 388 | $value = mb_decode_mimeheader($value); |
@@ -390,14 +390,14 @@ discard block |
||
| 390 | 390 | if ($this->notDecoded($original_value, $value)) { |
| 391 | 391 | $decoded_value = $this->mime_header_decode($value); |
| 392 | 392 | if (count($decoded_value) > 0) { |
| 393 | - if(property_exists($decoded_value[0], "text")) { |
|
| 393 | + if (property_exists($decoded_value[0], "text")) { |
|
| 394 | 394 | $value = $decoded_value[0]->text; |
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | - }elseif($decoder === 'iconv') { |
|
| 398 | + }elseif ($decoder === 'iconv') { |
|
| 399 | 399 | $value = iconv_mime_decode($value); |
| 400 | - }else{ |
|
| 400 | + }else { |
|
| 401 | 401 | $value = mb_decode_mimeheader($value); |
| 402 | 402 | } |
| 403 | 403 | |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return array |
| 421 | 421 | */ |
| 422 | 422 | private function decodeArray($values) { |
| 423 | - foreach($values as $key => $value) { |
|
| 423 | + foreach ($values as $key => $value) { |
|
| 424 | 424 | $values[$key] = $this->decode($value); |
| 425 | 425 | } |
| 426 | 426 | return $values; |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * Try to extract the priority from a given raw header string |
| 431 | 431 | */ |
| 432 | 432 | private function findPriority() { |
| 433 | - if(($priority = $this->get("x_priority")) === null) return; |
|
| 434 | - switch($priority){ |
|
| 433 | + if (($priority = $this->get("x_priority")) === null) return; |
|
| 434 | + switch ($priority) { |
|
| 435 | 435 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 436 | 436 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 437 | 437 | break; |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | private function decodeAddresses($values) { |
| 465 | 465 | $addresses = []; |
| 466 | - foreach($values as $address) { |
|
| 466 | + foreach ($values as $address) { |
|
| 467 | 467 | $address = trim(rtrim($address)); |
| 468 | 468 | if (strpos($address, ",") == strlen($address) - 1) { |
| 469 | 469 | $address = substr($address, 0, -1); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
| 473 | 473 | $address, |
| 474 | 474 | $matches |
| 475 | - )){ |
|
| 475 | + )) { |
|
| 476 | 476 | $name = trim(rtrim($matches["name"])); |
| 477 | 477 | $email = trim(rtrim($matches["email"])); |
| 478 | 478 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * @param object $header |
| 492 | 492 | */ |
| 493 | 493 | private function extractAddresses($header) { |
| 494 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
| 494 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
| 495 | 495 | if (property_exists($header, $key)) { |
| 496 | 496 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
| 497 | 497 | } |
@@ -522,10 +522,10 @@ discard block |
||
| 522 | 522 | } |
| 523 | 523 | if (!property_exists($address, 'personal')) { |
| 524 | 524 | $address->personal = false; |
| 525 | - } else { |
|
| 525 | + }else { |
|
| 526 | 526 | $personalParts = $this->mime_header_decode($address->personal); |
| 527 | 527 | |
| 528 | - if(is_array($personalParts)) { |
|
| 528 | + if (is_array($personalParts)) { |
|
| 529 | 529 | $address->personal = ''; |
| 530 | 530 | foreach ($personalParts as $p) { |
| 531 | 531 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -545,18 +545,18 @@ discard block |
||
| 545 | 545 | /** |
| 546 | 546 | * Search and extract potential header extensions |
| 547 | 547 | */ |
| 548 | - private function extractHeaderExtensions(){ |
|
| 548 | + private function extractHeaderExtensions() { |
|
| 549 | 549 | foreach ($this->attributes as $key => $value) { |
| 550 | 550 | // Only parse strings and don't parse any attributes like the user-agent |
| 551 | 551 | if (is_string($value) === true && in_array($key, ["user_agent"]) === false) { |
| 552 | - if (($pos = strpos($value, ";")) !== false){ |
|
| 552 | + if (($pos = strpos($value, ";")) !== false) { |
|
| 553 | 553 | $original = substr($value, 0, $pos); |
| 554 | 554 | $this->attributes[$key] = trim(rtrim($original)); |
| 555 | 555 | |
| 556 | 556 | // Get all potential extensions |
| 557 | 557 | $extensions = explode(";", substr($value, $pos + 1)); |
| 558 | - foreach($extensions as $extension) { |
|
| 559 | - if (($pos = strpos($extension, "=")) !== false){ |
|
| 558 | + foreach ($extensions as $extension) { |
|
| 559 | + if (($pos = strpos($extension, "=")) !== false) { |
|
| 560 | 560 | $key = substr($extension, 0, $pos); |
| 561 | 561 | $key = trim(rtrim(strtolower($key))); |
| 562 | 562 | |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | $parsed_date = null; |
| 600 | 600 | $date = $header->date; |
| 601 | 601 | |
| 602 | - if(preg_match('/\+0580/', $date)) { |
|
| 602 | + if (preg_match('/\+0580/', $date)) { |
|
| 603 | 603 | $date = str_replace('+0580', '+0530', $date); |
| 604 | 604 | } |
| 605 | 605 | |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | $date = trim(array_pop($array)); |
| 623 | 623 | break; |
| 624 | 624 | } |
| 625 | - try{ |
|
| 625 | + try { |
|
| 626 | 626 | $parsed_date = Carbon::parse($date); |
| 627 | 627 | } catch (\Exception $_e) { |
| 628 | 628 | 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); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $value = trim(rtrim(substr($line, $pos + 1))); |
| 214 | 214 | if (isset($headers[$key])) { |
| 215 | 215 | $headers[$key][] = $value; |
| 216 | - }else{ |
|
| 216 | + } else{ |
|
| 217 | 217 | $headers[$key] = [$value]; |
| 218 | 218 | } |
| 219 | 219 | $prev_header = $key; |
@@ -222,7 +222,9 @@ discard block |
||
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | foreach($headers as $key => $values) { |
| 225 | - if (isset($imap_headers[$key])) continue; |
|
| 225 | + if (isset($imap_headers[$key])) { |
|
| 226 | + continue; |
|
| 227 | + } |
|
| 226 | 228 | $value = null; |
| 227 | 229 | switch($key){ |
| 228 | 230 | case 'from': |
@@ -359,9 +361,9 @@ discard block |
||
| 359 | 361 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
| 360 | 362 | } |
| 361 | 363 | } |
| 362 | - }elseif (property_exists($structure, 'charset')) { |
|
| 364 | + } elseif (property_exists($structure, 'charset')) { |
|
| 363 | 365 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 364 | - }elseif (is_string($structure) === true){ |
|
| 366 | + } elseif (is_string($structure) === true){ |
|
| 365 | 367 | return mb_detect_encoding($structure); |
| 366 | 368 | } |
| 367 | 369 | |
@@ -395,9 +397,9 @@ discard block |
||
| 395 | 397 | } |
| 396 | 398 | } |
| 397 | 399 | } |
| 398 | - }elseif($decoder === 'iconv') { |
|
| 400 | + } elseif($decoder === 'iconv') { |
|
| 399 | 401 | $value = iconv_mime_decode($value); |
| 400 | - }else{ |
|
| 402 | + } else{ |
|
| 401 | 403 | $value = mb_decode_mimeheader($value); |
| 402 | 404 | } |
| 403 | 405 | |
@@ -430,7 +432,9 @@ discard block |
||
| 430 | 432 | * Try to extract the priority from a given raw header string |
| 431 | 433 | */ |
| 432 | 434 | private function findPriority() { |
| 433 | - if(($priority = $this->get("x_priority")) === null) return; |
|
| 435 | + if(($priority = $this->get("x_priority")) === null) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 434 | 438 | switch($priority){ |
| 435 | 439 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 436 | 440 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |