@@ -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, |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function __serialize(){ |
|
63 | + public function __serialize() { |
|
64 | 64 | return $this->values; |
65 | 65 | } |
66 | 66 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | if ($this->contains($value) === false) { |
124 | 124 | $this->values[] = $value; |
125 | 125 | } |
126 | - }else{ |
|
126 | + }else { |
|
127 | 127 | $this->values[] = $value; |
128 | 128 | } |
129 | 129 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @return Attribute |
136 | 136 | */ |
137 | - public function setName($name){ |
|
137 | + public function setName($name) { |
|
138 | 138 | $this->name = $name; |
139 | 139 | |
140 | 140 | return $this; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - public function getName(){ |
|
148 | + public function getName() { |
|
149 | 149 | return $this->name; |
150 | 150 | } |
151 | 151 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - public function get(){ |
|
157 | + public function get() { |
|
158 | 158 | return $this->values; |
159 | 159 | } |
160 | 160 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return array |
165 | 165 | */ |
166 | - public function all(){ |
|
166 | + public function all() { |
|
167 | 167 | return $this->get(); |
168 | 168 | } |
169 | 169 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return mixed|null |
174 | 174 | */ |
175 | - public function first(){ |
|
175 | + public function first() { |
|
176 | 176 | if (count($this->values) > 0) { |
177 | 177 | return $this->values[0]; |
178 | 178 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return mixed|null |
186 | 186 | */ |
187 | - public function last(){ |
|
187 | + public function last() { |
|
188 | 188 | $cnt = count($this->values); |
189 | 189 | if ($cnt > 0) { |
190 | 190 | return $this->values[$cnt - 1]; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function add($value, $strict = false) { |
75 | 75 | if (is_array($value)) { |
76 | 76 | return $this->merge($value, $strict); |
77 | - }elseif ($value !== null) { |
|
77 | + } elseif ($value !== null) { |
|
78 | 78 | $this->attach($value, $strict); |
79 | 79 | } |
80 | 80 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | if ($this->contains($value) === false) { |
124 | 124 | $this->values[] = $value; |
125 | 125 | } |
126 | - }else{ |
|
126 | + } else{ |
|
127 | 127 | $this->values[] = $value; |
128 | 128 | } |
129 | 129 | } |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @throws MethodNotFoundException |
74 | 74 | */ |
75 | 75 | public function __call($method, $arguments) { |
76 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
76 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
77 | 77 | $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3)); |
78 | 78 | |
79 | - if(in_array($name, array_keys($this->attributes))) { |
|
79 | + if (in_array($name, array_keys($this->attributes))) { |
|
80 | 80 | return $this->attributes[$name]; |
81 | 81 | } |
82 | 82 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return Attribute|null |
103 | 103 | */ |
104 | 104 | public function get($name) { |
105 | - if(isset($this->attributes[$name])) { |
|
105 | + if (isset($this->attributes[$name])) { |
|
106 | 106 | return $this->attributes[$name]; |
107 | 107 | } |
108 | 108 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * @return Attribute |
119 | 119 | */ |
120 | 120 | public function set($name, $value, $strict = false) { |
121 | - if(isset($this->attributes[$name]) && $strict === false) { |
|
121 | + if (isset($this->attributes[$name]) && $strict === false) { |
|
122 | 122 | $this->attributes[$name]->add($value, true); |
123 | - }else{ |
|
123 | + }else { |
|
124 | 124 | $this->attributes[$name] = new Attribute($name, $value); |
125 | 125 | } |
126 | 126 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | public function find($pattern) { |
137 | 137 | if (preg_match_all($pattern, $this->raw, $matches)) { |
138 | 138 | if (isset($matches[1])) { |
139 | - if(count($matches[1]) > 0) { |
|
139 | + if (count($matches[1]) > 0) { |
|
140 | 140 | return $matches[1][0]; |
141 | 141 | } |
142 | 142 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @throws InvalidMessageDateException |
151 | 151 | */ |
152 | - protected function parse(){ |
|
152 | + protected function parse() { |
|
153 | 153 | $header = $this->rfc822_parse_headers($this->raw); |
154 | 154 | |
155 | 155 | $this->extractAddresses($header); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $this->parseDate($header); |
168 | 168 | foreach ($header as $key => $value) { |
169 | 169 | $key = trim(rtrim(strtolower($key))); |
170 | - if(!isset($this->attributes[$key])){ |
|
170 | + if (!isset($this->attributes[$key])) { |
|
171 | 171 | $this->set($key, $value); |
172 | 172 | } |
173 | 173 | } |
@@ -183,12 +183,12 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return object |
185 | 185 | */ |
186 | - public function rfc822_parse_headers($raw_headers){ |
|
186 | + public function rfc822_parse_headers($raw_headers) { |
|
187 | 187 | $headers = []; |
188 | 188 | $imap_headers = []; |
189 | 189 | if (extension_loaded('imap')) { |
190 | 190 | $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw); |
191 | - foreach($raw_imap_headers as $key => $values) { |
|
191 | + foreach ($raw_imap_headers as $key => $values) { |
|
192 | 192 | $key = str_replace("-", "_", $key); |
193 | 193 | $imap_headers[$key] = $values; |
194 | 194 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | |
197 | 197 | $lines = explode("\r\n", $raw_headers); |
198 | 198 | $prev_header = null; |
199 | - foreach($lines as $line) { |
|
199 | + foreach ($lines as $line) { |
|
200 | 200 | if (substr($line, 0, 1) === "\n") { |
201 | 201 | $line = substr($line, 1); |
202 | 202 | } |
@@ -216,19 +216,19 @@ discard block |
||
216 | 216 | } |
217 | 217 | if (is_array($headers[$prev_header])) { |
218 | 218 | $headers[$prev_header][] = $line; |
219 | - }else{ |
|
219 | + }else { |
|
220 | 220 | $headers[$prev_header] .= $line; |
221 | 221 | } |
222 | 222 | } |
223 | - }else{ |
|
223 | + }else { |
|
224 | 224 | if (($pos = strpos($line, ":")) > 0) { |
225 | 225 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
226 | 226 | $key = str_replace("-", "_", $key); |
227 | 227 | |
228 | 228 | $value = trim(rtrim(substr($line, $pos + 1))); |
229 | 229 | if (isset($headers[$key])) { |
230 | - $headers[$key][] = $value; |
|
231 | - }else{ |
|
230 | + $headers[$key][] = $value; |
|
231 | + }else { |
|
232 | 232 | $headers[$key] = [$value]; |
233 | 233 | } |
234 | 234 | $prev_header = $key; |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - foreach($headers as $key => $values) { |
|
239 | + foreach ($headers as $key => $values) { |
|
240 | 240 | if (isset($imap_headers[$key])) continue; |
241 | 241 | $value = null; |
242 | - switch($key){ |
|
242 | + switch ($key) { |
|
243 | 243 | case 'from': |
244 | 244 | case 'to': |
245 | 245 | case 'cc': |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | break; |
255 | 255 | default: |
256 | 256 | if (is_array($values)) { |
257 | - foreach($values as $k => $v) { |
|
257 | + foreach ($values as $k => $v) { |
|
258 | 258 | if ($v == "") { |
259 | 259 | unset($values[$k]); |
260 | 260 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $value = implode(" ", $values); |
267 | 267 | } elseif ($available_values > 2) { |
268 | 268 | $value = array_values($values); |
269 | - } else { |
|
269 | + }else { |
|
270 | 270 | $value = ""; |
271 | 271 | } |
272 | 272 | } |
@@ -286,12 +286,12 @@ discard block |
||
286 | 286 | * @return array The decoded elements are returned in an array of objects, where each |
287 | 287 | * object has two properties, charset and text. |
288 | 288 | */ |
289 | - public function mime_header_decode($text){ |
|
289 | + public function mime_header_decode($text) { |
|
290 | 290 | if (extension_loaded('imap')) { |
291 | 291 | return \imap_mime_header_decode($text); |
292 | 292 | } |
293 | 293 | $charset = $this->getEncoding($text); |
294 | - return [(object)[ |
|
294 | + return [(object) [ |
|
295 | 295 | "charset" => $charset, |
296 | 296 | "text" => $this->convertEncoding($text, $charset) |
297 | 297 | ]]; |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | try { |
346 | 346 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
347 | 347 | return iconv($from, $to, $str); |
348 | - } else { |
|
348 | + }else { |
|
349 | 349 | if (!$from) { |
350 | 350 | return mb_convert_encoding($str, $to); |
351 | 351 | } |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | if (strstr($from, '-')) { |
356 | 356 | $from = str_replace('-', '', $from); |
357 | 357 | return $this->convertEncoding($str, $from, $to); |
358 | - } else { |
|
358 | + }else { |
|
359 | 359 | return $str; |
360 | 360 | } |
361 | 361 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | } |
377 | 377 | }elseif (property_exists($structure, 'charset')) { |
378 | 378 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
379 | - }elseif (is_string($structure) === true){ |
|
379 | + }elseif (is_string($structure) === true) { |
|
380 | 380 | return mb_detect_encoding($structure); |
381 | 381 | } |
382 | 382 | |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | $decoder = $this->config['decoder']['message']; |
398 | 398 | |
399 | 399 | if ($value !== null) { |
400 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
400 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
401 | 401 | $value = \imap_utf8($value); |
402 | 402 | if (strpos(strtolower($value), '=?utf-8?') === 0) { |
403 | 403 | $value = mb_decode_mimeheader($value); |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | if ($this->notDecoded($original_value, $value)) { |
406 | 406 | $decoded_value = $this->mime_header_decode($value); |
407 | 407 | if (count($decoded_value) > 0) { |
408 | - if(property_exists($decoded_value[0], "text")) { |
|
408 | + if (property_exists($decoded_value[0], "text")) { |
|
409 | 409 | $value = $decoded_value[0]->text; |
410 | 410 | } |
411 | 411 | } |
412 | 412 | } |
413 | - }elseif($decoder === 'iconv') { |
|
413 | + }elseif ($decoder === 'iconv') { |
|
414 | 414 | $value = iconv_mime_decode($value); |
415 | - }else{ |
|
415 | + }else { |
|
416 | 416 | $value = mb_decode_mimeheader($value); |
417 | 417 | } |
418 | 418 | |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @return array |
436 | 436 | */ |
437 | 437 | private function decodeArray($values) { |
438 | - foreach($values as $key => $value) { |
|
438 | + foreach ($values as $key => $value) { |
|
439 | 439 | $values[$key] = $this->decode($value); |
440 | 440 | } |
441 | 441 | return $values; |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * Try to extract the priority from a given raw header string |
446 | 446 | */ |
447 | 447 | private function findPriority() { |
448 | - if(($priority = $this->get("x_priority")) === null) return; |
|
449 | - switch((int)"$priority"){ |
|
448 | + if (($priority = $this->get("x_priority")) === null) return; |
|
449 | + switch ((int) "$priority") { |
|
450 | 450 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
451 | 451 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
452 | 452 | break; |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | */ |
479 | 479 | private function decodeAddresses($values) { |
480 | 480 | $addresses = []; |
481 | - foreach($values as $address) { |
|
481 | + foreach ($values as $address) { |
|
482 | 482 | $address = trim(rtrim($address)); |
483 | 483 | if (strpos($address, ",") == strlen($address) - 1) { |
484 | 484 | $address = substr($address, 0, -1); |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/', |
488 | 488 | $address, |
489 | 489 | $matches |
490 | - )){ |
|
490 | + )) { |
|
491 | 491 | $name = trim(rtrim($matches["name"])); |
492 | 492 | $email = trim(rtrim($matches["email"])); |
493 | 493 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * @param object $header |
507 | 507 | */ |
508 | 508 | private function extractAddresses($header) { |
509 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
509 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
510 | 510 | if (property_exists($header, $key)) { |
511 | 511 | $this->set($key, $this->parseAddresses($header->$key)); |
512 | 512 | } |
@@ -537,10 +537,10 @@ discard block |
||
537 | 537 | } |
538 | 538 | if (!property_exists($address, 'personal')) { |
539 | 539 | $address->personal = false; |
540 | - } else { |
|
540 | + }else { |
|
541 | 541 | $personalParts = $this->mime_header_decode($address->personal); |
542 | 542 | |
543 | - if(is_array($personalParts)) { |
|
543 | + if (is_array($personalParts)) { |
|
544 | 544 | $address->personal = ''; |
545 | 545 | foreach ($personalParts as $p) { |
546 | 546 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -564,19 +564,19 @@ discard block |
||
564 | 564 | /** |
565 | 565 | * Search and extract potential header extensions |
566 | 566 | */ |
567 | - private function extractHeaderExtensions(){ |
|
567 | + private function extractHeaderExtensions() { |
|
568 | 568 | foreach ($this->attributes as $key => $value) { |
569 | - $value = (string)$value; |
|
569 | + $value = (string) $value; |
|
570 | 570 | // Only parse strings and don't parse any attributes like the user-agent |
571 | 571 | if (in_array($key, ["user_agent"]) === false) { |
572 | - if (($pos = strpos($value, ";")) !== false){ |
|
572 | + if (($pos = strpos($value, ";")) !== false) { |
|
573 | 573 | $original = substr($value, 0, $pos); |
574 | 574 | $this->set($key, trim(rtrim($original)), true); |
575 | 575 | |
576 | 576 | // Get all potential extensions |
577 | 577 | $extensions = explode(";", substr($value, $pos + 1)); |
578 | - foreach($extensions as $extension) { |
|
579 | - if (($pos = strpos($extension, "=")) !== false){ |
|
578 | + foreach ($extensions as $extension) { |
|
579 | + if (($pos = strpos($extension, "=")) !== false) { |
|
580 | 580 | $key = substr($extension, 0, $pos); |
581 | 581 | $key = trim(rtrim(strtolower($key))); |
582 | 582 | |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | $parsed_date = null; |
620 | 620 | $date = $header->date; |
621 | 621 | |
622 | - if(preg_match('/\+0580/', $date)) { |
|
622 | + if (preg_match('/\+0580/', $date)) { |
|
623 | 623 | $date = str_replace('+0580', '+0530', $date); |
624 | 624 | } |
625 | 625 | |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | $date = trim(array_pop($array)); |
643 | 643 | break; |
644 | 644 | } |
645 | - try{ |
|
645 | + try { |
|
646 | 646 | $parsed_date = Carbon::parse($date); |
647 | 647 | } catch (\Exception $_e) { |
648 | 648 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | public function set($name, $value, $strict = false) { |
121 | 121 | if(isset($this->attributes[$name]) && $strict === false) { |
122 | 122 | $this->attributes[$name]->add($value, true); |
123 | - }else{ |
|
123 | + } else{ |
|
124 | 124 | $this->attributes[$name] = new Attribute($name, $value); |
125 | 125 | } |
126 | 126 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | if ($prev_header !== null) { |
208 | 208 | $headers[$prev_header][] = $line; |
209 | 209 | } |
210 | - }elseif (substr($line, 0, 1) === " ") { |
|
210 | + } elseif (substr($line, 0, 1) === " ") { |
|
211 | 211 | $line = substr($line, 1); |
212 | 212 | $line = trim(rtrim($line)); |
213 | 213 | if ($prev_header !== null) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } |
217 | 217 | if (is_array($headers[$prev_header])) { |
218 | 218 | $headers[$prev_header][] = $line; |
219 | - }else{ |
|
219 | + } else{ |
|
220 | 220 | $headers[$prev_header] .= $line; |
221 | 221 | } |
222 | 222 | } |
223 | - }else{ |
|
223 | + } else{ |
|
224 | 224 | if (($pos = strpos($line, ":")) > 0) { |
225 | 225 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
226 | 226 | $key = str_replace("-", "_", $key); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $value = trim(rtrim(substr($line, $pos + 1))); |
229 | 229 | if (isset($headers[$key])) { |
230 | 230 | $headers[$key][] = $value; |
231 | - }else{ |
|
231 | + } else{ |
|
232 | 232 | $headers[$key] = [$value]; |
233 | 233 | } |
234 | 234 | $prev_header = $key; |
@@ -237,7 +237,9 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | foreach($headers as $key => $values) { |
240 | - if (isset($imap_headers[$key])) continue; |
|
240 | + if (isset($imap_headers[$key])) { |
|
241 | + continue; |
|
242 | + } |
|
241 | 243 | $value = null; |
242 | 244 | switch($key){ |
243 | 245 | case 'from': |
@@ -374,9 +376,9 @@ discard block |
||
374 | 376 | return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
375 | 377 | } |
376 | 378 | } |
377 | - }elseif (property_exists($structure, 'charset')) { |
|
379 | + } elseif (property_exists($structure, 'charset')) { |
|
378 | 380 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
379 | - }elseif (is_string($structure) === true){ |
|
381 | + } elseif (is_string($structure) === true){ |
|
380 | 382 | return mb_detect_encoding($structure); |
381 | 383 | } |
382 | 384 | |
@@ -410,9 +412,9 @@ discard block |
||
410 | 412 | } |
411 | 413 | } |
412 | 414 | } |
413 | - }elseif($decoder === 'iconv') { |
|
415 | + } elseif($decoder === 'iconv') { |
|
414 | 416 | $value = iconv_mime_decode($value); |
415 | - }else{ |
|
417 | + } else{ |
|
416 | 418 | $value = mb_decode_mimeheader($value); |
417 | 419 | } |
418 | 420 | |
@@ -445,7 +447,9 @@ discard block |
||
445 | 447 | * Try to extract the priority from a given raw header string |
446 | 448 | */ |
447 | 449 | private function findPriority() { |
448 | - if(($priority = $this->get("x_priority")) === null) return; |
|
450 | + if(($priority = $this->get("x_priority")) === null) { |
|
451 | + return; |
|
452 | + } |
|
449 | 453 | switch((int)"$priority"){ |
450 | 454 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
451 | 455 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |