Skip to content

Commit

Permalink
Fix use of ST_MSGN as sequence method (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
gioid committed Mar 1, 2023
1 parent 9f56ebf commit e108c27
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/Connection/Protocols/ImapProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, in
$data = [];

// find array key of UID value; try the last elements, or search for it
if ($uid) {
if ($uid === IMAP::ST_UID) {
$count = count($tokens[2]);
if ($tokens[2][$count - 2] == 'UID') {
$uidKey = $count - 1;
Expand All @@ -661,15 +661,15 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, in
}

// ignore other messages
if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] != $from : $tokens[0] != $from)) {
if ($to === null && !is_array($from) && ($uid === IMAP::ST_UID ? $tokens[2][$uidKey] != $from : $tokens[0] != $from)) {
continue;
}

// if we only want one item we return that one directly
if (count($items) == 1) {
if ($tokens[2][0] == $items[0]) {
$data = $tokens[2][1];
} elseif ($uid && $tokens[2][2] == $items[0]) {
} elseif ($uid === IMAP::ST_UID && $tokens[2][2] == $items[0]) {
$data = $tokens[2][3];
} else {
$expectedResponse = 0;
Expand All @@ -696,12 +696,12 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, in
}

// if we want only one message we can ignore everything else and just return
if ($to === null && !is_array($from) && ($uid ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
if ($to === null && !is_array($from) && ($uid === IMAP::ST_UID ? $tokens[2][$uidKey] == $from : $tokens[0] == $from)) {
// we still need to read all lines
while (!$this->readLine($response, $tokens, $tag))
return $response->setResult($data);
}
if ($uid) {
if ($uid === IMAP::ST_UID) {
$result[$tokens[2][$uidKey]] = $data;
} else {
$result[$tokens[0]] = $data;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public function overview(string $sequence, int|string $uid = IMAP::ST_UID): Resp
$response = $this->getUid();
$ids = [];
foreach ($response->data() as $msgn => $v) {
$id = $uid ? $v : $msgn;
$id = $uid === IMAP::ST_UID ? $v : $msgn;
if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) {
$ids[] = $id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Protocols/LegacyProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function content(int|array $uids, string $rfc = "RFC822", int|string $uid
$uids = is_array($uids) ? $uids : [$uids];
foreach ($uids as $id) {
$response->addCommand("imap_fetchbody");
$result[$id] = \imap_fetchbody($this->stream, $id, "", $uid ? IMAP::ST_UID : IMAP::NIL);
$result[$id] = \imap_fetchbody($this->stream, $id, "", $uid === IMAP::ST_UID ? IMAP::ST_UID : IMAP::NIL);
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function move(string $new_name, bool $expunge = true): array {
public function overview(string $sequence = null): array {
$this->client->openFolder($this->path);
$sequence = $sequence === null ? "1:*" : $sequence;
$uid = ClientManager::get('options.sequence', IMAP::ST_MSGN) == IMAP::ST_UID;
$uid = ClientManager::get('options.sequence', IMAP::ST_MSGN);
$response = $this->client->getConnection()->overview($sequence, $uid);
return $response->validatedData();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public function getHTMLBody(): string {
*/
private function parseHeader(): void {
$sequence_id = $this->getSequenceId();
$headers = $this->client->getConnection()->headers([$sequence_id], "RFC822", $this->sequence === IMAP::ST_UID)->validatedData();
$headers = $this->client->getConnection()->headers([$sequence_id], "RFC822", $this->sequence)->validatedData();
if (!isset($headers[$sequence_id])) {
throw new MessageHeaderFetchingException("no headers found", 0);
}
Expand Down Expand Up @@ -548,7 +548,7 @@ private function parseFlags(): void {

$sequence_id = $this->getSequenceId();
try {
$flags = $this->client->getConnection()->flags([$sequence_id], $this->sequence === IMAP::ST_UID)->validatedData();
$flags = $this->client->getConnection()->flags([$sequence_id], $this->sequence)->validatedData();
} catch (Exceptions\RuntimeException $e) {
throw new MessageFlagException("flag could not be fetched", 0, $e);
}
Expand Down Expand Up @@ -578,7 +578,7 @@ public function parseBody(): Message {

$sequence_id = $this->getSequenceId();
try {
$contents = $this->client->getConnection()->content([$sequence_id], "RFC822", $this->sequence === IMAP::ST_UID)->validatedData();
$contents = $this->client->getConnection()->content([$sequence_id], "RFC822", $this->sequence)->validatedData();
} catch (Exceptions\RuntimeException $e) {
throw new MessageContentFetchingException("failed to fetch content", 0);
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ public function copy(string $folder_path, bool $expunge = false): ?Message {
$folder = $this->client->getFolderByPath($folder_path);

$this->client->openFolder($this->folder_path);
if ($this->client->getConnection()->copyMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID)->validatedData()) {
if ($this->client->getConnection()->copyMessage($folder->path, $this->getSequenceId(), null, $this->sequence)->validatedData()) {
return $this->fetchNewMail($folder, $next_uid, "copied", $expunge);
}
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public function move(string $folder_path, bool $expunge = false): ?Message {
$folder = $this->client->getFolderByPath($folder_path);

$this->client->openFolder($this->folder_path);
if ($this->client->getConnection()->moveMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID)->validatedData()) {
if ($this->client->getConnection()->moveMessage($folder->path, $this->getSequenceId(), null, $this->sequence)->validatedData()) {
return $this->fetchNewMail($folder, $next_uid, "moved", $expunge);
}
}
Expand Down Expand Up @@ -1172,7 +1172,7 @@ public function setFlag(array|string $flag): bool {
$flag = "\\" . trim(is_array($flag) ? implode(" \\", $flag) : $flag);
$sequence_id = $this->getSequenceId();
try {
$status = $this->client->getConnection()->store([$flag], $sequence_id, $sequence_id, "+", true, $this->sequence === IMAP::ST_UID)->validatedData();
$status = $this->client->getConnection()->store([$flag], $sequence_id, $sequence_id, "+", true, $this->sequence)->validatedData();
} catch (Exceptions\RuntimeException $e) {
throw new MessageFlagException("flag could not be set", 0, $e);
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public function unsetFlag(array|string $flag): bool {
$flag = "\\" . trim(is_array($flag) ? implode(" \\", $flag) : $flag);
$sequence_id = $this->getSequenceId();
try {
$status = $this->client->getConnection()->store([$flag], $sequence_id, $sequence_id, "-", true, $this->sequence === IMAP::ST_UID)->validatedData();
$status = $this->client->getConnection()->store([$flag], $sequence_id, $sequence_id, "-", true, $this->sequence)->validatedData();
} catch (Exceptions\RuntimeException $e) {
throw new MessageFlagException("flag could not be removed", 0, $e);
}
Expand Down

0 comments on commit e108c27

Please sign in to comment.