@@ -121,6 +121,22 @@ class Folder {
121
121
/** @var array */
122
122
public array $ status ;
123
123
124
+ /** @var array */
125
+ public array $ attributes = [];
126
+
127
+
128
+ const SPECIAL_ATTRIBUTES = [
129
+ 'haschildren ' => ['\haschildren ' ],
130
+ 'hasnochildren ' => ['\hasnochildren ' ],
131
+ 'template ' => ['\template ' , '\templates ' ],
132
+ 'inbox ' => ['\inbox ' ],
133
+ 'sent ' => ['\sent ' ],
134
+ 'drafts ' => ['\draft ' , '\drafts ' ],
135
+ 'archive ' => ['\archive ' , '\archives ' ],
136
+ 'trash ' => ['\trash ' ],
137
+ 'junk ' => ['\junk ' , '\spam ' ],
138
+ ];
139
+
124
140
/**
125
141
* Folder constructor.
126
142
* @param Client $client
@@ -235,7 +251,7 @@ public function getChildren(): FolderCollection {
235
251
*/
236
252
protected function decodeName ($ name ): string |array |bool |null {
237
253
$ parts = [];
238
- foreach (explode ($ this ->delimiter , $ name ) as $ item ) {
254
+ foreach (explode ($ this ->delimiter , $ name ) as $ item ) {
239
255
$ parts [] = EncodingAliases::convert ($ item , "UTF7-IMAP " , "UTF-8 " );
240
256
}
241
257
@@ -264,6 +280,14 @@ protected function parseAttributes($attributes): void {
264
280
$ this ->marked = in_array ('\Marked ' , $ attributes );
265
281
$ this ->referral = in_array ('\Referral ' , $ attributes );
266
282
$ this ->has_children = in_array ('\HasChildren ' , $ attributes );
283
+
284
+ array_map (function ($ el ) {
285
+ foreach (self ::SPECIAL_ATTRIBUTES as $ key => $ attribute ) {
286
+ if (in_array (strtolower ($ el ), $ attribute )){
287
+ $ this ->attributes [] = $ key ;
288
+ }
289
+ }
290
+ }, $ attributes );
267
291
}
268
292
269
293
/**
@@ -284,7 +308,7 @@ protected function parseAttributes($attributes): void {
284
308
public function move (string $ new_name , bool $ expunge = true ): array {
285
309
$ this ->client ->checkConnection ();
286
310
$ status = $ this ->client ->getConnection ()->renameFolder ($ this ->full_name , $ new_name )->validatedData ();
287
- if ($ expunge ) $ this ->client ->expunge ();
311
+ if ($ expunge ) $ this ->client ->expunge ();
288
312
289
313
$ folder = $ this ->client ->getFolder ($ new_name );
290
314
$ event = $ this ->getEvent ("folder " , "moved " );
@@ -336,7 +360,7 @@ public function appendMessage(string $message, array $options = null, Carbon|str
336
360
* date string that conforms to the rfc2060 specifications for a date_time value or be a Carbon object.
337
361
*/
338
362
339
- if ($ internal_date instanceof Carbon) {
363
+ if ($ internal_date instanceof Carbon){
340
364
$ internal_date = $ internal_date ->format ('d-M-Y H:i:s O ' );
341
365
}
342
366
@@ -377,11 +401,11 @@ public function rename(string $new_name, bool $expunge = true): array {
377
401
*/
378
402
public function delete (bool $ expunge = true ): array {
379
403
$ status = $ this ->client ->getConnection ()->deleteFolder ($ this ->path )->validatedData ();
380
- if ($ this ->client ->getActiveFolder () == $ this ->path ){
404
+ if ($ this ->client ->getActiveFolder () == $ this ->path ){
381
405
$ this ->client ->setActiveFolder (null );
382
406
}
383
407
384
- if ($ expunge ) $ this ->client ->expunge ();
408
+ if ($ expunge ) $ this ->client ->expunge ();
385
409
386
410
$ event = $ this ->getEvent ("folder " , "deleted " );
387
411
$ event ::dispatch ($ this );
@@ -437,7 +461,7 @@ public function unsubscribe(): array {
437
461
public function idle (callable $ callback , int $ timeout = 300 ): void {
438
462
$ this ->client ->setTimeout ($ timeout );
439
463
440
- if (!in_array ("IDLE " , $ this ->client ->getConnection ()->getCapabilities ()->validatedData ())) {
464
+ if (!in_array ("IDLE " , $ this ->client ->getConnection ()->getCapabilities ()->validatedData ())){
441
465
throw new Exceptions \NotSupportedCapabilityException ("IMAP server does not support IDLE " );
442
466
}
443
467
@@ -450,15 +474,15 @@ public function idle(callable $callback, int $timeout = 300): void {
450
474
451
475
$ sequence = ClientManager::get ('options.sequence ' , IMAP ::ST_MSGN );
452
476
453
- while (true ) {
477
+ while (true ) {
454
478
// This polymorphic call is fine - Protocol::idle() will throw an exception beforehand
455
479
$ line = $ idle_client ->getConnection ()->nextLine (Response::empty ());
456
480
457
- if (($ pos = strpos ($ line , "EXISTS " )) !== false ) {
481
+ if (($ pos = strpos ($ line , "EXISTS " )) !== false ){
458
482
$ msgn = (int )substr ($ line , 2 , $ pos - 2 );
459
483
460
484
// Check if the stream is still alive or should be considered stale
461
- if (!$ this ->client ->isConnected () || $ last_action ->isBefore (Carbon::now ())) {
485
+ if (!$ this ->client ->isConnected () || $ last_action ->isBefore (Carbon::now ())){
462
486
// Reset the connection before interacting with it. Otherwise, the resource might be stale which
463
487
// would result in a stuck interaction. If you know of a way of detecting a stale resource, please
464
488
// feel free to improve this logic. I tried a lot but nothing seem to work reliably...
@@ -582,7 +606,7 @@ public function getClient(): Client {
582
606
* @param $delimiter
583
607
*/
584
608
public function setDelimiter ($ delimiter ): void {
585
- if (in_array ($ delimiter , [null , '' , ' ' , false ]) === true ) {
609
+ if (in_array ($ delimiter , [null , '' , ' ' , false ]) === true ){
586
610
$ delimiter = ClientManager::get ('options.delimiter ' , '/ ' );
587
611
}
588
612
0 commit comments