Skip to content

Commit 5255f0e

Browse files
committed
Finish up connection implementation
1 parent d83254a commit 5255f0e

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/Connection/ConnectionInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,22 @@ public function appendMessage(string $folder, string $message, ?array $flags = n
128128
/**
129129
* Copy message set from current folder to other folder.
130130
*/
131-
public function copyMessage(string $folder, $from, ?int $to = null): ResponseCollection;
131+
public function copyMessage(string $folder, $from, ?int $to = null): void;
132132

133133
/**
134134
* Copy multiple messages to the target folder.
135135
*/
136-
public function copyManyMessages(array $messages, string $folder): ResponseCollection;
136+
public function copyManyMessages(array $messages, string $folder): void;
137137

138138
/**
139139
* Move a message set from current folder to another folder.
140140
*/
141-
public function moveMessage(string $folder, $from, ?int $to = null): ResponseCollection;
141+
public function moveMessage(string $folder, $from, ?int $to = null): void;
142142

143143
/**
144144
* Move multiple messages to the target folder.
145145
*/
146-
public function moveManyMessages(array $messages, string $folder): ResponseCollection;
146+
public function moveManyMessages(array $messages, string $folder): void;
147147

148148
/**
149149
* Create a new folder.

src/Connection/ImapConnection.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ public function folderStatus(string $folder = 'INBOX', array $arguments = ['MESS
117117
*/
118118
public function createFolder(string $folder): ResponseCollection
119119
{
120-
$this->send('CREATE', [$this->escapeString($folder)]);
120+
$this->send('CREATE', [$this->escapeString($folder)], $tag);
121+
122+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to create folder'));
123+
124+
return $this->result->responses()->untagged()->filter(
125+
fn (UntaggedResponse $response) => $response->type()->is('LIST')
126+
);
121127
}
122128

123129
/**
@@ -193,52 +199,66 @@ public function appendMessage(string $folder, string $message, ?array $flags = n
193199

194200
$tokens[] = $this->escapeString($message);
195201

196-
return $this->send('APPEND', $tokens);
202+
$this->send('APPEND', $tokens, tag: $tag);
203+
204+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to append message'));
205+
206+
return $this->result->responses()->untagged()->filter(
207+
fn (UntaggedResponse $response) => $response->type()->is('LIST')
208+
);
197209
}
198210

199211
/**
200212
* {@inheritDoc}
201213
*/
202-
public function copyMessage(string $folder, $from, ?int $to = null): ResponseCollection
214+
public function copyMessage(string $folder, $from, ?int $to = null): void
203215
{
204-
return $this->send('UID COPY', [
216+
$this->send('UID COPY', [
205217
$this->buildSet($from, $to),
206218
$this->escapeString($folder),
207-
]);
219+
], $tag);
220+
221+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to copy message'));
208222
}
209223

210224
/**
211225
* {@inheritDoc}
212226
*/
213-
public function copyManyMessages(array $messages, string $folder): ResponseCollection
227+
public function copyManyMessages(array $messages, string $folder): void
214228
{
215229
$set = implode(',', $messages);
216230

217231
$tokens = [$set, $this->escapeString($folder)];
218232

219-
$this->send('UID COPY', $tokens);
233+
$this->send('UID COPY', $tokens, $tag);
234+
235+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to copy messages'));
220236
}
221237

222238
/**
223239
* {@inheritDoc}
224240
*/
225-
public function moveMessage(string $folder, $from, ?int $to = null): ResponseCollection
241+
public function moveMessage(string $folder, $from, ?int $to = null): void
226242
{
227243
$set = $this->buildSet($from, $to);
228244

229-
return $this->send('UID MOVE', [$set, $this->escapeString($folder)]);
245+
$this->send('UID MOVE', [$set, $this->escapeString($folder)], $tag);
246+
247+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to move message'));
230248
}
231249

232250
/**
233251
* {@inheritDoc}
234252
*/
235-
public function moveManyMessages(array $messages, string $folder): ResponseCollection
253+
public function moveManyMessages(array $messages, string $folder): void
236254
{
237255
$set = implode(',', $messages);
238256

239257
$tokens = [$set, $this->escapeString($folder)];
240258

241-
return $this->send('UID MOVE', $tokens);
259+
$this->send('UID MOVE', $tokens, $tag);
260+
261+
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to move messages'));
242262
}
243263

244264
/**

0 commit comments

Comments
 (0)