Skip to content

Commit 8b73114

Browse files
committed
Fix up flagging
1 parent 5255f0e commit 8b73114

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

src/Connection/ImapConnection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function login(string $user, string $password): TaggedResponse
3535
*/
3636
public function authenticate(string $user, string $token): TaggedResponse
3737
{
38-
$authenticateParams = ['XOAUTH2', base64_encode("user=$user\1auth=Bearer $token\1\1")];
38+
$credentials = base64_encode("user=$user\1auth=Bearer $token\1\1");
3939

40-
$this->send('AUTHENTICATE', $authenticateParams, $tag);
40+
$this->send('AUTHENTICATE', ['XOAUTH2', $credentials], $tag);
4141

4242
return $this->assertTaggedResponse($tag, fn () => new AuthFailedException('Failed to authenticate'));
4343
}
@@ -84,13 +84,9 @@ public function examineFolder(string $folder = 'INBOX'): ResponseCollection
8484

8585
/**
8686
* Examine and select have the same response.
87-
*
88-
* @param string $command can be 'EXAMINE' or 'SELECT'
89-
* @param string $folder target folder
9087
*/
9188
protected function examineOrSelect(string $command = 'EXAMINE', string $folder = 'INBOX'): ResponseCollection
9289
{
93-
// Send the command and retrieve the tag.
9490
$this->send($command, [$this->escapeString($folder)], $tag);
9591

9692
$this->assertTaggedResponse($tag, fn () => new RuntimeException('Failed to select folder'));

src/Connection/Responses/Data/Data.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function __construct(
1919

2020
/**
2121
* Get the tokens.
22+
*
23+
* @return Token[]|Data[]
2224
*/
2325
public function tokens(): array
2426
{

src/Connection/Responses/HasTokens.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trait HasTokens
99
{
1010
/**
1111
* Get the response tokens.
12+
*
13+
* @return Token[]|Data[]
1214
*/
1315
abstract public function tokens(): array;
1416

src/Connection/Responses/Response.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function __construct(
2020

2121
/**
2222
* Get the response tokens.
23+
*
24+
* @return Token[]|Data[]
2325
*/
2426
public function tokens(): array
2527
{

src/Folder.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function messages(): MessageQuery
9090
*/
9191
public function idle(callable $callback, int $timeout = 300): void
9292
{
93-
if (! $this->hasIdleSupport()) {
93+
if (! $this->hasCapability('IDLE')) {
9494
throw new RuntimeException('IMAP server does not support IDLE');
9595
}
9696

@@ -123,33 +123,27 @@ function (int $msgn) use ($callback, $fetch) {
123123
/**
124124
* Move or rename the current folder.
125125
*/
126-
public function move(string $newPath, bool $expunge = true): array
126+
public function move(string $newPath, bool $expunge = true): void
127127
{
128-
$status = $this->mailbox->connection()
129-
->renameFolder($this->path, $newPath)
130-
->getValidatedData();
128+
$this->mailbox->connection()->renameFolder($this->path, $newPath);
131129

132130
if ($expunge) {
133131
$this->expunge();
134132
}
135133

136134
$this->path = $newPath;
137-
138-
return $status;
139135
}
140136

141137
/**
142138
* Delete the current folder.
143139
*/
144-
public function delete(bool $expunge = true): array
140+
public function delete(bool $expunge = true): void
145141
{
146142
$this->mailbox->connection()->deleteFolder($this->path);
147143

148144
if ($expunge) {
149-
return $this->expunge();
145+
$this->expunge();
150146
}
151-
152-
return [];
153147
}
154148

155149
/**
@@ -186,7 +180,7 @@ public function examine(): array
186180
{
187181
return $this->mailbox->connection()->examineFolder($this->path)->map(
188182
fn (UntaggedResponse $response) => $response->toArray()
189-
);
183+
)->all();
190184
}
191185

192186
/**
@@ -196,15 +190,15 @@ public function expunge(): array
196190
{
197191
return $this->mailbox->connection()->expunge()->map(
198192
fn (UntaggedResponse $response) => $response->tokenAt(1)->value
199-
);
193+
)->all();
200194
}
201195

202196
/**
203-
* Determine if the mailbox has IDLE support.
197+
* Determine if the mailbox has the given capability.
204198
*/
205-
protected function hasIdleSupport(): bool
199+
public function hasCapability(string $capability): bool
206200
{
207-
return in_array('IDLE', $this->capabilities());
201+
return in_array($capability, $this->capabilities());
208202
}
209203

210204
/**

src/Message.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ public function header(string $name, int $offset = 0): ?IHeader
283283
return $this->parse()->getHeader($name, $offset);
284284
}
285285

286+
/**
287+
* Mark the message as read. Alias for markSeen.
288+
*/
289+
public function markRead(bool $expunge = true): void
290+
{
291+
$this->markSeen($expunge);
292+
}
293+
294+
/**
295+
* Mark the message as unread. Alias for unmarkSeen.
296+
*/
297+
public function markUnread(bool $expunge = true): void
298+
{
299+
$this->unmarkSeen($expunge);
300+
}
301+
286302
/**
287303
* Mark the message as seen.
288304
*/
@@ -380,15 +396,15 @@ public function unmarkRecent(bool $expunge = true): void
380396
}
381397

382398
/**
383-
* Set or remove a flag from the message.
399+
* Add or remove a flag from the message.
384400
*/
385401
public function flag(array|string $flag, string $operation = '+', bool $expunge = true): void
386402
{
387403
$flag = '\\'.trim(is_array($flag) ? implode(' \\', $flag) : $flag);
388404

389-
$this->folder->mailbox()->connection()
390-
->store([$flag], $this->uid, null, $operation, true)
391-
->getValidatedData();
405+
$this->folder->mailbox()
406+
->connection()
407+
->store([$flag], $this->uid, null, $operation, true);
392408

393409
if ($expunge) {
394410
$this->folder->expunge();

0 commit comments

Comments
 (0)