@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $this->boot(); |
| 193 | 193 | |
| 194 | 194 | $default_mask = $client->getDefaultMessageMask(); |
| 195 | - if($default_mask != null) { |
|
| 195 | + if ($default_mask != null) { |
|
| 196 | 196 | $this->mask = $default_mask; |
| 197 | 197 | } |
| 198 | 198 | $this->events["message"] = $client->getDefaultEvents("message"); |
@@ -246,14 +246,14 @@ discard block |
||
| 246 | 246 | * @throws Exceptions\RuntimeException |
| 247 | 247 | * @throws Exceptions\MessageNotFoundException |
| 248 | 248 | */ |
| 249 | - public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null){ |
|
| 249 | + public static function make($uid, $msglist, Client $client, $raw_header, $raw_body, $raw_flags, $fetch_options = null, $sequence = null) { |
|
| 250 | 250 | $reflection = new ReflectionClass(self::class); |
| 251 | 251 | /** @var self $instance */ |
| 252 | 252 | $instance = $reflection->newInstanceWithoutConstructor(); |
| 253 | 253 | $instance->boot(); |
| 254 | 254 | |
| 255 | 255 | $default_mask = $client->getDefaultMessageMask(); |
| 256 | - if($default_mask != null) { |
|
| 256 | + if ($default_mask != null) { |
|
| 257 | 257 | $instance->setMask($default_mask); |
| 258 | 258 | } |
| 259 | 259 | $instance->setEvents([ |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | /** |
| 279 | 279 | * Boot a new instance |
| 280 | 280 | */ |
| 281 | - public function boot(){ |
|
| 281 | + public function boot() { |
|
| 282 | 282 | $this->attributes = []; |
| 283 | 283 | |
| 284 | 284 | $this->config = ClientManager::get('options'); |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | * @throws MethodNotFoundException |
| 298 | 298 | */ |
| 299 | 299 | public function __call($method, $arguments) { |
| 300 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 300 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 301 | 301 | $name = Str::snake(substr($method, 3)); |
| 302 | 302 | return $this->get($name); |
| 303 | 303 | }elseif (strtolower(substr($method, 0, 3)) === 'set') { |
| 304 | 304 | $name = Str::snake(substr($method, 3)); |
| 305 | 305 | |
| 306 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 306 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 307 | 307 | return $this->__set($name, array_pop($arguments)); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * @return Attribute|mixed|null |
| 343 | 343 | */ |
| 344 | 344 | public function get($name) { |
| 345 | - if(isset($this->attributes[$name])) { |
|
| 345 | + if (isset($this->attributes[$name])) { |
|
| 346 | 346 | return $this->attributes[$name]; |
| 347 | 347 | } |
| 348 | 348 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @throws InvalidMessageDateException |
| 418 | 418 | */ |
| 419 | - public function parseRawHeader($raw_header){ |
|
| 419 | + public function parseRawHeader($raw_header) { |
|
| 420 | 420 | $this->header = new Header($raw_header); |
| 421 | 421 | } |
| 422 | 422 | |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | public function parseRawFlags($raw_flags) { |
| 428 | 428 | $this->flags = FlagCollection::make([]); |
| 429 | 429 | |
| 430 | - foreach($raw_flags as $flag) { |
|
| 431 | - if (strpos($flag, "\\") === 0){ |
|
| 430 | + foreach ($raw_flags as $flag) { |
|
| 431 | + if (strpos($flag, "\\") === 0) { |
|
| 432 | 432 | $flag = substr($flag, 1); |
| 433 | 433 | } |
| 434 | 434 | $flag_key = strtolower($flag); |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | * @throws MessageFlagException |
| 502 | 502 | * @throws Exceptions\RuntimeException |
| 503 | 503 | */ |
| 504 | - public function peek(){ |
|
| 504 | + public function peek() { |
|
| 505 | 505 | if ($this->fetch_options == IMAP::FT_PEEK) { |
| 506 | 506 | if ($this->getFlags()->get("seen") == null) { |
| 507 | 507 | $this->unsetFlag("Seen"); |
@@ -550,7 +550,7 @@ discard block |
||
| 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); |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | |
| 576 | 576 | if (isset($this->bodies[$subtype])) { |
| 577 | 577 | $this->bodies[$subtype] .= "\n".$content; |
| 578 | - }else{ |
|
| 578 | + }else { |
|
| 579 | 579 | $this->bodies[$subtype] = $content; |
| 580 | 580 | } |
| 581 | 581 | } |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) { |
| 592 | 592 | if ($oAttachment->getId() !== null) { |
| 593 | 593 | $this->attachments->put($oAttachment->getId(), $oAttachment); |
| 594 | - } else { |
|
| 594 | + }else { |
|
| 595 | 595 | $this->attachments->push($oAttachment); |
| 596 | 596 | } |
| 597 | 597 | } |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | |
| 726 | 726 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 727 | 727 | return @iconv($from, $to.'//IGNORE', $str); |
| 728 | - } else { |
|
| 728 | + }else { |
|
| 729 | 729 | if (!$from) { |
| 730 | 730 | return mb_convert_encoding($str, $to); |
| 731 | 731 | } |
@@ -746,9 +746,9 @@ discard block |
||
| 746 | 746 | return EncodingAliases::get($parameter->value); |
| 747 | 747 | } |
| 748 | 748 | } |
| 749 | - }elseif (property_exists($structure, 'charset')){ |
|
| 749 | + }elseif (property_exists($structure, 'charset')) { |
|
| 750 | 750 | return EncodingAliases::get($structure->charset); |
| 751 | - }elseif (is_string($structure) === true){ |
|
| 751 | + }elseif (is_string($structure) === true) { |
|
| 752 | 752 | return mb_detect_encoding($structure); |
| 753 | 753 | } |
| 754 | 754 | |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * @throws Exceptions\FolderFetchingException |
| 764 | 764 | * @throws Exceptions\RuntimeException |
| 765 | 765 | */ |
| 766 | - public function getFolder(){ |
|
| 766 | + public function getFolder() { |
|
| 767 | 767 | return $this->client->getFolderByPath($this->folder_path); |
| 768 | 768 | } |
| 769 | 769 | |
@@ -779,13 +779,13 @@ discard block |
||
| 779 | 779 | * @throws Exceptions\GetMessagesFailedException |
| 780 | 780 | * @throws Exceptions\RuntimeException |
| 781 | 781 | */ |
| 782 | - public function thread($sent_folder = null, &$thread = null, $folder = null){ |
|
| 782 | + public function thread($sent_folder = null, &$thread = null, $folder = null) { |
|
| 783 | 783 | $thread = $thread ? $thread : MessageCollection::make([]); |
| 784 | - $folder = $folder ? $folder : $this->getFolder(); |
|
| 784 | + $folder = $folder ? $folder : $this->getFolder(); |
|
| 785 | 785 | $sent_folder = $sent_folder ? $sent_folder : $this->client->getFolderByPath(ClientManager::get("options.common_folders.sent", "INBOX/Sent")); |
| 786 | 786 | |
| 787 | 787 | /** @var Message $message */ |
| 788 | - foreach($thread as $message) { |
|
| 788 | + foreach ($thread as $message) { |
|
| 789 | 789 | if ($message->message_id->first() == $this->message_id->first()) { |
| 790 | 790 | return $thread; |
| 791 | 791 | } |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | $this->fetchThreadByInReplyTo($thread, $this->message_id, $sent_folder, $folder, $sent_folder); |
| 797 | 797 | |
| 798 | 798 | if (is_array($this->in_reply_to)) { |
| 799 | - foreach($this->in_reply_to as $in_reply_to) { |
|
| 799 | + foreach ($this->in_reply_to as $in_reply_to) { |
|
| 800 | 800 | $this->fetchThreadByMessageId($thread, $in_reply_to, $folder, $folder, $sent_folder); |
| 801 | 801 | $this->fetchThreadByMessageId($thread, $in_reply_to, $sent_folder, $folder, $sent_folder); |
| 802 | 802 | } |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | * @throws Exceptions\GetMessagesFailedException |
| 818 | 818 | * @throws Exceptions\RuntimeException |
| 819 | 819 | */ |
| 820 | - protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder){ |
|
| 820 | + protected function fetchThreadByInReplyTo(&$thread, $in_reply_to, $primary_folder, $secondary_folder, $sent_folder) { |
|
| 821 | 821 | $primary_folder->query()->inReplyTo($in_reply_to) |
| 822 | 822 | ->setFetchBody($this->getFetchBodyOption()) |
| 823 | 823 | ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){ |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | * @throws Exceptions\GetMessagesFailedException |
| 839 | 839 | * @throws Exceptions\RuntimeException |
| 840 | 840 | */ |
| 841 | - protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder){ |
|
| 841 | + protected function fetchThreadByMessageId(&$thread, $message_id, $primary_folder, $secondary_folder, $sent_folder) { |
|
| 842 | 842 | $primary_folder->query()->messageId($message_id) |
| 843 | 843 | ->setFetchBody($this->getFetchBodyOption()) |
| 844 | 844 | ->leaveUnread()->get()->each(function($message) use(&$thread, $secondary_folder, $sent_folder){ |
@@ -934,14 +934,14 @@ discard block |
||
| 934 | 934 | * @throws MessageFlagException |
| 935 | 935 | * @throws MessageHeaderFetchingException |
| 936 | 936 | */ |
| 937 | - protected function fetchNewMail($folder, $next_uid, $event, $expunge){ |
|
| 938 | - if($expunge) $this->client->expunge(); |
|
| 937 | + protected function fetchNewMail($folder, $next_uid, $event, $expunge) { |
|
| 938 | + if ($expunge) $this->client->expunge(); |
|
| 939 | 939 | |
| 940 | 940 | $this->client->openFolder($folder->path); |
| 941 | 941 | |
| 942 | 942 | if ($this->sequence === IMAP::ST_UID) { |
| 943 | 943 | $sequence_id = $next_uid; |
| 944 | - }else{ |
|
| 944 | + }else { |
|
| 945 | 945 | $sequence_id = $this->client->getConnection()->getMessageNumber($next_uid); |
| 946 | 946 | } |
| 947 | 947 | |
@@ -964,7 +964,7 @@ discard block |
||
| 964 | 964 | */ |
| 965 | 965 | public function delete($expunge = true) { |
| 966 | 966 | $status = $this->setFlag("Deleted"); |
| 967 | - if($expunge) $this->client->expunge(); |
|
| 967 | + if ($expunge) $this->client->expunge(); |
|
| 968 | 968 | |
| 969 | 969 | $event = $this->getEvent("message", "deleted"); |
| 970 | 970 | $event::dispatch($this); |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | */ |
| 985 | 985 | public function restore($expunge = true) { |
| 986 | 986 | $status = $this->unsetFlag("Deleted"); |
| 987 | - if($expunge) $this->client->expunge(); |
|
| 987 | + if ($expunge) $this->client->expunge(); |
|
| 988 | 988 | |
| 989 | 989 | $event = $this->getEvent("message", "restored"); |
| 990 | 990 | $event::dispatch($this); |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | * |
| 1090 | 1090 | * @return AttachmentCollection |
| 1091 | 1091 | */ |
| 1092 | - public function attachments(){ |
|
| 1092 | + public function attachments() { |
|
| 1093 | 1093 | return $this->getAttachments(); |
| 1094 | 1094 | } |
| 1095 | 1095 | |
@@ -1187,7 +1187,7 @@ discard block |
||
| 1187 | 1187 | * |
| 1188 | 1188 | * @return FlagCollection |
| 1189 | 1189 | */ |
| 1190 | - public function flags(){ |
|
| 1190 | + public function flags() { |
|
| 1191 | 1191 | return $this->getFlags(); |
| 1192 | 1192 | } |
| 1193 | 1193 | |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | * |
| 1197 | 1197 | * @return Structure|null |
| 1198 | 1198 | */ |
| 1199 | - public function getStructure(){ |
|
| 1199 | + public function getStructure() { |
|
| 1200 | 1200 | return $this->structure; |
| 1201 | 1201 | } |
| 1202 | 1202 | |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | * |
| 1223 | 1223 | * @return array |
| 1224 | 1224 | */ |
| 1225 | - public function getAttributes(){ |
|
| 1225 | + public function getAttributes() { |
|
| 1226 | 1226 | return array_merge($this->attributes, $this->header->getAttributes()); |
| 1227 | 1227 | } |
| 1228 | 1228 | |
@@ -1232,8 +1232,8 @@ discard block |
||
| 1232 | 1232 | * |
| 1233 | 1233 | * @return $this |
| 1234 | 1234 | */ |
| 1235 | - public function setMask($mask){ |
|
| 1236 | - if(class_exists($mask)){ |
|
| 1235 | + public function setMask($mask) { |
|
| 1236 | + if (class_exists($mask)) { |
|
| 1237 | 1237 | $this->mask = $mask; |
| 1238 | 1238 | } |
| 1239 | 1239 | |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | * |
| 1246 | 1246 | * @return string |
| 1247 | 1247 | */ |
| 1248 | - public function getMask(){ |
|
| 1248 | + public function getMask() { |
|
| 1249 | 1249 | return $this->mask; |
| 1250 | 1250 | } |
| 1251 | 1251 | |
@@ -1256,9 +1256,9 @@ discard block |
||
| 1256 | 1256 | * @return mixed |
| 1257 | 1257 | * @throws MaskNotFoundException |
| 1258 | 1258 | */ |
| 1259 | - public function mask($mask = null){ |
|
| 1259 | + public function mask($mask = null) { |
|
| 1260 | 1260 | $mask = $mask !== null ? $mask : $this->mask; |
| 1261 | - if(class_exists($mask)){ |
|
| 1261 | + if (class_exists($mask)) { |
|
| 1262 | 1262 | return new $mask($this); |
| 1263 | 1263 | } |
| 1264 | 1264 | |
@@ -1270,7 +1270,7 @@ discard block |
||
| 1270 | 1270 | * |
| 1271 | 1271 | * @return string |
| 1272 | 1272 | */ |
| 1273 | - public function getFolderPath(){ |
|
| 1273 | + public function getFolderPath() { |
|
| 1274 | 1274 | return $this->folder_path; |
| 1275 | 1275 | } |
| 1276 | 1276 | |
@@ -1280,7 +1280,7 @@ discard block |
||
| 1280 | 1280 | * |
| 1281 | 1281 | * @return $this |
| 1282 | 1282 | */ |
| 1283 | - public function setFolderPath($folder_path){ |
|
| 1283 | + public function setFolderPath($folder_path) { |
|
| 1284 | 1284 | $this->folder_path = $folder_path; |
| 1285 | 1285 | |
| 1286 | 1286 | return $this; |
@@ -1292,7 +1292,7 @@ discard block |
||
| 1292 | 1292 | * |
| 1293 | 1293 | * @return $this |
| 1294 | 1294 | */ |
| 1295 | - public function setConfig($config){ |
|
| 1295 | + public function setConfig($config) { |
|
| 1296 | 1296 | $this->config = $config; |
| 1297 | 1297 | |
| 1298 | 1298 | return $this; |
@@ -1304,7 +1304,7 @@ discard block |
||
| 1304 | 1304 | * |
| 1305 | 1305 | * @return $this |
| 1306 | 1306 | */ |
| 1307 | - public function setAvailableFlags($available_flags){ |
|
| 1307 | + public function setAvailableFlags($available_flags) { |
|
| 1308 | 1308 | $this->available_flags = $available_flags; |
| 1309 | 1309 | |
| 1310 | 1310 | return $this; |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | * |
| 1317 | 1317 | * @return $this |
| 1318 | 1318 | */ |
| 1319 | - public function setAttachments($attachments){ |
|
| 1319 | + public function setAttachments($attachments) { |
|
| 1320 | 1320 | $this->attachments = $attachments; |
| 1321 | 1321 | |
| 1322 | 1322 | return $this; |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | * |
| 1329 | 1329 | * @return $this |
| 1330 | 1330 | */ |
| 1331 | - public function setFlags($flags){ |
|
| 1331 | + public function setFlags($flags) { |
|
| 1332 | 1332 | $this->flags = $flags; |
| 1333 | 1333 | |
| 1334 | 1334 | return $this; |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | * @throws Exceptions\RuntimeException |
| 1343 | 1343 | * @throws Exceptions\ConnectionFailedException |
| 1344 | 1344 | */ |
| 1345 | - public function setClient($client){ |
|
| 1345 | + public function setClient($client) { |
|
| 1346 | 1346 | $this->client = $client; |
| 1347 | 1347 | $this->client->openFolder($this->folder_path); |
| 1348 | 1348 | |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | * @throws Exceptions\MessageNotFoundException |
| 1358 | 1358 | * @throws Exceptions\ConnectionFailedException |
| 1359 | 1359 | */ |
| 1360 | - public function setUid($uid){ |
|
| 1360 | + public function setUid($uid) { |
|
| 1361 | 1361 | $this->uid = $uid; |
| 1362 | 1362 | $this->msgn = $this->client->getConnection()->getMessageNumber($this->uid); |
| 1363 | 1363 | $this->msglist = null; |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | * @throws Exceptions\MessageNotFoundException |
| 1375 | 1375 | * @throws Exceptions\ConnectionFailedException |
| 1376 | 1376 | */ |
| 1377 | - public function setMsgn($msgn, $msglist = null){ |
|
| 1377 | + public function setMsgn($msgn, $msglist = null) { |
|
| 1378 | 1378 | $this->msgn = $msgn; |
| 1379 | 1379 | $this->msglist = $msglist; |
| 1380 | 1380 | $this->uid = $this->client->getConnection()->getUid($this->msgn); |
@@ -1387,7 +1387,7 @@ discard block |
||
| 1387 | 1387 | * |
| 1388 | 1388 | * @return int |
| 1389 | 1389 | */ |
| 1390 | - public function getSequence(){ |
|
| 1390 | + public function getSequence() { |
|
| 1391 | 1391 | return $this->sequence; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1396,7 +1396,7 @@ discard block |
||
| 1396 | 1396 | * |
| 1397 | 1397 | * @return int |
| 1398 | 1398 | */ |
| 1399 | - public function getSequenceId(){ |
|
| 1399 | + public function getSequenceId() { |
|
| 1400 | 1400 | return $this->sequence === IMAP::ST_UID ? $this->uid : $this->msgn; |
| 1401 | 1401 | } |
| 1402 | 1402 | |
@@ -1408,11 +1408,11 @@ discard block |
||
| 1408 | 1408 | * @throws Exceptions\ConnectionFailedException |
| 1409 | 1409 | * @throws Exceptions\MessageNotFoundException |
| 1410 | 1410 | */ |
| 1411 | - public function setSequenceId($uid, $msglist = null){ |
|
| 1411 | + public function setSequenceId($uid, $msglist = null) { |
|
| 1412 | 1412 | if ($this->getSequence() === IMAP::ST_UID) { |
| 1413 | 1413 | $this->setUid($uid); |
| 1414 | 1414 | $this->setMsglist($msglist); |
| 1415 | - }else{ |
|
| 1415 | + }else { |
|
| 1416 | 1416 | $this->setMsgn($uid, $msglist); |
| 1417 | 1417 | } |
| 1418 | 1418 | } |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @throws MethodNotFoundException |
| 83 | 83 | */ |
| 84 | 84 | public function __call($method, $arguments) { |
| 85 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 85 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 86 | 86 | $name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3)); |
| 87 | 87 | |
| 88 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 88 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 89 | 89 | return $this->attributes[$name]; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return Attribute|mixed |
| 112 | 112 | */ |
| 113 | 113 | public function get($name) { |
| 114 | - if(isset($this->attributes[$name])) { |
|
| 114 | + if (isset($this->attributes[$name])) { |
|
| 115 | 115 | return $this->attributes[$name]; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -127,23 +127,23 @@ discard block |
||
| 127 | 127 | * @return Attribute |
| 128 | 128 | */ |
| 129 | 129 | public function set($name, $value, $strict = false) { |
| 130 | - if(isset($this->attributes[$name]) && $strict === false) { |
|
| 130 | + if (isset($this->attributes[$name]) && $strict === false) { |
|
| 131 | 131 | if ($this->attributize) { |
| 132 | 132 | $this->attributes[$name]->add($value, true); |
| 133 | - }else{ |
|
| 134 | - if(isset($this->attributes[$name])) { |
|
| 133 | + }else { |
|
| 134 | + if (isset($this->attributes[$name])) { |
|
| 135 | 135 | if (is_array($this->attributes[$name]) == false) { |
| 136 | 136 | $this->attributes[$name] = [$this->attributes[$name], $value]; |
| 137 | - }else{ |
|
| 137 | + }else { |
|
| 138 | 138 | $this->attributes[$name][] = $value; |
| 139 | 139 | } |
| 140 | - }else{ |
|
| 140 | + }else { |
|
| 141 | 141 | $this->attributes[$name] = $value; |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | - }elseif($this->attributize == false){ |
|
| 144 | + }elseif ($this->attributize == false) { |
|
| 145 | 145 | $this->attributes[$name] = $value; |
| 146 | - }else{ |
|
| 146 | + }else { |
|
| 147 | 147 | $this->attributes[$name] = new Attribute($name, $value); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | public function find($pattern) { |
| 160 | 160 | if (preg_match_all($pattern, $this->raw, $matches)) { |
| 161 | 161 | if (isset($matches[1])) { |
| 162 | - if(count($matches[1]) > 0) { |
|
| 162 | + if (count($matches[1]) > 0) { |
|
| 163 | 163 | return $matches[1][0]; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @return string|null |
| 174 | 174 | */ |
| 175 | - public function getBoundary(){ |
|
| 175 | + public function getBoundary() { |
|
| 176 | 176 | $boundary = $this->find("/boundary\=(.*)/i"); |
| 177 | 177 | |
| 178 | 178 | if ($boundary === null) { |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * |
| 198 | 198 | * @throws InvalidMessageDateException |
| 199 | 199 | */ |
| 200 | - protected function parse(){ |
|
| 200 | + protected function parse() { |
|
| 201 | 201 | $header = $this->rfc822_parse_headers($this->raw); |
| 202 | 202 | |
| 203 | 203 | $this->extractAddresses($header); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $this->parseDate($header); |
| 216 | 216 | foreach ($header as $key => $value) { |
| 217 | 217 | $key = trim(rtrim(strtolower($key))); |
| 218 | - if(!isset($this->attributes[$key])){ |
|
| 218 | + if (!isset($this->attributes[$key])) { |
|
| 219 | 219 | $this->set($key, $value); |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -231,19 +231,19 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return object |
| 233 | 233 | */ |
| 234 | - public function rfc822_parse_headers($raw_headers){ |
|
| 234 | + public function rfc822_parse_headers($raw_headers) { |
|
| 235 | 235 | $headers = []; |
| 236 | 236 | $imap_headers = []; |
| 237 | 237 | if (extension_loaded('imap') && $this->config["rfc822"]) { |
| 238 | 238 | $raw_imap_headers = (array) \imap_rfc822_parse_headers($this->raw); |
| 239 | - foreach($raw_imap_headers as $key => $values) { |
|
| 239 | + foreach ($raw_imap_headers as $key => $values) { |
|
| 240 | 240 | $key = str_replace("-", "_", $key); |
| 241 | 241 | $imap_headers[$key] = $values; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | $lines = explode("\r\n", str_replace("\r\n\t", ' ', $raw_headers)); |
| 245 | 245 | $prev_header = null; |
| 246 | - foreach($lines as $line) { |
|
| 246 | + foreach ($lines as $line) { |
|
| 247 | 247 | if (substr($line, 0, 1) === "\n") { |
| 248 | 248 | $line = substr($line, 1); |
| 249 | 249 | } |
@@ -263,19 +263,19 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | if (is_array($headers[$prev_header])) { |
| 265 | 265 | $headers[$prev_header][] = $line; |
| 266 | - }else{ |
|
| 266 | + }else { |
|
| 267 | 267 | $headers[$prev_header] .= $line; |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | - }else{ |
|
| 270 | + }else { |
|
| 271 | 271 | if (($pos = strpos($line, ":")) > 0) { |
| 272 | 272 | $key = trim(rtrim(strtolower(substr($line, 0, $pos)))); |
| 273 | 273 | $key = str_replace("-", "_", $key); |
| 274 | 274 | |
| 275 | 275 | $value = trim(rtrim(substr($line, $pos + 1))); |
| 276 | 276 | if (isset($headers[$key])) { |
| 277 | - $headers[$key][] = $value; |
|
| 278 | - }else{ |
|
| 277 | + $headers[$key][] = $value; |
|
| 278 | + }else { |
|
| 279 | 279 | $headers[$key] = [$value]; |
| 280 | 280 | } |
| 281 | 281 | $prev_header = $key; |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - foreach($headers as $key => $values) { |
|
| 286 | + foreach ($headers as $key => $values) { |
|
| 287 | 287 | if (isset($imap_headers[$key])) continue; |
| 288 | 288 | $value = null; |
| 289 | - switch($key){ |
|
| 289 | + switch ($key) { |
|
| 290 | 290 | case 'from': |
| 291 | 291 | case 'to': |
| 292 | 292 | case 'cc': |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | break; |
| 302 | 302 | default: |
| 303 | 303 | if (is_array($values)) { |
| 304 | - foreach($values as $k => $v) { |
|
| 304 | + foreach ($values as $k => $v) { |
|
| 305 | 305 | if ($v == "") { |
| 306 | 306 | unset($values[$k]); |
| 307 | 307 | } |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $value = implode(" ", $values); |
| 314 | 314 | } elseif ($available_values > 2) { |
| 315 | 315 | $value = array_values($values); |
| 316 | - } else { |
|
| 316 | + }else { |
|
| 317 | 317 | $value = ""; |
| 318 | 318 | } |
| 319 | 319 | } |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | * @return array The decoded elements are returned in an array of objects, where each |
| 334 | 334 | * object has two properties, charset and text. |
| 335 | 335 | */ |
| 336 | - public function mime_header_decode($text){ |
|
| 336 | + public function mime_header_decode($text) { |
|
| 337 | 337 | if (extension_loaded('imap')) { |
| 338 | 338 | return \imap_mime_header_decode($text); |
| 339 | 339 | } |
| 340 | 340 | $charset = $this->getEncoding($text); |
| 341 | - return [(object)[ |
|
| 341 | + return [(object) [ |
|
| 342 | 342 | "charset" => $charset, |
| 343 | 343 | "text" => $this->convertEncoding($text, $charset) |
| 344 | 344 | ]]; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | try { |
| 393 | 393 | if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') { |
| 394 | 394 | return iconv($from, $to, $str); |
| 395 | - } else { |
|
| 395 | + }else { |
|
| 396 | 396 | if (!$from) { |
| 397 | 397 | return mb_convert_encoding($str, $to); |
| 398 | 398 | } |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | if (strstr($from, '-')) { |
| 403 | 403 | $from = str_replace('-', '', $from); |
| 404 | 404 | return $this->convertEncoding($str, $from, $to); |
| 405 | - } else { |
|
| 405 | + }else { |
|
| 406 | 406 | return $str; |
| 407 | 407 | } |
| 408 | 408 | } |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | }elseif (property_exists($structure, 'charset')) { |
| 425 | 425 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 426 | - }elseif (is_string($structure) === true){ |
|
| 426 | + }elseif (is_string($structure) === true) { |
|
| 427 | 427 | return mb_detect_encoding($structure); |
| 428 | 428 | } |
| 429 | 429 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | if ($value !== null) { |
| 457 | 457 | $is_utf8_base = $this->is_uft8($value); |
| 458 | 458 | |
| 459 | - if($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 459 | + if ($decoder === 'utf-8' && extension_loaded('imap')) { |
|
| 460 | 460 | $value = \imap_utf8($value); |
| 461 | 461 | $is_utf8_base = $this->is_uft8($value); |
| 462 | 462 | if ($is_utf8_base) { |
@@ -465,14 +465,14 @@ discard block |
||
| 465 | 465 | if ($this->notDecoded($original_value, $value)) { |
| 466 | 466 | $decoded_value = $this->mime_header_decode($value); |
| 467 | 467 | if (count($decoded_value) > 0) { |
| 468 | - if(property_exists($decoded_value[0], "text")) { |
|
| 468 | + if (property_exists($decoded_value[0], "text")) { |
|
| 469 | 469 | $value = $decoded_value[0]->text; |
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | - }elseif($decoder === 'iconv' && $is_utf8_base) { |
|
| 473 | + }elseif ($decoder === 'iconv' && $is_utf8_base) { |
|
| 474 | 474 | $value = iconv_mime_decode($value); |
| 475 | - }elseif($is_utf8_base){ |
|
| 475 | + }elseif ($is_utf8_base) { |
|
| 476 | 476 | $value = mb_decode_mimeheader($value); |
| 477 | 477 | } |
| 478 | 478 | |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * @return array |
| 496 | 496 | */ |
| 497 | 497 | private function decodeArray($values) { |
| 498 | - foreach($values as $key => $value) { |
|
| 498 | + foreach ($values as $key => $value) { |
|
| 499 | 499 | $values[$key] = $this->decode($value); |
| 500 | 500 | } |
| 501 | 501 | return $values; |
@@ -505,8 +505,8 @@ discard block |
||
| 505 | 505 | * Try to extract the priority from a given raw header string |
| 506 | 506 | */ |
| 507 | 507 | private function findPriority() { |
| 508 | - if(($priority = $this->get("x_priority")) === null) return; |
|
| 509 | - switch((int)"$priority"){ |
|
| 508 | + if (($priority = $this->get("x_priority")) === null) return; |
|
| 509 | + switch ((int) "$priority") { |
|
| 510 | 510 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 511 | 511 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 512 | 512 | break; |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | if (isset($parsed_address['address'])) { |
| 546 | 546 | $mail_address = explode('@', $parsed_address['address']); |
| 547 | 547 | if (count($mail_address) == 2) { |
| 548 | - $addresses[] = (object)[ |
|
| 548 | + $addresses[] = (object) [ |
|
| 549 | 549 | "personal" => isset($parsed_address['display']) ? $parsed_address['display'] : '', |
| 550 | 550 | "mailbox" => $mail_address[0], |
| 551 | 551 | "host" => $mail_address[1], |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | return $addresses; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - foreach($values as $address) { |
|
| 561 | + foreach ($values as $address) { |
|
| 562 | 562 | foreach (preg_split('/, (?=(?:[^"]*"[^"]*")*[^"]*$)/', $address) as $split_address) { |
| 563 | 563 | $split_address = trim(rtrim($split_address)); |
| 564 | 564 | |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | $name = trim(rtrim($matches["name"])); |
| 574 | 574 | $email = trim(rtrim($matches["email"])); |
| 575 | 575 | list($mailbox, $host) = array_pad(explode("@", $email), 2, null); |
| 576 | - $addresses[] = (object)[ |
|
| 576 | + $addresses[] = (object) [ |
|
| 577 | 577 | "personal" => $name, |
| 578 | 578 | "mailbox" => $mailbox, |
| 579 | 579 | "host" => $host, |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @param object $header |
| 591 | 591 | */ |
| 592 | 592 | private function extractAddresses($header) { |
| 593 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key){ |
|
| 593 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $key) { |
|
| 594 | 594 | if (property_exists($header, $key)) { |
| 595 | 595 | $this->set($key, $this->parseAddresses($header->$key)); |
| 596 | 596 | } |
@@ -621,10 +621,10 @@ discard block |
||
| 621 | 621 | } |
| 622 | 622 | if (!property_exists($address, 'personal')) { |
| 623 | 623 | $address->personal = false; |
| 624 | - } else { |
|
| 624 | + }else { |
|
| 625 | 625 | $personalParts = $this->mime_header_decode($address->personal); |
| 626 | 626 | |
| 627 | - if(is_array($personalParts)) { |
|
| 627 | + if (is_array($personalParts)) { |
|
| 628 | 628 | $address->personal = ''; |
| 629 | 629 | foreach ($personalParts as $p) { |
| 630 | 630 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -648,23 +648,23 @@ discard block |
||
| 648 | 648 | /** |
| 649 | 649 | * Search and extract potential header extensions |
| 650 | 650 | */ |
| 651 | - private function extractHeaderExtensions(){ |
|
| 651 | + private function extractHeaderExtensions() { |
|
| 652 | 652 | foreach ($this->attributes as $key => $value) { |
| 653 | 653 | if (is_array($value)) { |
| 654 | 654 | $value = implode(", ", $value); |
| 655 | - }else{ |
|
| 656 | - $value = (string)$value; |
|
| 655 | + }else { |
|
| 656 | + $value = (string) $value; |
|
| 657 | 657 | } |
| 658 | 658 | // Only parse strings and don't parse any attributes like the user-agent |
| 659 | 659 | if (in_array($key, ["user_agent"]) === false) { |
| 660 | - if (($pos = strpos($value, ";")) !== false){ |
|
| 660 | + if (($pos = strpos($value, ";")) !== false) { |
|
| 661 | 661 | $original = substr($value, 0, $pos); |
| 662 | 662 | $this->set($key, trim(rtrim($original)), true); |
| 663 | 663 | |
| 664 | 664 | // Get all potential extensions |
| 665 | 665 | $extensions = explode(";", substr($value, $pos + 1)); |
| 666 | - foreach($extensions as $extension) { |
|
| 667 | - if (($pos = strpos($extension, "=")) !== false){ |
|
| 666 | + foreach ($extensions as $extension) { |
|
| 667 | + if (($pos = strpos($extension, "=")) !== false) { |
|
| 668 | 668 | $key = substr($extension, 0, $pos); |
| 669 | 669 | $key = trim(rtrim(strtolower($key))); |
| 670 | 670 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | $parsed_date = null; |
| 708 | 708 | $date = $header->date; |
| 709 | 709 | |
| 710 | - if(preg_match('/\+0580/', $date)) { |
|
| 710 | + if (preg_match('/\+0580/', $date)) { |
|
| 711 | 711 | $date = str_replace('+0580', '+0530', $date); |
| 712 | 712 | } |
| 713 | 713 | |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | $date = trim(array_pop($array)); |
| 731 | 731 | break; |
| 732 | 732 | } |
| 733 | - try{ |
|
| 733 | + try { |
|
| 734 | 734 | $parsed_date = Carbon::parse($date); |
| 735 | 735 | } catch (\Exception $_e) { |
| 736 | 736 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->get("message_id"), 1100, $e); |