feat: implement message create and update

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-25 21:45:32 -04:00
parent 0e99bb0fd2
commit ab5871aad7
4 changed files with 206 additions and 5 deletions
+39 -1
View File
@@ -131,7 +131,7 @@ class RemoteMailService
return null;
}
$logDir = dirname(__DIR__, 5) . '/var/log';
$logDir = dirname(__DIR__, 5) . '/var/logs/provider_imap';
return new PlainFileLogger($logDir . '/' . $channel, $this->service->identifier());
}
@@ -490,6 +490,44 @@ class RemoteMailService
return $this->imapClient()->perform(new AppendCommand($collection, $rawMessage, $flags));
}
/**
* Append a replacement message, then permanently remove the superseded UID.
* The replacement is removed on cleanup failure so the old UID remains
* authoritative for a later retry.
*
* @param string[] $flags
*/
public function entityReplace(
string $collection,
int $identifier,
string $rawMessage,
array $flags = [],
): ?int {
if ($identifier <= 0) {
throw new RuntimeException('A valid IMAP UID is required for replacement');
}
$replacement = $this->entityCreate($collection, $rawMessage, $flags);
if ($replacement === null || $replacement <= 0) {
throw new RuntimeException('IMAP replacement append did not return a valid UID');
}
try {
$deleted = $this->entityDestroy($collection, $identifier);
if (($deleted[$identifier] ?? false) !== true) {
throw new RuntimeException('Failed to delete the superseded IMAP entity');
}
} catch (\Throwable $error) {
try {
$this->entityDestroy($collection, $replacement);
} catch (\Throwable) {
}
throw $error;
}
return $replacement;
}
/**
* Modify message flags for one or more messages.
*