Skip to content

Commit 7d4b2a7

Browse files
committed
Use PHP enum instead of int for fetch option
1 parent 8b73114 commit 7d4b2a7

File tree

6 files changed

+31
-36
lines changed

6 files changed

+31
-36
lines changed

src/Connection/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ protected function write(string $data): void
381381
/**
382382
* Fetch one or more items for one or more messages.
383383
*/
384-
public function fetch(array|string $items, array|int $from, mixed $to = null, $identifier = Imap::SEQUENCE_TYPE_UID): ResponseCollection
384+
public function fetch(array|string $items, array|int $from, mixed $to = null, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): ResponseCollection
385385
{
386386
if (is_array($from) && count($from) > 1) {
387387
$set = implode(',', $from);
@@ -397,7 +397,7 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, $i
397397

398398
$items = (array) $items;
399399

400-
$prefix = ($identifier === Imap::SEQUENCE_TYPE_UID) ? 'UID' : '';
400+
$prefix = ($identifier === ImapFetchIdentifier::Uid) ? 'UID' : '';
401401

402402
$this->send(trim($prefix.' FETCH'), [$set, $this->escapeList($items)], $tag);
403403

src/Connection/ImapConnection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
1010
use DirectoryTree\ImapEngine\Exceptions\AuthFailedException;
1111
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
12-
use DirectoryTree\ImapEngine\Imap;
1312
use Illuminate\Support\Arr;
1413
use Throwable;
1514

@@ -282,7 +281,7 @@ public function store(array|string $flags, int $from, ?int $to = null, ?string $
282281
*/
283282
public function uids(int|array $msgns): ResponseCollection
284283
{
285-
return $this->fetch(['UID'], (array) $msgns, null, Imap::SEQUENCE_TYPE_MSG_NUMBER);
284+
return $this->fetch(['UID'], (array) $msgns, null, ImapFetchIdentifier::MessageNumber);
286285
}
287286

288287
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace DirectoryTree\ImapEngine\Connection;
4+
5+
enum ImapFetchOption
6+
{
7+
case Uid;
8+
case MessageNumber;
9+
}

src/Folder.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace DirectoryTree\ImapEngine;
44

5+
use DirectoryTree\ImapEngine\Connection\ImapFetchIdentifier;
56
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
67
use DirectoryTree\ImapEngine\Exceptions\ResponseException;
78
use DirectoryTree\ImapEngine\Exceptions\RuntimeException;
@@ -95,7 +96,7 @@ public function idle(callable $callback, int $timeout = 300): void
9596
}
9697

9798
$fetch = function (int $msgn) {
98-
return $this->messages()->withBody()->find($msgn, Imap::SEQUENCE_TYPE_MSG_NUMBER);
99+
return $this->messages()->withBody()->find($msgn, ImapFetchIdentifier::MessageNumber);
99100
};
100101

101102
(new Idle(clone $this->mailbox, $this->path, $timeout))->await(
@@ -134,18 +135,6 @@ public function move(string $newPath, bool $expunge = true): void
134135
$this->path = $newPath;
135136
}
136137

137-
/**
138-
* Delete the current folder.
139-
*/
140-
public function delete(bool $expunge = true): void
141-
{
142-
$this->mailbox->connection()->deleteFolder($this->path);
143-
144-
if ($expunge) {
145-
$this->expunge();
146-
}
147-
}
148-
149138
/**
150139
* Select the current folder.
151140
*/
@@ -193,6 +182,18 @@ public function expunge(): array
193182
)->all();
194183
}
195184

185+
/**
186+
* Delete the current folder.
187+
*/
188+
public function delete(bool $expunge = true): void
189+
{
190+
$this->mailbox->connection()->deleteFolder($this->path);
191+
192+
if ($expunge) {
193+
$this->expunge();
194+
}
195+
}
196+
196197
/**
197198
* Determine if the mailbox has the given capability.
198199
*/
@@ -202,7 +203,7 @@ public function hasCapability(string $capability): bool
202203
}
203204

204205
/**
205-
* Get the mailboxes's capabilities.
206+
* Get and in-memory cache the mailboxes's capabilities.
206207
*/
207208
protected function capabilities(): array
208209
{

src/Imap.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/MessageQuery.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTimeInterface;
88
use DirectoryTree\ImapEngine\Collections\MessageCollection;
99
use DirectoryTree\ImapEngine\Connection\ConnectionInterface;
10+
use DirectoryTree\ImapEngine\Connection\ImapFetchIdentifier;
1011
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
1112
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
1213
use DirectoryTree\ImapEngine\Support\Str;
@@ -860,12 +861,12 @@ public function paginate(int $perPage = 5, $page = null, string $pageName = 'pag
860861
/**
861862
* Find a message by the given identifier type.
862863
*/
863-
public function find(int $id, int $identifier = Imap::SEQUENCE_TYPE_UID): Message
864+
public function find(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): Message
864865
{
865866
// If the sequence is not UID, we'll need to fetch the UID first.
866867
$uid = match ($identifier) {
867-
Imap::SEQUENCE_TYPE_UID => $id,
868-
Imap::SEQUENCE_TYPE_MSG_NUMBER => $this->connection()->uids([$id]) // ResponseCollection
868+
ImapFetchIdentifier::Uid => $id,
869+
ImapFetchIdentifier::MessageNumber => $this->connection()->uids([$id]) // ResponseCollection
869870
->firstOrFail() // Untagged response
870871
->tokenAt(3) // ListData
871872
->tokenAt(1) // Atom

0 commit comments

Comments
 (0)