@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function __construct(Client $client, $charset = 'UTF-8') { |
| 70 | 70 | $this->setClient($client); |
| 71 | 71 | |
| 72 | - if(config('imap.options.fetch') === IMAP::FT_PEEK) $this->leaveUnread(); |
|
| 72 | + if (config('imap.options.fetch') === IMAP::FT_PEEK) $this->leaveUnread(); |
|
| 73 | 73 | |
| 74 | 74 | $this->date_format = config('imap.date_format', 'd M y'); |
| 75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * Instance boot method for additional functionality |
| 83 | 83 | */ |
| 84 | - protected function boot(){} |
|
| 84 | + protected function boot() {} |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * Parse a given value |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | - protected function parse_value($value){ |
|
| 93 | - switch(true){ |
|
| 92 | + protected function parse_value($value) { |
|
| 93 | + switch (true) { |
|
| 94 | 94 | case $value instanceof \Carbon\Carbon: |
| 95 | 95 | $value = $value->format($this->date_format); |
| 96 | 96 | break; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @throws MessageSearchValidationException |
| 108 | 108 | */ |
| 109 | 109 | protected function parse_date($date) { |
| 110 | - if($date instanceof \Carbon\Carbon) return $date; |
|
| 110 | + if ($date instanceof \Carbon\Carbon) return $date; |
|
| 111 | 111 | |
| 112 | 112 | try { |
| 113 | 113 | $date = Carbon::parse($date); |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | * @return \Illuminate\Support\Collection |
| 147 | 147 | * @throws \Webklex\IMAP\Exceptions\ConnectionFailedException |
| 148 | 148 | */ |
| 149 | - protected function search(){ |
|
| 149 | + protected function search() { |
|
| 150 | 150 | $this->generate_query(); |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * Don't set the charset if it isn't used - prevent strange outlook mail server errors |
| 154 | 154 | * @see https://github.com/Webklex/laravel-imap/issues/100 |
| 155 | 155 | */ |
| 156 | - if($this->getCharset() === null){ |
|
| 156 | + if ($this->getCharset() === null) { |
|
| 157 | 157 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID); |
| 158 | - }else{ |
|
| 158 | + } else { |
|
| 159 | 159 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID, $this->getCharset()); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $options = config('imap.options'); |
| 197 | 197 | |
| 198 | - if(strtolower($options['fetch_order']) === 'desc'){ |
|
| 198 | + if (strtolower($options['fetch_order']) === 'desc') { |
|
| 199 | 199 | $available_messages = $available_messages->reverse(); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - $query =& $this; |
|
| 202 | + $query = & $this; |
|
| 203 | 203 | |
| 204 | 204 | $available_messages->forPage($this->page, $this->limit)->each(function($msgno, $msglist) use(&$messages, $options, $query) { |
| 205 | 205 | $oMessage = new Message($msgno, $msglist, $query->getClient(), $query->getFetchOptions(), $query->getFetchBody(), $query->getFetchAttachment(), $query->getFetchFlags()); |
| 206 | - switch ($options['message_key']){ |
|
| 206 | + switch ($options['message_key']) { |
|
| 207 | 207 | case 'number': |
| 208 | 208 | $message_key = $oMessage->getMessageNo(); |
| 209 | 209 | break; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @return \Illuminate\Pagination\LengthAwarePaginator |
| 235 | 235 | * @throws GetMessagesFailedException |
| 236 | 236 | */ |
| 237 | - public function paginate($per_page = 5, $page = null, $page_name = 'imap_page'){ |
|
| 237 | + public function paginate($per_page = 5, $page = null, $page_name = 'imap_page') { |
|
| 238 | 238 | $this->page = $page > $this->page ? $page : $this->page; |
| 239 | 239 | $this->limit = $per_page; |
| 240 | 240 | |
@@ -248,23 +248,23 @@ discard block |
||
| 248 | 248 | * @throws GetMessagesFailedException |
| 249 | 249 | * @throws \Webklex\IMAP\Exceptions\ConnectionFailedException |
| 250 | 250 | */ |
| 251 | - public function idle(callable $callback = null, $timeout = 10){ |
|
| 251 | + public function idle(callable $callback = null, $timeout = 10) { |
|
| 252 | 252 | $known_messages = []; |
| 253 | 253 | $this->get()->each(function($message) use(&$known_messages){ |
| 254 | 254 | /** @var Message $message */ |
| 255 | 255 | $known_messages[] = $message->getToken(); |
| 256 | 256 | }); |
| 257 | - while ($this->getClient()->isConnected()){ |
|
| 257 | + while ($this->getClient()->isConnected()) { |
|
| 258 | 258 | $this->getClient()->expunge(); |
| 259 | 259 | $this->get()->each(function($message) use(&$known_messages, $callback){ |
| 260 | 260 | /** @var \Webklex\IMAP\Message $message */ |
| 261 | 261 | $token = $message->getToken(); |
| 262 | - if(in_array($token, $known_messages)){ |
|
| 262 | + if (in_array($token, $known_messages)) { |
|
| 263 | 263 | return; |
| 264 | 264 | } |
| 265 | 265 | $known_messages[] = $token; |
| 266 | 266 | MessageNewEvent::dispatch($message); |
| 267 | - if ($callback){ |
|
| 267 | + if ($callback) { |
|
| 268 | 268 | $callback($message); |
| 269 | 269 | } |
| 270 | 270 | }); |
@@ -283,9 +283,9 @@ discard block |
||
| 283 | 283 | if (count($statement) == 1) { |
| 284 | 284 | $query .= $statement[0]; |
| 285 | 285 | } else { |
| 286 | - if($statement[1] === null){ |
|
| 286 | + if ($statement[1] === null) { |
|
| 287 | 287 | $query .= $statement[0]; |
| 288 | - }else{ |
|
| 288 | + } else { |
|
| 289 | 289 | $query .= $statement[0].' "'.$statement[1].'"'; |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @return $this |
| 316 | 316 | */ |
| 317 | 317 | public function limit($limit, $page = 1) { |
| 318 | - if($page >= 1) $this->page = $page; |
|
| 318 | + if ($page >= 1) $this->page = $page; |
|
| 319 | 319 | $this->limit = $limit; |
| 320 | 320 | |
| 321 | 321 | return $this; |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_attachment = false, $fetch_flags = false) { |
| 201 | 201 | |
| 202 | 202 | $default_mask = $client->getDefaultMessageMask(); |
| 203 | - if($default_mask != null) { |
|
| 203 | + if ($default_mask != null) { |
|
| 204 | 204 | $this->mask = $default_mask; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $this->msglist = $msglist; |
| 220 | 220 | $this->client = $client; |
| 221 | 221 | |
| 222 | - $this->uid = ($this->fetch_options == IMAP::FT_UID) ? $uid : $uid; |
|
| 222 | + $this->uid = ($this->fetch_options == IMAP::FT_UID) ? $uid : $uid; |
|
| 223 | 223 | $this->msgn = ($this->fetch_options == IMAP::FT_UID) ? \imap_msgno($this->client->getConnection(), $uid) : $uid; |
| 224 | 224 | |
| 225 | 225 | $this->parseHeader(); |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | * @throws MethodNotFoundException |
| 243 | 243 | */ |
| 244 | 244 | public function __call($method, $arguments) { |
| 245 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 245 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 246 | 246 | $name = Str::snake(substr($method, 3)); |
| 247 | 247 | |
| 248 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 248 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 249 | 249 | return $this->attributes[$name]; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | }elseif (strtolower(substr($method, 0, 3)) === 'set') { |
| 253 | 253 | $name = Str::snake(substr($method, 3)); |
| 254 | 254 | |
| 255 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 255 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 256 | 256 | $this->attributes[$name] = array_pop($arguments); |
| 257 | 257 | |
| 258 | 258 | return $this->attributes[$name]; |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @return mixed|null |
| 282 | 282 | */ |
| 283 | 283 | public function __get($name) { |
| 284 | - if(isset($this->attributes[$name])) { |
|
| 284 | + if (isset($this->attributes[$name])) { |
|
| 285 | 285 | return $this->attributes[$name]; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -367,11 +367,11 @@ discard block |
||
| 367 | 367 | if ($replaceImages !== false) { |
| 368 | 368 | $this->attachments->each(function($oAttachment) use(&$body, $replaceImages) { |
| 369 | 369 | /** @var Attachment $oAttachment */ |
| 370 | - if(is_callable($replaceImages)) { |
|
| 370 | + if (is_callable($replaceImages)) { |
|
| 371 | 371 | $body = $replaceImages($body, $oAttachment); |
| 372 | - }elseif(is_string($replaceImages)) { |
|
| 372 | + }elseif (is_string($replaceImages)) { |
|
| 373 | 373 | call_user_func($replaceImages, [$body, $oAttachment]); |
| 374 | - }else{ |
|
| 374 | + } else { |
|
| 375 | 375 | if ($oAttachment->id && $oAttachment->getImgSrc() != null) { |
| 376 | 376 | $body = str_replace('cid:'.$oAttachment->id, $oAttachment->getImgSrc(), $body); |
| 377 | 377 | } |
@@ -400,16 +400,16 @@ discard block |
||
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | if (property_exists($header, 'subject')) { |
| 403 | - if($this->config['decoder']['message']['subject'] === 'utf-8') { |
|
| 403 | + if ($this->config['decoder']['message']['subject'] === 'utf-8') { |
|
| 404 | 404 | $this->subject = \imap_utf8($header->subject); |
| 405 | - }elseif($this->config['decoder']['message']['subject'] === 'iconv') { |
|
| 405 | + }elseif ($this->config['decoder']['message']['subject'] === 'iconv') { |
|
| 406 | 406 | $this->subject = iconv_mime_decode($header->subject); |
| 407 | - }else{ |
|
| 407 | + } else { |
|
| 408 | 408 | $this->subject = mb_decode_mimeheader($header->subject); |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $part){ |
|
| 412 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $part) { |
|
| 413 | 413 | $this->extractHeaderAddressPart($header, $part); |
| 414 | 414 | } |
| 415 | 415 | |
@@ -439,9 +439,9 @@ discard block |
||
| 439 | 439 | * @return int|null |
| 440 | 440 | */ |
| 441 | 441 | private function extractPriority($header) { |
| 442 | - if(preg_match('/x\-priority\:.*([0-9]{1,2})/i', $header, $priority)){ |
|
| 442 | + if (preg_match('/x\-priority\:.*([0-9]{1,2})/i', $header, $priority)) { |
|
| 443 | 443 | $priority = isset($priority[1]) ? (int) $priority[1] : 0; |
| 444 | - switch($priority){ |
|
| 444 | + switch ($priority) { |
|
| 445 | 445 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 446 | 446 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 447 | 447 | break; |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | if (property_exists($header, 'date')) { |
| 493 | 493 | $date = $header->date; |
| 494 | 494 | |
| 495 | - if(preg_match('/\+0580/', $date)) { |
|
| 495 | + if (preg_match('/\+0580/', $date)) { |
|
| 496 | 496 | $date = str_replace('+0580', '+0530', $date); |
| 497 | 497 | } |
| 498 | 498 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | $date = trim(array_pop($array)); |
| 516 | 516 | break; |
| 517 | 517 | } |
| 518 | - try{ |
|
| 518 | + try { |
|
| 519 | 519 | $parsed_date = Carbon::parse($date); |
| 520 | 520 | } catch (\Exception $_e) { |
| 521 | 521 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->getMessageId(), 1000, $e); |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | $this->client->openFolder($this->folder_path); |
| 539 | 539 | $flags = \imap_fetch_overview($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 540 | 540 | if (is_array($flags) && isset($flags[0])) { |
| 541 | - foreach($this->available_flags as $flag) { |
|
| 541 | + foreach ($this->available_flags as $flag) { |
|
| 542 | 542 | $this->parseFlag($flags, $flag); |
| 543 | 543 | } |
| 544 | 544 | } |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | } else { |
| 611 | 611 | $personalParts = \imap_mime_header_decode($address->personal); |
| 612 | 612 | |
| 613 | - if(is_array($personalParts)) { |
|
| 613 | + if (is_array($personalParts)) { |
|
| 614 | 614 | $address->personal = ''; |
| 615 | 615 | foreach ($personalParts as $p) { |
| 616 | 616 | $encoding = (property_exists($p, 'charset')) ? $p->charset : $this->getEncoding($p->text); |
@@ -638,12 +638,12 @@ discard block |
||
| 638 | 638 | $this->client->openFolder($this->folder_path); |
| 639 | 639 | $this->structure = \imap_fetchstructure($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 640 | 640 | |
| 641 | - if(property_exists($this->structure, 'parts')){ |
|
| 641 | + if (property_exists($this->structure, 'parts')) { |
|
| 642 | 642 | $parts = $this->structure->parts; |
| 643 | 643 | |
| 644 | - foreach ($parts as $part) { |
|
| 645 | - foreach ($part->parameters as $parameter) { |
|
| 646 | - if($parameter->attribute == "charset") { |
|
| 644 | + foreach ($parts as $part) { |
|
| 645 | + foreach ($part->parameters as $parameter) { |
|
| 646 | + if ($parameter->attribute == "charset") { |
|
| 647 | 647 | $encoding = $parameter->value; |
| 648 | 648 | |
| 649 | 649 | $encoding = preg_replace('/Content-Transfer-Encoding/', '', $encoding); |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | return EncodingAliases::get($parameter->value); |
| 923 | 923 | } |
| 924 | 924 | } |
| 925 | - }elseif (is_string($structure) === true){ |
|
| 925 | + }elseif (is_string($structure) === true) { |
|
| 926 | 926 | return mb_detect_encoding($structure); |
| 927 | 927 | } |
| 928 | 928 | |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | return null; |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - public function getFolder(){ |
|
| 975 | + public function getFolder() { |
|
| 976 | 976 | return $this->client->getFolder($this->folder_path); |
| 977 | 977 | } |
| 978 | 978 | |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | */ |
| 989 | 989 | public function moveToFolder($mailbox = 'INBOX', $expunge = false, $create_folder = true) { |
| 990 | 990 | |
| 991 | - if($create_folder) $this->client->createFolder($mailbox, true); |
|
| 991 | + if ($create_folder) $this->client->createFolder($mailbox, true); |
|
| 992 | 992 | |
| 993 | 993 | $target_folder = $this->client->getFolder($mailbox); |
| 994 | 994 | $target_status = $target_folder->getStatus(IMAP::SA_ALL); |
@@ -996,8 +996,8 @@ discard block |
||
| 996 | 996 | $this->client->openFolder($this->folder_path); |
| 997 | 997 | $status = \imap_mail_move($this->client->getConnection(), $this->uid, $mailbox, IMAP::CP_UID); |
| 998 | 998 | |
| 999 | - if($status === true){ |
|
| 1000 | - if($expunge) $this->client->expunge(); |
|
| 999 | + if ($status === true) { |
|
| 1000 | + if ($expunge) $this->client->expunge(); |
|
| 1001 | 1001 | $this->client->openFolder($target_folder->path); |
| 1002 | 1002 | |
| 1003 | 1003 | $message = $target_folder->getMessage($target_status->uidnext, null, $this->fetch_options, $this->fetch_body, $this->fetch_attachment, $this->fetch_flags); |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | $this->client->openFolder($this->folder_path); |
| 1020 | 1020 | |
| 1021 | 1021 | $status = \imap_delete($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 1022 | - if($expunge) $this->client->expunge(); |
|
| 1022 | + if ($expunge) $this->client->expunge(); |
|
| 1023 | 1023 | MessageDeletedEvent::dispatch($this); |
| 1024 | 1024 | |
| 1025 | 1025 | return $status; |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | $this->client->openFolder($this->folder_path); |
| 1037 | 1037 | |
| 1038 | 1038 | $status = \imap_undelete($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 1039 | - if($expunge) $this->client->expunge(); |
|
| 1039 | + if ($expunge) $this->client->expunge(); |
|
| 1040 | 1040 | MessageRestoredEvent::dispatch($this); |
| 1041 | 1041 | |
| 1042 | 1042 | return $status; |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | * @return string |
| 1114 | 1114 | * @throws Exceptions\ConnectionFailedException |
| 1115 | 1115 | */ |
| 1116 | - public function getToken(){ |
|
| 1116 | + public function getToken() { |
|
| 1117 | 1117 | return base64_encode(implode('-', [$this->message_id, $this->subject, strlen($this->getRawBody())])); |
| 1118 | 1118 | } |
| 1119 | 1119 | |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | /** |
| 1177 | 1177 | * @return object|null |
| 1178 | 1178 | */ |
| 1179 | - public function getStructure(){ |
|
| 1179 | + public function getStructure() { |
|
| 1180 | 1180 | return $this->structure; |
| 1181 | 1181 | } |
| 1182 | 1182 | |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | /** |
| 1203 | 1203 | * @return array |
| 1204 | 1204 | */ |
| 1205 | - public function getAttributes(){ |
|
| 1205 | + public function getAttributes() { |
|
| 1206 | 1206 | return $this->attributes; |
| 1207 | 1207 | } |
| 1208 | 1208 | |
@@ -1210,8 +1210,8 @@ discard block |
||
| 1210 | 1210 | * @param $mask |
| 1211 | 1211 | * @return $this |
| 1212 | 1212 | */ |
| 1213 | - public function setMask($mask){ |
|
| 1214 | - if(class_exists($mask)){ |
|
| 1213 | + public function setMask($mask) { |
|
| 1214 | + if (class_exists($mask)) { |
|
| 1215 | 1215 | $this->mask = $mask; |
| 1216 | 1216 | } |
| 1217 | 1217 | |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | /** |
| 1222 | 1222 | * @return string |
| 1223 | 1223 | */ |
| 1224 | - public function getMask(){ |
|
| 1224 | + public function getMask() { |
|
| 1225 | 1225 | return $this->mask; |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -1232,9 +1232,9 @@ discard block |
||
| 1232 | 1232 | * @return mixed |
| 1233 | 1233 | * @throws MaskNotFoundException |
| 1234 | 1234 | */ |
| 1235 | - public function mask($mask = null){ |
|
| 1235 | + public function mask($mask = null) { |
|
| 1236 | 1236 | $mask = $mask !== null ? $mask : $this->mask; |
| 1237 | - if(class_exists($mask)){ |
|
| 1237 | + if (class_exists($mask)) { |
|
| 1238 | 1238 | return new $mask($this); |
| 1239 | 1239 | } |
| 1240 | 1240 | |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * New custom method which can be called through a mask |
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | - public function my_token(){ |
|
| 19 | + public function my_token() { |
|
| 20 | 20 | return implode('-', [$this->message_id, $this->uid, $this->message_no]); |
| 21 | 21 | } |
| 22 | 22 | |