forked from DirectoryTree/ImapEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderRepository.php
More file actions
65 lines (56 loc) · 1.55 KB
/
FolderRepository.php
File metadata and controls
65 lines (56 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace DirectoryTree\ImapEngine;
use DirectoryTree\ImapEngine\Collections\FolderCollection;
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
class FolderRepository implements FolderRepositoryInterface
{
/**
* Constructor.
*/
public function __construct(
protected Mailbox $mailbox
) {}
/**
* {@inheritDoc}
*/
public function find(string $folder): ?FolderInterface
{
return $this->get($folder)->first();
}
/**
* {@inheritDoc}
*/
public function findOrFail(string $folder): FolderInterface
{
return $this->get($folder)->firstOrFail();
}
/**
* {@inheritDoc}
*/
public function create(string $folder): FolderInterface
{
$this->mailbox->connection()->create($folder);
return $this->find($folder);
}
/**
* {@inheritDoc}
*/
public function firstOrCreate(string $folder): FolderInterface
{
return $this->find($folder) ?? $this->create($folder);
}
/**
* {@inheritDoc}
*/
public function get(?string $match = '*', ?string $reference = ''): FolderCollection
{
return $this->mailbox->connection()->list($reference, $match)->map(
fn (UntaggedResponse $response) => new Folder(
mailbox: $this->mailbox,
path: $response->tokenAt(4)->value,
flags: $response->tokenAt(2)->values(),
delimiter: $response->tokenAt(3)->value,
)
)->pipeInto(FolderCollection::class);
}
}