@@ -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 | * @throws InvalidMessageDateException |
174 | 174 | */ |
175 | - protected function parse(){ |
|
175 | + protected function parse() { |
|
176 | 176 | $header = $this->rfc822_parse_headers($this->raw); |
177 | 177 | |
178 | 178 | $this->extractAddresses($header); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $this->parseDate($header); |
191 | 191 | foreach ($header as $key => $value) { |
192 | 192 | $key = trim(rtrim(strtolower($key))); |
193 | - if(!isset($this->attributes[$key])){ |
|
193 | + if (!isset($this->attributes[$key])) { |
|
194 | 194 | $this->set($key, $value); |
195 | 195 | } |
196 | 196 | } |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return object |
208 | 208 | */ |
209 | - public function rfc822_parse_headers($raw_headers){ |
|
209 | + public function rfc822_parse_headers($raw_headers) { |
|
210 | 210 | $headers = []; |
211 | 211 | $imap_headers = []; |
212 | 212 | if (extension_loaded('imap')) { |
213 | 213 | $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw); |
214 | - foreach($raw_imap_headers as $key => $values) { |
|
214 | + foreach ($raw_imap_headers as $key => $values) { |
|
215 | 215 | $key = str_replace("-", "_", $key); |
216 | 216 | $imap_headers[$key] = $values; |
217 | 217 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | $lines = explode("\r\n", $raw_headers); |
221 | 221 | $prev_header = null; |
222 | - foreach($lines as $line) { |
|
222 | + foreach ($lines as $line) { |
|
223 | 223 | if (substr($line, 0, 1) === "\n") { |
224 | 224 | $line = substr($line, 1); |
225 | 225 | } |
@@ -239,19 +239,19 @@ discard block |
||
239 | 239 | } |
240 | 240 | if (is_array($headers[$prev_header])) { |
241 | 241 | $headers[$prev_header][] = $line; |
242 | - }else{ |
|
242 | + }else { |
|
243 | 243 | $headers[$prev_header] .= $line; |
244 | 244 | } |
245 | 245 | } |
246 | - }else{ |
|
246 | + }else { |
|
247 | 247 | if (($pos = strpos($line, ":")) > 0) { |
248 | 248 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
249 | 249 | $key = str_replace("-", "_", $key); |
250 | 250 | |
251 | 251 | $value = trim(rtrim(substr($line, $pos + 1))); |
252 | 252 | if (isset($headers[$key])) { |
253 | - $headers[$key][] = $value; |
|
254 | - }else{ |
|
253 | + $headers[$key][] = $value; |
|
254 | + }else { |
|
255 | 255 | $headers[$key] = [$value]; |
256 | 256 | } |
257 | 257 | $prev_header = $key; |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | - foreach($headers as $key => $values) { |
|
262 | + foreach ($headers as $key => $values) { |
|
263 | 263 | if (isset($imap_headers[$key])) continue; |
264 | 264 | $value = null; |
265 | - switch($key){ |
|
265 | + switch ($key) { |
|
266 | 266 | case 'from': |
267 | 267 | case 'to': |
268 | 268 | case 'cc': |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | break; |
278 | 278 | default: |
279 | 279 | if (is_array($values)) { |
280 | - foreach($values as $k => $v) { |
|
280 | + foreach ($values as $k => $v) { |
|
281 | 281 | if ($v == "") { |
282 | 282 | unset($values[$k]); |
283 | 283 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $value = implode(" ", $values); |
290 | 290 | } elseif ($available_values > 2) { |
291 | 291 | $value = array_values($values); |
292 | - } else { |
|
292 | + }else { |
|
293 | 293 | $value = ""; |
294 | 294 | } |
295 | 295 | } |
@@ -309,12 +309,12 @@ discard block |
||
309 | 309 | * @return array The decoded elements are returned in an array of objects, where each |
310 | 310 | * object has two properties, charset and text. |
311 | 311 | */ |
312 | - public function mime_header_decode($text){ |
|
312 | + public function mime_header_decode($text) { |
|
313 | 313 | if (extension_loaded('imap')) { |
314 | 314 | return \imap_mime_header_decode($text); |
315 | 315 | } |
316 | 316 | $charset = $this->getEncoding($text); |
317 | - return [(object)[ |
|
317 | + return [(object) [ |
|
318 | 318 | "charset" => $charset, |
319 | 319 | "text" => $this->convertEncoding($text, $charset) |
320 | 320 | ]]; |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | try { |
369 | 369 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
370 | 370 | return iconv($from, $to, $str); |
371 | - } else { |
|
371 | + }else { |
|
372 | 372 | if (!$from) { |
373 | 373 | return mb_convert_encoding($str, $to); |
374 | 374 | } |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | if (strstr($from, '-')) { |
379 | 379 | $from = str_replace('-', '', $from); |
380 | 380 | return $this->convertEncoding($str, $from, $to); |
381 | - } else { |
|
381 | + }else { |
|
382 | 382 | return $str; |
383 | 383 | } |
384 | 384 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | } |
400 | 400 | }elseif (property_exists($structure, 'charset')) { |
401 | 401 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
402 | - }elseif (is_string($structure) === true){ |
|
402 | + }elseif (is_string($structure) === true) { |
|
403 | 403 | return mb_detect_encoding($structure); |
404 | 404 | } |
405 | 405 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | if ($value !== null) { |
433 | 433 | $is_utf8_base = $this->is_uft8($value); |
434 | 434 | |
435 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
435 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
436 | 436 | $value = \imap_utf8($value); |
437 | 437 | $is_utf8_base = $this->is_uft8($value); |
438 | 438 | if ($is_utf8_base) { |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | if ($this->notDecoded($original_value, $value)) { |
442 | 442 | $decoded_value = $this->mime_header_decode($value); |
443 | 443 | if (count($decoded_value) > 0) { |
444 | - if(property_exists($decoded_value[0], "text")) { |
|
444 | + if (property_exists($decoded_value[0], "text")) { |
|
445 | 445 | $value = $decoded_value[0]->text; |
446 | 446 | } |
447 | 447 | } |
448 | 448 | } |
449 | - }elseif($decoder === 'iconv' && $is_utf8_base) { |
|
449 | + }elseif ($decoder === 'iconv' && $is_utf8_base) { |
|
450 | 450 | $value = iconv_mime_decode($value); |
451 | - }elseif($is_utf8_base){ |
|
451 | + }elseif ($is_utf8_base) { |
|
452 | 452 | $value = mb_decode_mimeheader($value); |
453 | 453 | } |
454 | 454 | |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return array |
472 | 472 | */ |
473 | 473 | private function decodeArray($values) { |
474 | - foreach($values as $key => $value) { |
|
474 | + foreach ($values as $key => $value) { |
|
475 | 475 | $values[$key] = $this->decode($value); |
476 | 476 | } |
477 | 477 | return $values; |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * Try to extract the priority from a given raw header string |
482 | 482 | */ |
483 | 483 | private function findPriority() { |
484 | - if(($priority = $this->get("x_priority")) === null) return; |
|
485 | - switch((int)"$priority"){ |
|
484 | + if (($priority = $this->get("x_priority")) === null) return; |
|
485 | + switch ((int) "$priority") { |
|
486 | 486 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
487 | 487 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
488 | 488 | break; |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | */ |
515 | 515 | private function decodeAddresses($values) { |
516 | 516 | $addresses = []; |
517 | - foreach($values as $address) { |
|
517 | + foreach ($values as $address) { |
|
518 | 518 | $address = trim(rtrim($address)); |
519 | 519 | if (strpos($address, ",") == strlen($address) - 1) { |
520 | 520 | $address = substr($address, 0, -1); |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
524 | 524 | $address, |
525 | 525 | $matches |
526 | - )){ |
|
526 | + )) { |
|
527 | 527 | $name = trim(rtrim($matches["name"])); |
528 | 528 | $email = trim(rtrim($matches["email"])); |
529 | 529 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @param object $header |
543 | 543 | */ |
544 | 544 | private function extractAddresses($header) { |
545 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
545 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
546 | 546 | if (property_exists($header, $key)) { |
547 | 547 | $this->set($key, $this->parseAddresses($header->$key)); |
548 | 548 | } |
@@ -573,10 +573,10 @@ discard block |
||
573 | 573 | } |
574 | 574 | if (!property_exists($address, 'personal')) { |
575 | 575 | $address->personal = false; |
576 | - } else { |
|
576 | + }else { |
|
577 | 577 | $personalParts = $this->mime_header_decode($address->personal); |
578 | 578 | |
579 | - if(is_array($personalParts)) { |
|
579 | + if (is_array($personalParts)) { |
|
580 | 580 | $address->personal = ''; |
581 | 581 | foreach ($personalParts as $p) { |
582 | 582 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -600,23 +600,23 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Search and extract potential header extensions |
602 | 602 | */ |
603 | - private function extractHeaderExtensions(){ |
|
603 | + private function extractHeaderExtensions() { |
|
604 | 604 | foreach ($this->attributes as $key => $value) { |
605 | 605 | if (is_array($value)) { |
606 | 606 | $value = implode(", ", $value); |
607 | - }else{ |
|
608 | - $value = (string)$value; |
|
607 | + }else { |
|
608 | + $value = (string) $value; |
|
609 | 609 | } |
610 | 610 | // Only parse strings and don't parse any attributes like the user-agent |
611 | 611 | if (in_array($key, ["user_agent"]) === false) { |
612 | - if (($pos = strpos($value, ";")) !== false){ |
|
612 | + if (($pos = strpos($value, ";")) !== false) { |
|
613 | 613 | $original = substr($value, 0, $pos); |
614 | 614 | $this->set($key, trim(rtrim($original)), true); |
615 | 615 | |
616 | 616 | // Get all potential extensions |
617 | 617 | $extensions = explode(";", substr($value, $pos + 1)); |
618 | - foreach($extensions as $extension) { |
|
619 | - if (($pos = strpos($extension, "=")) !== false){ |
|
618 | + foreach ($extensions as $extension) { |
|
619 | + if (($pos = strpos($extension, "=")) !== false) { |
|
620 | 620 | $key = substr($extension, 0, $pos); |
621 | 621 | $key = trim(rtrim(strtolower($key))); |
622 | 622 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | $parsed_date = null; |
660 | 660 | $date = $header->date; |
661 | 661 | |
662 | - if(preg_match('/\+0580/', $date)) { |
|
662 | + if (preg_match('/\+0580/', $date)) { |
|
663 | 663 | $date = str_replace('+0580', '+0530', $date); |
664 | 664 | } |
665 | 665 | |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | $date = trim(array_pop($array)); |
683 | 683 | break; |
684 | 684 | } |
685 | - try{ |
|
685 | + try { |
|
686 | 686 | $parsed_date = Carbon::parse($date); |
687 | 687 | } catch (\Exception $_e) { |
688 | 688 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | if(isset($this->attributes[$name]) && $strict === false) { |
131 | 131 | if ($this->attributize) { |
132 | 132 | $this->attributes[$name]->add($value, true); |
133 | - }else{ |
|
133 | + } else{ |
|
134 | 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 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | if ($prev_header !== null) { |
231 | 231 | $headers[$prev_header][] = $line; |
232 | 232 | } |
233 | - }elseif (substr($line, 0, 1) === " ") { |
|
233 | + } elseif (substr($line, 0, 1) === " ") { |
|
234 | 234 | $line = substr($line, 1); |
235 | 235 | $line = trim(rtrim($line)); |
236 | 236 | if ($prev_header !== null) { |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | } |
240 | 240 | if (is_array($headers[$prev_header])) { |
241 | 241 | $headers[$prev_header][] = $line; |
242 | - }else{ |
|
242 | + } else{ |
|
243 | 243 | $headers[$prev_header] .= $line; |
244 | 244 | } |
245 | 245 | } |
246 | - }else{ |
|
246 | + } else{ |
|
247 | 247 | if (($pos = strpos($line, ":")) > 0) { |
248 | 248 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
249 | 249 | $key = str_replace("-", "_", $key); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $value = trim(rtrim(substr($line, $pos + 1))); |
252 | 252 | if (isset($headers[$key])) { |
253 | 253 | $headers[$key][] = $value; |
254 | - }else{ |
|
254 | + } else{ |
|
255 | 255 | $headers[$key] = [$value]; |
256 | 256 | } |
257 | 257 | $prev_header = $key; |
@@ -260,7 +260,9 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | foreach($headers as $key => $values) { |
263 | - if (isset($imap_headers[$key])) continue; |
|
263 | + if (isset($imap_headers[$key])) { |
|
264 | + continue; |
|
265 | + } |
|
264 | 266 | $value = null; |
265 | 267 | switch($key){ |
266 | 268 | case 'from': |
@@ -397,9 +399,9 @@ discard block |
||
397 | 399 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
398 | 400 | } |
399 | 401 | } |
400 | - }elseif (property_exists($structure, 'charset')) { |
|
402 | + } elseif (property_exists($structure, 'charset')) { |
|
401 | 403 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
402 | - }elseif (is_string($structure) === true){ |
|
404 | + } elseif (is_string($structure) === true){ |
|
403 | 405 | return mb_detect_encoding($structure); |
404 | 406 | } |
405 | 407 | |
@@ -446,9 +448,9 @@ discard block |
||
446 | 448 | } |
447 | 449 | } |
448 | 450 | } |
449 | - }elseif($decoder === 'iconv' && $is_utf8_base) { |
|
451 | + } elseif($decoder === 'iconv' && $is_utf8_base) { |
|
450 | 452 | $value = iconv_mime_decode($value); |
451 | - }elseif($is_utf8_base){ |
|
453 | + } elseif($is_utf8_base){ |
|
452 | 454 | $value = mb_decode_mimeheader($value); |
453 | 455 | } |
454 | 456 | |
@@ -481,7 +483,9 @@ discard block |
||
481 | 483 | * Try to extract the priority from a given raw header string |
482 | 484 | */ |
483 | 485 | private function findPriority() { |
484 | - if(($priority = $this->get("x_priority")) === null) return; |
|
486 | + if(($priority = $this->get("x_priority")) === null) { |
|
487 | + return; |
|
488 | + } |
|
485 | 489 | switch((int)"$priority"){ |
486 | 490 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
487 | 491 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
@@ -604,7 +608,7 @@ discard block |
||
604 | 608 | foreach ($this->attributes as $key => $value) { |
605 | 609 | if (is_array($value)) { |
606 | 610 | $value = implode(", ", $value); |
607 | - }else{ |
|
611 | + } else{ |
|
608 | 612 | $value = (string)$value; |
609 | 613 | } |
610 | 614 | // Only parse strings and don't parse any attributes like the user-agent |