@@ -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 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | $decoder = $this->config['decoder']['message']; |
421 | 421 | |
422 | 422 | if ($value !== null) { |
423 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
423 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
424 | 424 | $value = \imap_utf8($value); |
425 | 425 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
426 | 426 | $value = mb_decode_mimeheader($value); |
@@ -428,14 +428,14 @@ discard block |
||
428 | 428 | if ($this->notDecoded($original_value, $value)) { |
429 | 429 | $decoded_value = $this->mime_header_decode($value); |
430 | 430 | if (count($decoded_value) > 0) { |
431 | - if(property_exists($decoded_value[0], "text")) { |
|
431 | + if (property_exists($decoded_value[0], "text")) { |
|
432 | 432 | $value = $decoded_value[0]->text; |
433 | 433 | } |
434 | 434 | } |
435 | 435 | } |
436 | - }elseif($decoder === 'iconv') { |
|
436 | + }elseif ($decoder === 'iconv') { |
|
437 | 437 | $value = iconv_mime_decode($value); |
438 | - }else{ |
|
438 | + }else { |
|
439 | 439 | $value = mb_decode_mimeheader($value); |
440 | 440 | } |
441 | 441 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @return array |
459 | 459 | */ |
460 | 460 | private function decodeArray($values) { |
461 | - foreach($values as $key => $value) { |
|
461 | + foreach ($values as $key => $value) { |
|
462 | 462 | $values[$key] = $this->decode($value); |
463 | 463 | } |
464 | 464 | return $values; |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | * Try to extract the priority from a given raw header string |
469 | 469 | */ |
470 | 470 | private function findPriority() { |
471 | - if(($priority = $this->get("x_priority")) === null) return; |
|
472 | - switch((int)"$priority"){ |
|
471 | + if (($priority = $this->get("x_priority")) === null) return; |
|
472 | + switch ((int) "$priority") { |
|
473 | 473 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
474 | 474 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
475 | 475 | break; |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | */ |
502 | 502 | private function decodeAddresses($values) { |
503 | 503 | $addresses = []; |
504 | - foreach($values as $address) { |
|
504 | + foreach ($values as $address) { |
|
505 | 505 | $address = trim(rtrim($address)); |
506 | 506 | if (strpos($address, ",") == strlen($address) - 1) { |
507 | 507 | $address = substr($address, 0, -1); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
511 | 511 | $address, |
512 | 512 | $matches |
513 | - )){ |
|
513 | + )) { |
|
514 | 514 | $name = trim(rtrim($matches["name"])); |
515 | 515 | $email = trim(rtrim($matches["email"])); |
516 | 516 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | * @param object $header |
530 | 530 | */ |
531 | 531 | private function extractAddresses($header) { |
532 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
532 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
533 | 533 | if (property_exists($header, $key)) { |
534 | 534 | $this->set($key, $this->parseAddresses($header->$key)); |
535 | 535 | } |
@@ -560,10 +560,10 @@ discard block |
||
560 | 560 | } |
561 | 561 | if (!property_exists($address, 'personal')) { |
562 | 562 | $address->personal = false; |
563 | - } else { |
|
563 | + }else { |
|
564 | 564 | $personalParts = $this->mime_header_decode($address->personal); |
565 | 565 | |
566 | - if(is_array($personalParts)) { |
|
566 | + if (is_array($personalParts)) { |
|
567 | 567 | $address->personal = ''; |
568 | 568 | foreach ($personalParts as $p) { |
569 | 569 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -587,23 +587,23 @@ discard block |
||
587 | 587 | /** |
588 | 588 | * Search and extract potential header extensions |
589 | 589 | */ |
590 | - private function extractHeaderExtensions(){ |
|
590 | + private function extractHeaderExtensions() { |
|
591 | 591 | foreach ($this->attributes as $key => $value) { |
592 | 592 | if (is_array($value)) { |
593 | 593 | $value = implode(", ", $value); |
594 | - }else{ |
|
595 | - $value = (string)$value; |
|
594 | + }else { |
|
595 | + $value = (string) $value; |
|
596 | 596 | } |
597 | 597 | // Only parse strings and don't parse any attributes like the user-agent |
598 | 598 | if (in_array($key, ["user_agent"]) === false) { |
599 | - if (($pos = strpos($value, ";")) !== false){ |
|
599 | + if (($pos = strpos($value, ";")) !== false) { |
|
600 | 600 | $original = substr($value, 0, $pos); |
601 | 601 | $this->set($key, trim(rtrim($original)), true); |
602 | 602 | |
603 | 603 | // Get all potential extensions |
604 | 604 | $extensions = explode(";", substr($value, $pos + 1)); |
605 | - foreach($extensions as $extension) { |
|
606 | - if (($pos = strpos($extension, "=")) !== false){ |
|
605 | + foreach ($extensions as $extension) { |
|
606 | + if (($pos = strpos($extension, "=")) !== false) { |
|
607 | 607 | $key = substr($extension, 0, $pos); |
608 | 608 | $key = trim(rtrim(strtolower($key))); |
609 | 609 | |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | $parsed_date = null; |
647 | 647 | $date = $header->date; |
648 | 648 | |
649 | - if(preg_match('/\+0580/', $date)) { |
|
649 | + if (preg_match('/\+0580/', $date)) { |
|
650 | 650 | $date = str_replace('+0580', '+0530', $date); |
651 | 651 | } |
652 | 652 | |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | $date = trim(array_pop($array)); |
670 | 670 | break; |
671 | 671 | } |
672 | - try{ |
|
672 | + try { |
|
673 | 673 | $parsed_date = Carbon::parse($date); |
674 | 674 | } catch (\Exception $_e) { |
675 | 675 | 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 | |
@@ -433,9 +435,9 @@ discard block |
||
433 | 435 | } |
434 | 436 | } |
435 | 437 | } |
436 | - }elseif($decoder === 'iconv') { |
|
438 | + } elseif($decoder === 'iconv') { |
|
437 | 439 | $value = iconv_mime_decode($value); |
438 | - }else{ |
|
440 | + } else{ |
|
439 | 441 | $value = mb_decode_mimeheader($value); |
440 | 442 | } |
441 | 443 | |
@@ -468,7 +470,9 @@ discard block |
||
468 | 470 | * Try to extract the priority from a given raw header string |
469 | 471 | */ |
470 | 472 | private function findPriority() { |
471 | - if(($priority = $this->get("x_priority")) === null) return; |
|
473 | + if(($priority = $this->get("x_priority")) === null) { |
|
474 | + return; |
|
475 | + } |
|
472 | 476 | switch((int)"$priority"){ |
473 | 477 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
474 | 478 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
@@ -591,7 +595,7 @@ discard block |
||
591 | 595 | foreach ($this->attributes as $key => $value) { |
592 | 596 | if (is_array($value)) { |
593 | 597 | $value = implode(", ", $value); |
594 | - }else{ |
|
598 | + } else{ |
|
595 | 599 | $value = (string)$value; |
596 | 600 | } |
597 | 601 | // Only parse strings and don't parse any attributes like the user-agent |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | * @param object $object |
45 | 45 | */ |
46 | 46 | public function __construct($object) { |
47 | - if (property_exists($object, "personal")){ $this->personal = $object->personal; } |
|
48 | - if (property_exists($object, "mailbox")){ $this->mailbox = $object->mailbox; } |
|
49 | - if (property_exists($object, "host")){ $this->host = $object->host; } |
|
50 | - if (property_exists($object, "mail")){ $this->mail = $object->mail; } |
|
51 | - if (property_exists($object, "full")){ $this->full = $object->full; } |
|
47 | + if (property_exists($object, "personal")) { $this->personal = $object->personal; } |
|
48 | + if (property_exists($object, "mailbox")) { $this->mailbox = $object->mailbox; } |
|
49 | + if (property_exists($object, "host")) { $this->host = $object->host; } |
|
50 | + if (property_exists($object, "mail")) { $this->mail = $object->mail; } |
|
51 | + if (property_exists($object, "full")) { $this->full = $object->full; } |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function __serialize(){ |
|
69 | + public function __serialize() { |
|
70 | 70 | return [ |
71 | 71 | "personal" => $this->personal, |
72 | 72 | "mailbox" => $this->mailbox, |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return array |
83 | 83 | */ |
84 | - public function toArray(){ |
|
84 | + public function toArray() { |
|
85 | 85 | return $this->__serialize(); |
86 | 86 | } |
87 | 87 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - public function toString(){ |
|
93 | + public function toString() { |
|
94 | 94 | return $this->__toString(); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | \ No newline at end of file |