@@ -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 | $value = str_replace('"', "", $value); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | $parsed_date = null; |
502 | 502 | $date = $header->date; |
503 | 503 | |
504 | - if(preg_match('/\+0580/', $date)) { |
|
504 | + if (preg_match('/\+0580/', $date)) { |
|
505 | 505 | $date = str_replace('+0580', '+0530', $date); |
506 | 506 | } |
507 | 507 | |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | $date = trim(array_pop($array)); |
525 | 525 | break; |
526 | 526 | } |
527 | - try{ |
|
527 | + try { |
|
528 | 528 | $parsed_date = Carbon::parse($date); |
529 | 529 | } catch (\Exception $_e) { |
530 | 530 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @throws InvalidMessageDateException |
120 | 120 | */ |
121 | - protected function parse(){ |
|
121 | + protected function parse() { |
|
122 | 122 | if ($this->header === null) { |
123 | 123 | $body = $this->findHeaders(); |
124 | - }else{ |
|
124 | + }else { |
|
125 | 125 | $body = $this->raw; |
126 | 126 | } |
127 | 127 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return string |
146 | 146 | * @throws InvalidMessageDateException |
147 | 147 | */ |
148 | - private function findHeaders(){ |
|
148 | + private function findHeaders() { |
|
149 | 149 | $body = $this->raw; |
150 | 150 | while (($pos = strpos($body, "\r\n")) > 0) { |
151 | 151 | $body = substr($body, $pos + 2); |
@@ -158,32 +158,32 @@ discard block |
||
158 | 158 | return (string) $body; |
159 | 159 | } |
160 | 160 | |
161 | - private function parseSubtype(){ |
|
161 | + private function parseSubtype() { |
|
162 | 162 | $content_type = $this->header->get("content-type"); |
163 | - if (($pos = strpos($content_type, "/")) !== false){ |
|
163 | + if (($pos = strpos($content_type, "/")) !== false) { |
|
164 | 164 | $this->subtype = substr($content_type, $pos + 1); |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - private function parseDisposition(){ |
|
168 | + private function parseDisposition() { |
|
169 | 169 | $content_disposition = $this->header->get("content-disposition"); |
170 | - if($content_disposition !== null) { |
|
170 | + if ($content_disposition !== null) { |
|
171 | 171 | $this->ifdisposition = true; |
172 | 172 | $this->disposition = $content_disposition; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - private function parseDescription(){ |
|
176 | + private function parseDescription() { |
|
177 | 177 | $content_description = $this->header->get("content-description"); |
178 | - if($content_description !== null) { |
|
178 | + if ($content_description !== null) { |
|
179 | 179 | $this->ifdescription = true; |
180 | 180 | $this->description = $content_description; |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - private function parseEncoding(){ |
|
184 | + private function parseEncoding() { |
|
185 | 185 | $encoding = $this->header->get("content-transfer-encoding"); |
186 | - if($encoding !== null) { |
|
186 | + if ($encoding !== null) { |
|
187 | 187 | switch (strtolower($encoding)) { |
188 | 188 | case "quoted-printable": |
189 | 189 | $this->encoding = IMAP::MESSAGE_ENC_QUOTED_PRINTABLE; |
@@ -121,7 +121,7 @@ |
||
121 | 121 | protected function parse(){ |
122 | 122 | if ($this->header === null) { |
123 | 123 | $body = $this->findHeaders(); |
124 | - }else{ |
|
124 | + } else{ |
|
125 | 125 | $body = $this->raw; |
126 | 126 | } |
127 | 127 |