@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @throws MethodNotFoundException |
83 | 83 | */ |
84 | 84 | public function __call($method, $arguments) { |
85 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
85 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
86 | 86 | $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3)); |
87 | 87 | |
88 | - if(in_array($name, array_keys($this->attributes))) { |
|
88 | + if (in_array($name, array_keys($this->attributes))) { |
|
89 | 89 | return $this->attributes[$name]; |
90 | 90 | } |
91 | 91 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return Attribute|mixed |
112 | 112 | */ |
113 | 113 | public function get($name) { |
114 | - if(isset($this->attributes[$name])) { |
|
114 | + if (isset($this->attributes[$name])) { |
|
115 | 115 | return $this->attributes[$name]; |
116 | 116 | } |
117 | 117 | |
@@ -127,23 +127,23 @@ discard block |
||
127 | 127 | * @return Attribute |
128 | 128 | */ |
129 | 129 | public function set($name, $value, $strict = false) { |
130 | - if(isset($this->attributes[$name]) && $strict === false) { |
|
130 | + if (isset($this->attributes[$name]) && $strict === false) { |
|
131 | 131 | if ($this->attributize) { |
132 | 132 | $this->attributes[$name]->add($value, true); |
133 | - }else{ |
|
134 | - if(isset($this->attributes[$name])) { |
|
133 | + }else { |
|
134 | + if (isset($this->attributes[$name])) { |
|
135 | 135 | if (is_array($this->attributes[$name]) == false) { |
136 | 136 | $this->attributes[$name] = [$this->attributes[$name], $value]; |
137 | - }else{ |
|
137 | + }else { |
|
138 | 138 | $this->attributes[$name][] = $value; |
139 | 139 | } |
140 | - }else{ |
|
140 | + }else { |
|
141 | 141 | $this->attributes[$name] = $value; |
142 | 142 | } |
143 | 143 | } |
144 | - }elseif($this->attributize == false){ |
|
144 | + }elseif ($this->attributize == false) { |
|
145 | 145 | $this->attributes[$name] = $value; |
146 | - }else{ |
|
146 | + }else { |
|
147 | 147 | $this->attributes[$name] = new Attribute($name, $value); |
148 | 148 | } |
149 | 149 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | public function find($pattern) { |
160 | 160 | if (preg_match_all($pattern, $this->raw, $matches)) { |
161 | 161 | if (isset($matches[1])) { |
162 | - if(count($matches[1]) > 0) { |
|
162 | + if (count($matches[1]) > 0) { |
|
163 | 163 | return $matches[1][0]; |
164 | 164 | } |
165 | 165 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return string|null |
174 | 174 | */ |
175 | - public function getBoundary(){ |
|
175 | + public function getBoundary() { |
|
176 | 176 | $boundary = $this->find("/boundary\=(.*)/i"); |
177 | 177 | |
178 | 178 | if ($boundary === null) { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @throws InvalidMessageDateException |
199 | 199 | */ |
200 | - protected function parse(){ |
|
200 | + protected function parse() { |
|
201 | 201 | $header = $this->rfc822_parse_headers($this->raw); |
202 | 202 | |
203 | 203 | $this->extractAddresses($header); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $this->parseDate($header); |
216 | 216 | foreach ($header as $key => $value) { |
217 | 217 | $key = trim(rtrim(strtolower($key))); |
218 | - if(!isset($this->attributes[$key])){ |
|
218 | + if (!isset($this->attributes[$key])) { |
|
219 | 219 | $this->set($key, $value); |
220 | 220 | } |
221 | 221 | } |
@@ -231,19 +231,19 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return object |
233 | 233 | */ |
234 | - public function rfc822_parse_headers($raw_headers){ |
|
234 | + public function rfc822_parse_headers($raw_headers) { |
|
235 | 235 | $headers = []; |
236 | 236 | $imap_headers = []; |
237 | 237 | if (extension_loaded('imap') && $this->config["rfc822"]) { |
238 | 238 | $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw); |
239 | - foreach($raw_imap_headers as $key => $values) { |
|
239 | + foreach ($raw_imap_headers as $key => $values) { |
|
240 | 240 | $key = str_replace("-", "_", $key); |
241 | 241 | $imap_headers[$key] = $values; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | $lines = explode("\r\n", str_replace("\r\n\t", ' ', $raw_headers)); |
245 | 245 | $prev_header = null; |
246 | - foreach($lines as $line) { |
|
246 | + foreach ($lines as $line) { |
|
247 | 247 | if (substr($line, 0, 1) === "\n") { |
248 | 248 | $line = substr($line, 1); |
249 | 249 | } |
@@ -263,19 +263,19 @@ discard block |
||
263 | 263 | } |
264 | 264 | if (is_array($headers[$prev_header])) { |
265 | 265 | $headers[$prev_header][] = $line; |
266 | - }else{ |
|
266 | + }else { |
|
267 | 267 | $headers[$prev_header] .= $line; |
268 | 268 | } |
269 | 269 | } |
270 | - }else{ |
|
270 | + }else { |
|
271 | 271 | if (($pos = strpos($line, ":")) > 0) { |
272 | 272 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
273 | 273 | $key = str_replace("-", "_", $key); |
274 | 274 | |
275 | 275 | $value = trim(rtrim(substr($line, $pos + 1))); |
276 | 276 | if (isset($headers[$key])) { |
277 | - $headers[$key][] = $value; |
|
278 | - }else{ |
|
277 | + $headers[$key][] = $value; |
|
278 | + }else { |
|
279 | 279 | $headers[$key] = [$value]; |
280 | 280 | } |
281 | 281 | $prev_header = $key; |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - foreach($headers as $key => $values) { |
|
286 | + foreach ($headers as $key => $values) { |
|
287 | 287 | if (isset($imap_headers[$key])) continue; |
288 | 288 | $value = null; |
289 | - switch($key){ |
|
289 | + switch ($key) { |
|
290 | 290 | case 'from': |
291 | 291 | case 'to': |
292 | 292 | case 'cc': |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | break; |
302 | 302 | default: |
303 | 303 | if (is_array($values)) { |
304 | - foreach($values as $k => $v) { |
|
304 | + foreach ($values as $k => $v) { |
|
305 | 305 | if ($v == "") { |
306 | 306 | unset($values[$k]); |
307 | 307 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $value = implode(" ", $values); |
314 | 314 | } elseif ($available_values > 2) { |
315 | 315 | $value = array_values($values); |
316 | - } else { |
|
316 | + }else { |
|
317 | 317 | $value = ""; |
318 | 318 | } |
319 | 319 | } |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | * @return array The decoded elements are returned in an array of objects, where each |
334 | 334 | * object has two properties, charset and text. |
335 | 335 | */ |
336 | - public function mime_header_decode($text){ |
|
336 | + public function mime_header_decode($text) { |
|
337 | 337 | if (extension_loaded('imap')) { |
338 | 338 | return \imap_mime_header_decode($text); |
339 | 339 | } |
340 | 340 | $charset = $this->getEncoding($text); |
341 | - return [(object)[ |
|
341 | + return [(object) [ |
|
342 | 342 | "charset" => $charset, |
343 | 343 | "text" => $this->convertEncoding($text, $charset) |
344 | 344 | ]]; |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | try { |
393 | 393 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
394 | 394 | return iconv($from, $to, $str); |
395 | - } else { |
|
395 | + }else { |
|
396 | 396 | if (!$from) { |
397 | 397 | return mb_convert_encoding($str, $to); |
398 | 398 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | if (strstr($from, '-')) { |
403 | 403 | $from = str_replace('-', '', $from); |
404 | 404 | return $this->convertEncoding($str, $from, $to); |
405 | - } else { |
|
405 | + }else { |
|
406 | 406 | return $str; |
407 | 407 | } |
408 | 408 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | }elseif (property_exists($structure, 'charset')) { |
425 | 425 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
426 | - }elseif (is_string($structure) === true){ |
|
426 | + }elseif (is_string($structure) === true) { |
|
427 | 427 | return mb_detect_encoding($structure); |
428 | 428 | } |
429 | 429 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | if ($value !== null) { |
457 | 457 | $is_utf8_base = $this->is_uft8($value); |
458 | 458 | |
459 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
459 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
460 | 460 | $value = \imap_utf8($value); |
461 | 461 | $is_utf8_base = $this->is_uft8($value); |
462 | 462 | if ($is_utf8_base) { |
@@ -465,14 +465,14 @@ discard block |
||
465 | 465 | if ($this->notDecoded($original_value, $value)) { |
466 | 466 | $decoded_value = $this->mime_header_decode($value); |
467 | 467 | if (count($decoded_value) > 0) { |
468 | - if(property_exists($decoded_value[0], "text")) { |
|
468 | + if (property_exists($decoded_value[0], "text")) { |
|
469 | 469 | $value = $decoded_value[0]->text; |
470 | 470 | } |
471 | 471 | } |
472 | 472 | } |
473 | - }elseif($decoder === 'iconv' && $is_utf8_base) { |
|
473 | + }elseif ($decoder === 'iconv' && $is_utf8_base) { |
|
474 | 474 | $value = iconv_mime_decode($value); |
475 | - }elseif($is_utf8_base){ |
|
475 | + }elseif ($is_utf8_base) { |
|
476 | 476 | $value = mb_decode_mimeheader($value); |
477 | 477 | } |
478 | 478 | |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | * @return array |
496 | 496 | */ |
497 | 497 | private function decodeArray($values) { |
498 | - foreach($values as $key => $value) { |
|
498 | + foreach ($values as $key => $value) { |
|
499 | 499 | $values[$key] = $this->decode($value); |
500 | 500 | } |
501 | 501 | return $values; |
@@ -505,8 +505,8 @@ discard block |
||
505 | 505 | * Try to extract the priority from a given raw header string |
506 | 506 | */ |
507 | 507 | private function findPriority() { |
508 | - if(($priority = $this->get("x_priority")) === null) return; |
|
509 | - switch((int)"$priority"){ |
|
508 | + if (($priority = $this->get("x_priority")) === null) return; |
|
509 | + switch ((int) "$priority") { |
|
510 | 510 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
511 | 511 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
512 | 512 | break; |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | private function decodeAddresses($values) { |
540 | 540 | $addresses = []; |
541 | 541 | |
542 | - foreach($values as $address) { |
|
542 | + foreach ($values as $address) { |
|
543 | 543 | foreach (preg_split('/, (?=(?:[^"]*"[^"]*")*[^"]*$)/', $address) as $split_address) { |
544 | 544 | $split_address = trim(rtrim($split_address)); |
545 | 545 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | $name = trim(rtrim($matches["name"])); |
555 | 555 | $email = trim(rtrim($matches["email"])); |
556 | 556 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
557 | - $addresses[] = (object)[ |
|
557 | + $addresses[] = (object) [ |
|
558 | 558 | "personal" => $name, |
559 | 559 | "mailbox" => $mailbox, |
560 | 560 | "host" => $host, |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | * @param object $header |
572 | 572 | */ |
573 | 573 | private function extractAddresses($header) { |
574 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
574 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
575 | 575 | if (property_exists($header, $key)) { |
576 | 576 | $this->set($key, $this->parseAddresses($header->$key)); |
577 | 577 | } |
@@ -602,10 +602,10 @@ discard block |
||
602 | 602 | } |
603 | 603 | if (!property_exists($address, 'personal')) { |
604 | 604 | $address->personal = false; |
605 | - } else { |
|
605 | + }else { |
|
606 | 606 | $personalParts = $this->mime_header_decode($address->personal); |
607 | 607 | |
608 | - if(is_array($personalParts)) { |
|
608 | + if (is_array($personalParts)) { |
|
609 | 609 | $address->personal = ''; |
610 | 610 | foreach ($personalParts as $p) { |
611 | 611 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -629,23 +629,23 @@ discard block |
||
629 | 629 | /** |
630 | 630 | * Search and extract potential header extensions |
631 | 631 | */ |
632 | - private function extractHeaderExtensions(){ |
|
632 | + private function extractHeaderExtensions() { |
|
633 | 633 | foreach ($this->attributes as $key => $value) { |
634 | 634 | if (is_array($value)) { |
635 | 635 | $value = implode(", ", $value); |
636 | - }else{ |
|
637 | - $value = (string)$value; |
|
636 | + }else { |
|
637 | + $value = (string) $value; |
|
638 | 638 | } |
639 | 639 | // Only parse strings and don't parse any attributes like the user-agent |
640 | 640 | if (in_array($key, ["user_agent"]) === false) { |
641 | - if (($pos = strpos($value, ";")) !== false){ |
|
641 | + if (($pos = strpos($value, ";")) !== false) { |
|
642 | 642 | $original = substr($value, 0, $pos); |
643 | 643 | $this->set($key, trim(rtrim($original)), true); |
644 | 644 | |
645 | 645 | // Get all potential extensions |
646 | 646 | $extensions = explode(";", substr($value, $pos + 1)); |
647 | - foreach($extensions as $extension) { |
|
648 | - if (($pos = strpos($extension, "=")) !== false){ |
|
647 | + foreach ($extensions as $extension) { |
|
648 | + if (($pos = strpos($extension, "=")) !== false) { |
|
649 | 649 | $key = substr($extension, 0, $pos); |
650 | 650 | $key = trim(rtrim(strtolower($key))); |
651 | 651 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | $parsed_date = null; |
689 | 689 | $date = $header->date; |
690 | 690 | |
691 | - if(preg_match('/\+0580/', $date)) { |
|
691 | + if (preg_match('/\+0580/', $date)) { |
|
692 | 692 | $date = str_replace('+0580', '+0530', $date); |
693 | 693 | } |
694 | 694 | |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | $date = trim(array_pop($array)); |
712 | 712 | break; |
713 | 713 | } |
714 | - try{ |
|
714 | + try { |
|
715 | 715 | $parsed_date = Carbon::parse($date); |
716 | 716 | } catch (\Exception $_e) { |
717 | 717 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |