Skip to content

Commit 085c10c

Browse files
committed
WIP
1 parent da8410d commit 085c10c

File tree

2 files changed

+28
-35
lines changed

2 files changed

+28
-35
lines changed

src/Connection/Connection.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function nextReply(): Response
337337
/**
338338
* Send an IMAP command.
339339
*/
340-
public function send(string $name, array $tokens, ?string &$tag): void
340+
public function send(string $name, array $tokens = [], ?string &$tag = null): void
341341
{
342342
$command = new ImapCommand($name, $tokens);
343343

@@ -381,7 +381,7 @@ protected function write(string $data): void
381381
* This method compiles the FETCH command, sends it, and then uses the new parser
382382
* to obtain the parsed result.
383383
*/
384-
public function fetch(array|string $items, array|int $from, mixed $to = null, $identifier = Imap::ST_UID): Response
384+
public function fetch(array|string $items, array|int $from, mixed $to = null, $identifier = Imap::ST_UID): UntaggedResponse
385385
{
386386
if (is_array($from) && count($from) > 1) {
387387
$set = implode(',', $from);
@@ -398,22 +398,16 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, $i
398398
$items = (array) $items;
399399
$prefix = ($identifier === Imap::ST_UID) ? 'UID' : '';
400400

401-
// Send the FETCH command.
402-
$response = $this->send(
401+
$this->send(
403402
trim($prefix.' FETCH'),
404403
[$set, $this->escapeList($items)],
405404
$tag
406405
);
407406

408-
// Use the new parser to parse the FETCH response.
409-
$tokenizer = new ImapTokenizer($this->stream);
410-
$parser = new ImapParser($tokenizer);
411-
$parsedData = $parser->next();
412-
413-
// Process $parsedData as needed; here we simply assign it.
414-
$response->setResult($parsedData);
415-
416-
return $response;
407+
return $this->assertUntaggedResponse(
408+
fn (UntaggedResponse $response) => $response->tokenAt(2)?->is('FETCH'),
409+
fn () => new RuntimeException('Failed to fetch items')
410+
);
417411
}
418412

419413
/**

src/Connection/ConnectionInterface.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DirectoryTree\ImapEngine\Collections\ResponseCollection;
66
use DirectoryTree\ImapEngine\Connection\Responses\TaggedResponse;
7+
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
78

89
interface ConnectionInterface
910
{
@@ -45,19 +46,17 @@ public function done(): void;
4546
/**
4647
* Send noop command.
4748
*/
48-
public function noop(): ResponseCollection;
49+
public function noop(): TaggedResponse;
4950

5051
/**
5152
* Apply session saved changes to the server.
5253
*/
5354
public function expunge(): ResponseCollection;
5455

5556
/**
56-
* Get an array of available capabilities.
57-
*
58-
* @return ResponseCollection containing a list of capabilities
57+
* Get the mailboxes available capabilities.
5958
*/
60-
public function capability(): ResponseCollection;
59+
public function capability(): UntaggedResponse;
6160

6261
/**
6362
* Execute a search request.
@@ -76,27 +75,27 @@ public function id(?array $ids = null): ResponseCollection;
7675
/**
7776
* Fetch message UIDs using the given message numbers.
7877
*/
79-
public function uids(int|array $msgns): ResponseCollection;
78+
public function uids(int|array $msgns): UntaggedResponse;
8079

8180
/**
8281
* Fetch message contents.
8382
*/
84-
public function contents(int|array $ids): ResponseCollection;
83+
public function contents(int|array $ids): UntaggedResponse;
8584

8685
/**
8786
* Fetch message headers.
8887
*/
89-
public function headers(int|array $ids): ResponseCollection;
88+
public function headers(int|array $ids): UntaggedResponse;
9089

9190
/**
9291
* Fetch message flags.
9392
*/
94-
public function flags(int|array $ids): ResponseCollection;
93+
public function flags(int|array $ids): UntaggedResponse;
9594

9695
/**
9796
* Fetch message sizes.
9897
*/
99-
public function sizes(int|array $ids): ResponseCollection;
98+
public function sizes(int|array $ids): UntaggedResponse;
10099

101100
/**
102101
* Select the given folder.
@@ -122,7 +121,7 @@ public function folders(string $reference = '', string $folder = '*'): ResponseC
122121
*
123122
* @return ResponseCollection list of STATUS items
124123
*/
125-
public function folderStatus(string $folder, array $arguments = ['MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY']): ResponseCollection;
124+
public function folderStatus(string $folder, array $arguments = ['MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY']): UntaggedResponse;
126125

127126
/**
128127
* Set message flags.
@@ -191,32 +190,32 @@ public function moveManyMessages(array $messages, string $folder): ResponseColle
191190
*/
192191
public function createFolder(string $folder): ResponseCollection;
193192

194-
/**
195-
* Rename an existing folder.
196-
*
197-
* @param string $oldPath old name
198-
* @param string $newPath new name
199-
*/
200-
public function renameFolder(string $oldPath, string $newPath): ResponseCollection;
201-
202193
/**
203194
* Delete a folder.
204195
*
205196
* @param string $folder folder name
206197
*/
207-
public function deleteFolder(string $folder): ResponseCollection;
198+
public function deleteFolder(string $folder): TaggedResponse;
208199

209200
/**
210201
* Subscribe to a folder.
211202
*
212203
* @param string $folder folder name
213204
*/
214-
public function subscribeFolder(string $folder): ResponseCollection;
205+
public function subscribeFolder(string $folder): TaggedResponse;
215206

216207
/**
217208
* Unsubscribe from a folder.
218209
*
219210
* @param string $folder folder name
220211
*/
221-
public function unsubscribeFolder(string $folder): ResponseCollection;
212+
public function unsubscribeFolder(string $folder): TaggedResponse;
213+
214+
/**
215+
* Rename an existing folder.
216+
*
217+
* @param string $oldPath old name
218+
* @param string $newPath new name
219+
*/
220+
public function renameFolder(string $oldPath, string $newPath): TaggedResponse;
222221
}

0 commit comments

Comments
 (0)