Completed
Push — master ( 92912a...d77b64 )
by Malte
02:03
created
src/Message.php 2 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_flags = false, $sequence = null) {
203 203
 
204 204
         $default_mask = $client->getDefaultMessageMask();
205
-        if($default_mask != null) {
205
+        if ($default_mask != null) {
206 206
             $this->mask = $default_mask;
207 207
         }
208 208
         $this->events["message"] = $client->getDefaultEvents("message");
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
      * @throws MessageFlagException
262 262
      * @throws Exceptions\RuntimeException
263 263
      */
264
-    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null){
264
+    public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null) {
265 265
         $reflection = new \ReflectionClass(self::class);
266 266
         /** @var self $instance */
267 267
         $instance = $reflection->newInstanceWithoutConstructor();
268 268
 
269 269
         $default_mask = $client->getDefaultMessageMask();
270
-        if($default_mask != null) {
270
+        if ($default_mask != null) {
271 271
             $instance->setMask($default_mask);
272 272
         }
273 273
         $instance->setEvents([
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
      * @throws MethodNotFoundException
303 303
      */
304 304
     public function __call($method, $arguments) {
305
-        if(strtolower(substr($method, 0, 3)) === 'get') {
305
+        if (strtolower(substr($method, 0, 3)) === 'get') {
306 306
             $name = Str::snake(substr($method, 3));
307 307
             return $this->get($name);
308 308
         }elseif (strtolower(substr($method, 0, 3)) === 'set') {
309 309
             $name = Str::snake(substr($method, 3));
310 310
 
311
-            if(in_array($name, array_keys($this->attributes))) {
311
+            if (in_array($name, array_keys($this->attributes))) {
312 312
                 return $this->__set($name, array_pop($arguments));
313 313
             }
314 314
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      * @return mixed|null
348 348
      */
349 349
     public function get($name) {
350
-        if(isset($this->attributes[$name])) {
350
+        if (isset($this->attributes[$name])) {
351 351
             return $this->attributes[$name];
352 352
         }
353 353
 
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
      *
422 422
      * @throws InvalidMessageDateException
423 423
      */
424
-    public function parseRawHeader($raw_header){
424
+    public function parseRawHeader($raw_header) {
425 425
         $this->header = new Header($raw_header);
426 426
     }
427 427
 
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
     public function parseRawFlags($raw_flags) {
433 433
         $this->flags = FlagCollection::make([]);
434 434
 
435
-        foreach($raw_flags as $flag) {
436
-            if (strpos($flag, "\\") === 0){
435
+        foreach ($raw_flags as $flag) {
436
+            if (strpos($flag, "\\") === 0) {
437 437
                 $flag = substr($flag, 1);
438 438
             }
439 439
             $flag_key = strtolower($flag);
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
      * @throws Exceptions\EventNotFoundException
504 504
      * @throws MessageFlagException
505 505
      */
506
-    public function peek(){
506
+    public function peek() {
507 507
         if ($this->fetch_options == IMAP::FT_PEEK) {
508 508
             if ($this->getFlags()->get("seen") == null) {
509 509
                 $this->unsetFlag("Seen");
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
     private function fetchPart(Part $part) {
551 551
         if ($part->isAttachment()) {
552 552
             $this->fetchAttachment($part);
553
-        }else{
553
+        }else {
554 554
             $encoding = $this->getEncoding($part);
555 555
 
556 556
             $content = $this->decodeString($part->content, $part->encoding);
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) {
588 588
             if ($oAttachment->getId() !== null) {
589 589
                 $this->attachments->put($oAttachment->getId(), $oAttachment);
590
-            } else {
590
+            }else {
591 591
                 $this->attachments->push($oAttachment);
592 592
             }
593 593
         }
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 
722 722
         if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
723 723
             return @iconv($from, $to.'//IGNORE', $str);
724
-        } else {
724
+        }else {
725 725
             if (!$from) {
726 726
                 return mb_convert_encoding($str, $to);
727 727
             }
@@ -742,9 +742,9 @@  discard block
 block discarded – undo
742 742
                     return EncodingAliases::get($parameter->value);
743 743
                 }
744 744
             }
745
-        }elseif (property_exists($structure, 'charset')){
745
+        }elseif (property_exists($structure, 'charset')) {
746 746
             return EncodingAliases::get($structure->charset);
747
-        }elseif (is_string($structure) === true){
747
+        }elseif (is_string($structure) === true) {
748 748
             return mb_detect_encoding($structure);
749 749
         }
750 750
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
      * @throws Exceptions\ConnectionFailedException
759 759
      * @throws Exceptions\FolderFetchingException
760 760
      */
761
-    public function getFolder(){
761
+    public function getFolder() {
762 762
         return $this->client->getFolder($this->folder_path);
763 763
     }
764 764
 
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
      * @throws Exceptions\FolderFetchingException
774 774
      * @throws Exceptions\GetMessagesFailedException
775 775
      */
776
-    public function thread($sent_folder = null, &$thread = null, $folder = null){
776
+    public function thread($sent_folder = null, &$thread = null, $folder = null) {
777 777
         $thread = $thread ? $thread : MessageCollection::make([]);
778
-        $folder = $folder ? $folder :  $this->getFolder();
778
+        $folder = $folder ? $folder : $this->getFolder();
779 779
         $sent_folder = $sent_folder ? $sent_folder : $this->client->getFolder(ClientManager::get("options.common_folders.sent", "INBOX/Sent"));
780 780
 
781 781
         /** @var Message $message */
782
-        foreach($thread as $message) {
782
+        foreach ($thread as $message) {
783 783
             if ($message->message_id == $this->message_id) {
784 784
                 return $thread;
785 785
             }
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
         $this->fetchThreadByInReplyTo($thread, $this->message_id, $sent_folder, $folder, $sent_folder);
791 791
 
792 792
         if (is_array($this->in_reply_to)) {
793
-            foreach($this->in_reply_to as $in_reply_to) {
793
+            foreach ($this->in_reply_to as $in_reply_to) {
794 794
                 $this->fetchThreadByMessageId($thread, $in_reply_to, $folder, $folder, $sent_folder);
795 795
                 $this->fetchThreadByMessageId($thread, $in_reply_to, $sent_folder, $folder, $sent_folder);
796 796
             }
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
      * @throws Exceptions\ConnectionFailedException
811 811
      * @throws Exceptions\GetMessagesFailedException
812 812
      */
813
-    protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder){
813
+    protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder) {
814 814
         $primary_folder->query()->inReplyTo($in_reply_to)
815 815
         ->setFetchBody($this->getFetchBodyOption())
816 816
         ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
      * @throws Exceptions\ConnectionFailedException
831 831
      * @throws Exceptions\GetMessagesFailedException
832 832
      */
833
-    protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder){
833
+    protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder) {
834 834
         $primary_folder->query()->messageId($message_id)
835 835
         ->setFetchBody($this->getFetchBodyOption())
836 836
         ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){
@@ -923,14 +923,14 @@  discard block
 block discarded – undo
923 923
      * @throws MessageFlagException
924 924
      * @throws MessageHeaderFetchingException
925 925
      */
926
-    protected function fetchNewMail($folder, $next_uid, $event, $expunge){
927
-        if($expunge) $this->client->expunge();
926
+    protected function fetchNewMail($folder, $next_uid, $event, $expunge) {
927
+        if ($expunge) $this->client->expunge();
928 928
 
929 929
         $this->client->openFolder($folder->path);
930 930
 
931 931
         if ($this->sequence === IMAP::ST_UID) {
932 932
             $sequence_id = $next_uid;
933
-        }else{
933
+        }else {
934 934
             $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
935 935
         }
936 936
 
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
      */
953 953
     public function delete($expunge = true) {
954 954
         $status = $this->setFlag("Deleted");
955
-        if($expunge) $this->client->expunge();
955
+        if ($expunge) $this->client->expunge();
956 956
 
957 957
         $event = $this->getEvent("message", "deleted");
958 958
         $event::dispatch($this);
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
      */
972 972
     public function restore($expunge = true) {
973 973
         $status = $this->unsetFlag("Deleted");
974
-        if($expunge) $this->client->expunge();
974
+        if ($expunge) $this->client->expunge();
975 975
 
976 976
         $event = $this->getEvent("message", "restored");
977 977
         $event::dispatch($this);
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
      *
1073 1073
      * @return AttachmentCollection
1074 1074
      */
1075
-    public function attachments(){
1075
+    public function attachments() {
1076 1076
         return $this->getAttachments();
1077 1077
     }
1078 1078
 
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
      *
1170 1170
      * @return FlagCollection
1171 1171
      */
1172
-    public function flags(){
1172
+    public function flags() {
1173 1173
         return $this->getFlags();
1174 1174
     }
1175 1175
 
@@ -1178,7 +1178,7 @@  discard block
 block discarded – undo
1178 1178
      *
1179 1179
      * @return Structure|null
1180 1180
      */
1181
-    public function getStructure(){
1181
+    public function getStructure() {
1182 1182
         return $this->structure;
1183 1183
     }
1184 1184
 
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
      *
1205 1205
      * @return array
1206 1206
      */
1207
-    public function getAttributes(){
1207
+    public function getAttributes() {
1208 1208
         return array_merge($this->attributes, $this->header->getAttributes());
1209 1209
     }
1210 1210
 
@@ -1214,8 +1214,8 @@  discard block
 block discarded – undo
1214 1214
      *
1215 1215
      * @return $this
1216 1216
      */
1217
-    public function setMask($mask){
1218
-        if(class_exists($mask)){
1217
+    public function setMask($mask) {
1218
+        if (class_exists($mask)) {
1219 1219
             $this->mask = $mask;
1220 1220
         }
1221 1221
 
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
      *
1228 1228
      * @return string
1229 1229
      */
1230
-    public function getMask(){
1230
+    public function getMask() {
1231 1231
         return $this->mask;
1232 1232
     }
1233 1233
 
@@ -1238,9 +1238,9 @@  discard block
 block discarded – undo
1238 1238
      * @return mixed
1239 1239
      * @throws MaskNotFoundException
1240 1240
      */
1241
-    public function mask($mask = null){
1241
+    public function mask($mask = null) {
1242 1242
         $mask = $mask !== null ? $mask : $this->mask;
1243
-        if(class_exists($mask)){
1243
+        if (class_exists($mask)) {
1244 1244
             return new $mask($this);
1245 1245
         }
1246 1246
 
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
      *
1254 1254
      * @return $this
1255 1255
      */
1256
-    public function setFolderPath($folder_path){
1256
+    public function setFolderPath($folder_path) {
1257 1257
         $this->folder_path = $folder_path;
1258 1258
 
1259 1259
         return $this;
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
      *
1266 1266
      * @return $this
1267 1267
      */
1268
-    public function setConfig($config){
1268
+    public function setConfig($config) {
1269 1269
         $this->config = $config;
1270 1270
 
1271 1271
         return $this;
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
      *
1278 1278
      * @return $this
1279 1279
      */
1280
-    public function setAvailableFlags($available_flags){
1280
+    public function setAvailableFlags($available_flags) {
1281 1281
         $this->available_flags = $available_flags;
1282 1282
 
1283 1283
         return $this;
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
      *
1290 1290
      * @return $this
1291 1291
      */
1292
-    public function setAttachments($attachments){
1292
+    public function setAttachments($attachments) {
1293 1293
         $this->attachments = $attachments;
1294 1294
 
1295 1295
         return $this;
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
      *
1302 1302
      * @return $this
1303 1303
      */
1304
-    public function setFlags($flags){
1304
+    public function setFlags($flags) {
1305 1305
         $this->flags = $flags;
1306 1306
 
1307 1307
         return $this;
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
      * @throws Exceptions\ConnectionFailedException
1315 1315
      * @return $this
1316 1316
      */
1317
-    public function setClient($client){
1317
+    public function setClient($client) {
1318 1318
         $this->client = $client;
1319 1319
         $this->client->openFolder($this->folder_path);
1320 1320
 
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
      * @throws Exceptions\RuntimeException
1330 1330
      * @return $this
1331 1331
      */
1332
-    public function setUid($uid){
1332
+    public function setUid($uid) {
1333 1333
         $this->uid = $uid;
1334 1334
         $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
1335 1335
         $this->msglist = null;
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
      * @throws Exceptions\RuntimeException
1347 1347
      * @return $this
1348 1348
      */
1349
-    public function setMsgn($msgn, $msglist = null){
1349
+    public function setMsgn($msgn, $msglist = null) {
1350 1350
         $this->msgn = $msgn;
1351 1351
         $this->msglist = $msglist;
1352 1352
         $this->uid = $this->client->getConnection()->getUid($this->msgn);
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
      *
1360 1360
      * @return int
1361 1361
      */
1362
-    public function getSequence(){
1362
+    public function getSequence() {
1363 1363
         return $this->sequence;
1364 1364
     }
1365 1365
 
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
      *
1369 1369
      * @return int
1370 1370
      */
1371
-    public function getSequenceId(){
1371
+    public function getSequenceId() {
1372 1372
         return $this->sequence === IMAP::ST_UID ? $this->uid : $this->msgn;
1373 1373
     }
1374 1374
 
@@ -1380,11 +1380,11 @@  discard block
 block discarded – undo
1380 1380
      * @throws Exceptions\ConnectionFailedException
1381 1381
      * @throws Exceptions\RuntimeException
1382 1382
      */
1383
-    public function setSequenceId($uid, $msglist = null){
1383
+    public function setSequenceId($uid, $msglist = null) {
1384 1384
         if ($this->getSequence() === IMAP::ST_UID) {
1385 1385
             $this->setUid($uid);
1386 1386
             $this->setMsglist($msglist);
1387
-        }else{
1387
+        }else {
1388 1388
             $this->setMsgn($uid, $msglist);
1389 1389
         }
1390 1390
     }
Please login to merge, or discard this patch.
Braces   +16 added lines, -10 removed lines patch added patch discarded remove patch
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
         if(strtolower(substr($method, 0, 3)) === 'get') {
306 306
             $name = Str::snake(substr($method, 3));
307 307
             return $this->get($name);
308
-        }elseif (strtolower(substr($method, 0, 3)) === 'set') {
308
+        } elseif (strtolower(substr($method, 0, 3)) === 'set') {
309 309
             $name = Str::snake(substr($method, 3));
310 310
 
311 311
             if(in_array($name, array_keys($this->attributes))) {
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
             if ($this->getFlags()->get("seen") == null) {
509 509
                 $this->unsetFlag("Seen");
510 510
             }
511
-        }elseif ($this->getFlags()->get("seen") != null) {
511
+        } elseif ($this->getFlags()->get("seen") != null) {
512 512
             $this->setFlag("Seen");
513 513
         }
514 514
     }
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
     private function fetchPart(Part $part) {
551 551
         if ($part->isAttachment()) {
552 552
             $this->fetchAttachment($part);
553
-        }else{
553
+        } else{
554 554
             $encoding = $this->getEncoding($part);
555 555
 
556 556
             $content = $this->decodeString($part->content, $part->encoding);
@@ -742,9 +742,9 @@  discard block
 block discarded – undo
742 742
                     return EncodingAliases::get($parameter->value);
743 743
                 }
744 744
             }
745
-        }elseif (property_exists($structure, 'charset')){
745
+        } elseif (property_exists($structure, 'charset')){
746 746
             return EncodingAliases::get($structure->charset);
747
-        }elseif (is_string($structure) === true){
747
+        } elseif (is_string($structure) === true){
748 748
             return mb_detect_encoding($structure);
749 749
         }
750 750
 
@@ -924,13 +924,15 @@  discard block
 block discarded – undo
924 924
      * @throws MessageHeaderFetchingException
925 925
      */
926 926
     protected function fetchNewMail($folder, $next_uid, $event, $expunge){
927
-        if($expunge) $this->client->expunge();
927
+        if($expunge) {
928
+            $this->client->expunge();
929
+        }
928 930
 
929 931
         $this->client->openFolder($folder->path);
930 932
 
931 933
         if ($this->sequence === IMAP::ST_UID) {
932 934
             $sequence_id = $next_uid;
933
-        }else{
935
+        } else{
934 936
             $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid);
935 937
         }
936 938
 
@@ -952,7 +954,9 @@  discard block
 block discarded – undo
952 954
      */
953 955
     public function delete($expunge = true) {
954 956
         $status = $this->setFlag("Deleted");
955
-        if($expunge) $this->client->expunge();
957
+        if($expunge) {
958
+            $this->client->expunge();
959
+        }
956 960
 
957 961
         $event = $this->getEvent("message", "deleted");
958 962
         $event::dispatch($this);
@@ -971,7 +975,9 @@  discard block
 block discarded – undo
971 975
      */
972 976
     public function restore($expunge = true) {
973 977
         $status = $this->unsetFlag("Deleted");
974
-        if($expunge) $this->client->expunge();
978
+        if($expunge) {
979
+            $this->client->expunge();
980
+        }
975 981
 
976 982
         $event = $this->getEvent("message", "restored");
977 983
         $event::dispatch($this);
@@ -1384,7 +1390,7 @@  discard block
 block discarded – undo
1384 1390
         if ($this->getSequence() === IMAP::ST_UID) {
1385 1391
             $this->setUid($uid);
1386 1392
             $this->setMsglist($msglist);
1387
-        }else{
1393
+        } else{
1388 1394
             $this->setMsgn($uid, $msglist);
1389 1395
         }
1390 1396
     }
Please login to merge, or discard this patch.