@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @throws MethodNotFoundException |
67 | 67 | */ |
68 | 68 | public function __call($method, $arguments) { |
69 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
69 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
70 | 70 | $name = Str::snake(substr($method, 3)); |
71 | 71 | |
72 | - if(in_array($name, array_keys($this->attributes))) { |
|
72 | + if (in_array($name, array_keys($this->attributes))) { |
|
73 | 73 | return $this->attributes[$name]; |
74 | 74 | } |
75 | 75 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @return mixed|null |
94 | 94 | */ |
95 | 95 | public function get($name) { |
96 | - if(isset($this->attributes[$name])) { |
|
96 | + if (isset($this->attributes[$name])) { |
|
97 | 97 | return $this->attributes[$name]; |
98 | 98 | } |
99 | 99 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | public function find($pattern) { |
109 | 109 | if (preg_match_all($pattern, $this->raw, $matches)) { |
110 | 110 | if (isset($matches[1])) { |
111 | - if(count($matches[1]) > 0) { |
|
111 | + if (count($matches[1]) > 0) { |
|
112 | 112 | return $matches[1][0]; |
113 | 113 | } |
114 | 114 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * Parse the raw headers |
121 | 121 | * @throws InvalidMessageDateException |
122 | 122 | */ |
123 | - protected function parse(){ |
|
123 | + protected function parse() { |
|
124 | 124 | $header = $this->rfc822_parse_headers($this->raw); |
125 | 125 | |
126 | 126 | $this->extractAddresses($header); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $this->parseDate($header); |
139 | 139 | foreach ($header as $key => $value) { |
140 | 140 | $key = trim(rtrim(strtolower($key))); |
141 | - if(!isset($this->attributes[$key])){ |
|
141 | + if (!isset($this->attributes[$key])) { |
|
142 | 142 | $this->attributes[$key] = $value; |
143 | 143 | } |
144 | 144 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return object |
156 | 156 | */ |
157 | - public function rfc822_parse_headers($raw_headers){ |
|
157 | + public function rfc822_parse_headers($raw_headers) { |
|
158 | 158 | $headers = []; |
159 | 159 | $imap_headers = []; |
160 | 160 | if (extension_loaded('imap')) { |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | |
164 | 164 | $lines = explode("\r\n", $raw_headers); |
165 | 165 | $prev_header = null; |
166 | - foreach($lines as $line) { |
|
166 | + foreach ($lines as $line) { |
|
167 | 167 | if (substr($line, 0, 1) === "\t") { |
168 | 168 | $line = substr($line, 2); |
169 | 169 | if ($prev_header !== null) { |
170 | 170 | $headers[$prev_header][] = $line; |
171 | 171 | } |
172 | - }else{ |
|
172 | + }else { |
|
173 | 173 | if (($pos = strpos($line, ":")) > 0) { |
174 | 174 | $key = strtolower(substr($line, 0, $pos)); |
175 | 175 | $value = trim(rtrim(strtolower(substr($line, $pos + 1)))); |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | - foreach($headers as $key => $values) { |
|
182 | + foreach ($headers as $key => $values) { |
|
183 | 183 | if (isset($imap_headers[$key])) continue; |
184 | 184 | $value = null; |
185 | - switch($key){ |
|
185 | + switch ($key) { |
|
186 | 186 | case 'from': |
187 | 187 | case 'to': |
188 | 188 | case 'cc': |
@@ -209,12 +209,12 @@ discard block |
||
209 | 209 | * @return array The decoded elements are returned in an array of objects, where each |
210 | 210 | * object has two properties, charset and text. |
211 | 211 | */ |
212 | - public function mime_header_decode($text){ |
|
212 | + public function mime_header_decode($text) { |
|
213 | 213 | if (extension_loaded('imap')) { |
214 | 214 | return \imap_mime_header_decode($text); |
215 | 215 | } |
216 | 216 | $charset = $this->getEncoding($text); |
217 | - return [(object)[ |
|
217 | + return [(object) [ |
|
218 | 218 | "charset" => $charset, |
219 | 219 | "text" => $this->convertEncoding($text, $charset) |
220 | 220 | ]]; |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | try { |
269 | 269 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
270 | 270 | return iconv($from, $to, $str); |
271 | - } else { |
|
271 | + }else { |
|
272 | 272 | if (!$from) { |
273 | 273 | return mb_convert_encoding($str, $to); |
274 | 274 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | if (strstr($from, '-')) { |
279 | 279 | $from = str_replace('-', '', $from); |
280 | 280 | return $this->convertEncoding($str, $from, $to); |
281 | - } else { |
|
281 | + }else { |
|
282 | 282 | return $str; |
283 | 283 | } |
284 | 284 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | } |
301 | 301 | }elseif (property_exists($structure, 'charset')) { |
302 | 302 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
303 | - }elseif (is_string($structure) === true){ |
|
303 | + }elseif (is_string($structure) === true) { |
|
304 | 304 | return mb_detect_encoding($structure); |
305 | 305 | } |
306 | 306 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $decoder = $this->config['decoder']['message']; |
319 | 319 | |
320 | 320 | if ($value !== null) { |
321 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
321 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
322 | 322 | $value = \imap_utf8($value); |
323 | 323 | if (Str::startsWith(mb_strtolower($value), '=?utf-8?')) { |
324 | 324 | $value = mb_decode_mimeheader($value); |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | if ($this->notDecoded($original_value, $value)) { |
327 | 327 | $value = $this->mime_header_decode(imap_utf8($value)); |
328 | 328 | } |
329 | - }elseif($decoder === 'iconv') { |
|
329 | + }elseif ($decoder === 'iconv') { |
|
330 | 330 | $value = iconv_mime_decode($value); |
331 | - }else{ |
|
331 | + }else { |
|
332 | 332 | $value = mb_decode_mimeheader($value); |
333 | 333 | } |
334 | 334 | |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | * Try to extract the priority from a given raw header string |
345 | 345 | */ |
346 | 346 | private function findPriority() { |
347 | - if(($priority = $this->get("x-priority")) === null) return; |
|
348 | - switch($priority){ |
|
347 | + if (($priority = $this->get("x-priority")) === null) return; |
|
348 | + switch ($priority) { |
|
349 | 349 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
350 | 350 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
351 | 351 | break; |
@@ -377,12 +377,12 @@ discard block |
||
377 | 377 | */ |
378 | 378 | private function decodeAddresses($values) { |
379 | 379 | $addresses = []; |
380 | - foreach($values as $address) { |
|
380 | + foreach ($values as $address) { |
|
381 | 381 | if (preg_match( |
382 | 382 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
383 | 383 | $address, |
384 | 384 | $matches |
385 | - )){ |
|
385 | + )) { |
|
386 | 386 | $name = trim(rtrim($matches["name"])); |
387 | 387 | $email = trim(rtrim($matches["email"])); |
388 | 388 | list($mailbox, $host) = explode("@", $email); |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @param object $header |
402 | 402 | */ |
403 | 403 | private function extractAddresses($header) { |
404 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key){ |
|
404 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key) { |
|
405 | 405 | if (property_exists($header, $key)) { |
406 | 406 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
407 | 407 | } |
@@ -428,10 +428,10 @@ discard block |
||
428 | 428 | } |
429 | 429 | if (!property_exists($address, 'personal')) { |
430 | 430 | $address->personal = false; |
431 | - } else { |
|
431 | + }else { |
|
432 | 432 | $personalParts = $this->mime_header_decode($address->personal); |
433 | 433 | |
434 | - if(is_array($personalParts)) { |
|
434 | + if (is_array($personalParts)) { |
|
435 | 435 | $address->personal = ''; |
436 | 436 | foreach ($personalParts as $p) { |
437 | 437 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -448,15 +448,15 @@ discard block |
||
448 | 448 | return $addresses; |
449 | 449 | } |
450 | 450 | |
451 | - private function extractHeaderExtensions(){ |
|
451 | + private function extractHeaderExtensions() { |
|
452 | 452 | foreach ($this->attributes as $key => $value) { |
453 | 453 | if (is_string($value) === true) { |
454 | - if (($pos = strpos($value, ";")) !== false){ |
|
454 | + if (($pos = strpos($value, ";")) !== false) { |
|
455 | 455 | $original = substr($value, 0, $pos); |
456 | 456 | $this->attributes[$key] = trim(rtrim($original)); |
457 | 457 | $extensions = explode(";", substr($value, $pos + 1)); |
458 | - foreach($extensions as $extension) { |
|
459 | - if (($pos = strpos($extension, "=")) !== false){ |
|
458 | + foreach ($extensions as $extension) { |
|
459 | + if (($pos = strpos($extension, "=")) !== false) { |
|
460 | 460 | $key = substr($extension, 0, $pos); |
461 | 461 | $value = substr($extension, $pos + 1); |
462 | 462 | $this->attributes[trim(rtrim(strtolower($key)))] = trim(rtrim($value)); |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | $parsed_date = null; |
493 | 493 | $date = $header->date; |
494 | 494 | |
495 | - if(preg_match('/\+0580/', $date)) { |
|
495 | + if (preg_match('/\+0580/', $date)) { |
|
496 | 496 | $date = str_replace('+0580', '+0530', $date); |
497 | 497 | } |
498 | 498 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | $date = trim(array_pop($array)); |
516 | 516 | break; |
517 | 517 | } |
518 | - try{ |
|
518 | + try { |
|
519 | 519 | $parsed_date = Carbon::parse($date); |
520 | 520 | } catch (\Exception $_e) { |
521 | 521 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | if ($prev_header !== null) { |
170 | 170 | $headers[$prev_header][] = $line; |
171 | 171 | } |
172 | - }else{ |
|
172 | + } else{ |
|
173 | 173 | if (($pos = strpos($line, ":")) > 0) { |
174 | 174 | $key = strtolower(substr($line, 0, $pos)); |
175 | 175 | $value = trim(rtrim(strtolower(substr($line, $pos + 1)))); |
@@ -180,7 +180,9 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | foreach($headers as $key => $values) { |
183 | - if (isset($imap_headers[$key])) continue; |
|
183 | + if (isset($imap_headers[$key])) { |
|
184 | + continue; |
|
185 | + } |
|
184 | 186 | $value = null; |
185 | 187 | switch($key){ |
186 | 188 | case 'from': |
@@ -298,9 +300,9 @@ discard block |
||
298 | 300 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
299 | 301 | } |
300 | 302 | } |
301 | - }elseif (property_exists($structure, 'charset')) { |
|
303 | + } elseif (property_exists($structure, 'charset')) { |
|
302 | 304 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
303 | - }elseif (is_string($structure) === true){ |
|
305 | + } elseif (is_string($structure) === true){ |
|
304 | 306 | return mb_detect_encoding($structure); |
305 | 307 | } |
306 | 308 | |
@@ -326,9 +328,9 @@ discard block |
||
326 | 328 | if ($this->notDecoded($original_value, $value)) { |
327 | 329 | $value = $this->mime_header_decode(imap_utf8($value)); |
328 | 330 | } |
329 | - }elseif($decoder === 'iconv') { |
|
331 | + } elseif($decoder === 'iconv') { |
|
330 | 332 | $value = iconv_mime_decode($value); |
331 | - }else{ |
|
333 | + } else{ |
|
332 | 334 | $value = mb_decode_mimeheader($value); |
333 | 335 | } |
334 | 336 | |
@@ -344,7 +346,9 @@ discard block |
||
344 | 346 | * Try to extract the priority from a given raw header string |
345 | 347 | */ |
346 | 348 | private function findPriority() { |
347 | - if(($priority = $this->get("x-priority")) === null) return; |
|
349 | + if(($priority = $this->get("x-priority")) === null) { |
|
350 | + return; |
|
351 | + } |
|
348 | 352 | switch($priority){ |
349 | 353 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
350 | 354 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |