@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @throws MethodNotFoundException |
66 | 66 | */ |
67 | 67 | public function __call($method, $arguments) { |
68 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
68 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
69 | 69 | $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3)); |
70 | 70 | |
71 | - if(in_array($name, array_keys($this->attributes))) { |
|
71 | + if (in_array($name, array_keys($this->attributes))) { |
|
72 | 72 | return $this->attributes[$name]; |
73 | 73 | } |
74 | 74 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @return mixed|null |
93 | 93 | */ |
94 | 94 | public function get($name) { |
95 | - if(isset($this->attributes[$name])) { |
|
95 | + if (isset($this->attributes[$name])) { |
|
96 | 96 | return $this->attributes[$name]; |
97 | 97 | } |
98 | 98 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | public function find($pattern) { |
108 | 108 | if (preg_match_all($pattern, $this->raw, $matches)) { |
109 | 109 | if (isset($matches[1])) { |
110 | - if(count($matches[1]) > 0) { |
|
110 | + if (count($matches[1]) > 0) { |
|
111 | 111 | return $matches[1][0]; |
112 | 112 | } |
113 | 113 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * Parse the raw headers |
120 | 120 | * @throws InvalidMessageDateException |
121 | 121 | */ |
122 | - protected function parse(){ |
|
122 | + protected function parse() { |
|
123 | 123 | $header = $this->rfc822_parse_headers($this->raw); |
124 | 124 | |
125 | 125 | $this->extractAddresses($header); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->parseDate($header); |
138 | 138 | foreach ($header as $key => $value) { |
139 | 139 | $key = trim(rtrim(strtolower($key))); |
140 | - if(!isset($this->attributes[$key])){ |
|
140 | + if (!isset($this->attributes[$key])) { |
|
141 | 141 | $this->attributes[$key] = $value; |
142 | 142 | } |
143 | 143 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return object |
155 | 155 | */ |
156 | - public function rfc822_parse_headers($raw_headers){ |
|
156 | + public function rfc822_parse_headers($raw_headers) { |
|
157 | 157 | $headers = []; |
158 | 158 | $imap_headers = []; |
159 | 159 | if (extension_loaded('imap')) { |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | |
163 | 163 | $lines = explode("\r\n", $raw_headers); |
164 | 164 | $prev_header = null; |
165 | - foreach($lines as $line) { |
|
165 | + foreach ($lines as $line) { |
|
166 | 166 | if (substr($line, 0, 1) === "\t") { |
167 | 167 | $line = substr($line, 2); |
168 | 168 | if ($prev_header !== null) { |
169 | 169 | $headers[$prev_header][] = $line; |
170 | 170 | } |
171 | - }else{ |
|
171 | + }else { |
|
172 | 172 | if (($pos = strpos($line, ":")) > 0) { |
173 | 173 | $key = strtolower(substr($line, 0, $pos)); |
174 | 174 | $value = trim(rtrim(strtolower(substr($line, $pos + 1)))); |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - foreach($headers as $key => $values) { |
|
181 | + foreach ($headers as $key => $values) { |
|
182 | 182 | if (isset($imap_headers[$key])) continue; |
183 | 183 | $value = null; |
184 | - switch($key){ |
|
184 | + switch ($key) { |
|
185 | 185 | case 'from': |
186 | 186 | case 'to': |
187 | 187 | case 'cc': |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | * @return array The decoded elements are returned in an array of objects, where each |
209 | 209 | * object has two properties, charset and text. |
210 | 210 | */ |
211 | - public function mime_header_decode($text){ |
|
211 | + public function mime_header_decode($text) { |
|
212 | 212 | if (extension_loaded('imap')) { |
213 | 213 | return \imap_mime_header_decode($text); |
214 | 214 | } |
215 | 215 | $charset = $this->getEncoding($text); |
216 | - return [(object)[ |
|
216 | + return [(object) [ |
|
217 | 217 | "charset" => $charset, |
218 | 218 | "text" => $this->convertEncoding($text, $charset) |
219 | 219 | ]]; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | try { |
268 | 268 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
269 | 269 | return iconv($from, $to, $str); |
270 | - } else { |
|
270 | + }else { |
|
271 | 271 | if (!$from) { |
272 | 272 | return mb_convert_encoding($str, $to); |
273 | 273 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | if (strstr($from, '-')) { |
278 | 278 | $from = str_replace('-', '', $from); |
279 | 279 | return $this->convertEncoding($str, $from, $to); |
280 | - } else { |
|
280 | + }else { |
|
281 | 281 | return $str; |
282 | 282 | } |
283 | 283 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | }elseif (property_exists($structure, 'charset')) { |
301 | 301 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
302 | - }elseif (is_string($structure) === true){ |
|
302 | + }elseif (is_string($structure) === true) { |
|
303 | 303 | return mb_detect_encoding($structure); |
304 | 304 | } |
305 | 305 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $decoder = $this->config['decoder']['message']; |
318 | 318 | |
319 | 319 | if ($value !== null) { |
320 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
320 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
321 | 321 | $value = \imap_utf8($value); |
322 | 322 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
323 | 323 | $value = mb_decode_mimeheader($value); |
@@ -325,14 +325,14 @@ discard block |
||
325 | 325 | if ($this->notDecoded($original_value, $value)) { |
326 | 326 | $decoded_value = $this->mime_header_decode($value); |
327 | 327 | if (count($decoded_value) > 0) { |
328 | - if(property_exists($decoded_value[0], "text")) { |
|
328 | + if (property_exists($decoded_value[0], "text")) { |
|
329 | 329 | $value = $decoded_value[0]->text; |
330 | 330 | } |
331 | 331 | } |
332 | 332 | } |
333 | - }elseif($decoder === 'iconv') { |
|
333 | + }elseif ($decoder === 'iconv') { |
|
334 | 334 | $value = iconv_mime_decode($value); |
335 | - }else{ |
|
335 | + }else { |
|
336 | 336 | $value = mb_decode_mimeheader($value); |
337 | 337 | } |
338 | 338 | |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | * Try to extract the priority from a given raw header string |
353 | 353 | */ |
354 | 354 | private function findPriority() { |
355 | - if(($priority = $this->get("x-priority")) === null) return; |
|
356 | - switch($priority){ |
|
355 | + if (($priority = $this->get("x-priority")) === null) return; |
|
356 | + switch ($priority) { |
|
357 | 357 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
358 | 358 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
359 | 359 | break; |
@@ -385,12 +385,12 @@ discard block |
||
385 | 385 | */ |
386 | 386 | private function decodeAddresses($values) { |
387 | 387 | $addresses = []; |
388 | - foreach($values as $address) { |
|
388 | + foreach ($values as $address) { |
|
389 | 389 | if (preg_match( |
390 | 390 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
391 | 391 | $address, |
392 | 392 | $matches |
393 | - )){ |
|
393 | + )) { |
|
394 | 394 | $name = trim(rtrim($matches["name"])); |
395 | 395 | $email = trim(rtrim($matches["email"])); |
396 | 396 | list($mailbox, $host) = explode("@", $email); |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @param object $header |
410 | 410 | */ |
411 | 411 | private function extractAddresses($header) { |
412 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key){ |
|
412 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender', 'in_reply_to'] as $key) { |
|
413 | 413 | if (property_exists($header, $key)) { |
414 | 414 | $this->attributes[$key] = $this->parseAddresses($header->$key); |
415 | 415 | } |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | } |
437 | 437 | if (!property_exists($address, 'personal')) { |
438 | 438 | $address->personal = false; |
439 | - } else { |
|
439 | + }else { |
|
440 | 440 | $personalParts = $this->mime_header_decode($address->personal); |
441 | 441 | |
442 | - if(is_array($personalParts)) { |
|
442 | + if (is_array($personalParts)) { |
|
443 | 443 | $address->personal = ''; |
444 | 444 | foreach ($personalParts as $p) { |
445 | 445 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -456,15 +456,15 @@ discard block |
||
456 | 456 | return $addresses; |
457 | 457 | } |
458 | 458 | |
459 | - private function extractHeaderExtensions(){ |
|
459 | + private function extractHeaderExtensions() { |
|
460 | 460 | foreach ($this->attributes as $key => $value) { |
461 | 461 | if (is_string($value) === true) { |
462 | - if (($pos = strpos($value, ";")) !== false){ |
|
462 | + if (($pos = strpos($value, ";")) !== false) { |
|
463 | 463 | $original = substr($value, 0, $pos); |
464 | 464 | $this->attributes[$key] = trim(rtrim($original)); |
465 | 465 | $extensions = explode(";", substr($value, $pos + 1)); |
466 | - foreach($extensions as $extension) { |
|
467 | - if (($pos = strpos($extension, "=")) !== false){ |
|
466 | + foreach ($extensions as $extension) { |
|
467 | + if (($pos = strpos($extension, "=")) !== false) { |
|
468 | 468 | $key = substr($extension, 0, $pos); |
469 | 469 | $value = substr($extension, $pos + 1); |
470 | 470 | $this->attributes[trim(rtrim(strtolower($key)))] = trim(rtrim($value)); |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $parsed_date = null; |
501 | 501 | $date = $header->date; |
502 | 502 | |
503 | - if(preg_match('/\+0580/', $date)) { |
|
503 | + if (preg_match('/\+0580/', $date)) { |
|
504 | 504 | $date = str_replace('+0580', '+0530', $date); |
505 | 505 | } |
506 | 506 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $date = trim(array_pop($array)); |
524 | 524 | break; |
525 | 525 | } |
526 | - try{ |
|
526 | + try { |
|
527 | 527 | $parsed_date = Carbon::parse($date); |
528 | 528 | } catch (\Exception $_e) { |
529 | 529 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | if ($prev_header !== null) { |
169 | 169 | $headers[$prev_header][] = $line; |
170 | 170 | } |
171 | - }else{ |
|
171 | + } else{ |
|
172 | 172 | if (($pos = strpos($line, ":")) > 0) { |
173 | 173 | $key = strtolower(substr($line, 0, $pos)); |
174 | 174 | $value = trim(rtrim(strtolower(substr($line, $pos + 1)))); |
@@ -179,7 +179,9 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | foreach($headers as $key => $values) { |
182 | - if (isset($imap_headers[$key])) continue; |
|
182 | + if (isset($imap_headers[$key])) { |
|
183 | + continue; |
|
184 | + } |
|
183 | 185 | $value = null; |
184 | 186 | switch($key){ |
185 | 187 | case 'from': |
@@ -297,9 +299,9 @@ discard block |
||
297 | 299 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
298 | 300 | } |
299 | 301 | } |
300 | - }elseif (property_exists($structure, 'charset')) { |
|
302 | + } elseif (property_exists($structure, 'charset')) { |
|
301 | 303 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
302 | - }elseif (is_string($structure) === true){ |
|
304 | + } elseif (is_string($structure) === true){ |
|
303 | 305 | return mb_detect_encoding($structure); |
304 | 306 | } |
305 | 307 | |
@@ -330,9 +332,9 @@ discard block |
||
330 | 332 | } |
331 | 333 | } |
332 | 334 | } |
333 | - }elseif($decoder === 'iconv') { |
|
335 | + } elseif($decoder === 'iconv') { |
|
334 | 336 | $value = iconv_mime_decode($value); |
335 | - }else{ |
|
337 | + } else{ |
|
336 | 338 | $value = mb_decode_mimeheader($value); |
337 | 339 | } |
338 | 340 | |
@@ -352,7 +354,9 @@ discard block |
||
352 | 354 | * Try to extract the priority from a given raw header string |
353 | 355 | */ |
354 | 356 | private function findPriority() { |
355 | - if(($priority = $this->get("x-priority")) === null) return; |
|
357 | + if(($priority = $this->get("x-priority")) === null) { |
|
358 | + return; |
|
359 | + } |
|
356 | 360 | switch($priority){ |
357 | 361 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
358 | 362 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |