fix: move draft to sent and clear draft flag on submission

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-25 22:42:16 -04:00
parent 72d72b29c5
commit 320db9f82b
2 changed files with 29 additions and 2 deletions
+19
View File
@@ -950,6 +950,23 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
); );
} }
// determine the sent folder
// if no explicit sent folder is configured, we will attempt to find a folder with the "sent" role.
$postSentTarget = $this->auxiliary['sentTarget'] ?? null;
$postSentTarget = $postSentTarget !== null && (string) $postSentTarget !== ''
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $postSentTarget)
: $this->resolveCollectionByRole(CollectionRoles::Sent->value);
if ($postSentTarget === null
|| $postSentTarget->provider() !== $this->provider()
|| $postSentTarget->service() !== (string)$this->identifier()) {
return new EntitySubmitResult(
EntitySubmitResult::DISPOSITION_ERROR,
errorCode: 'sent_collection_not_found',
errorMessage: 'No Sent target collection is configured or could be resolved for this service',
);
}
if ($message !== null) { if ($message !== null) {
[$nativeMessage, $nativeAttachments] = $this->messagePayload($message); [$nativeMessage, $nativeAttachments] = $this->messagePayload($message);
} else { } else {
@@ -960,6 +977,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
$transportId = $this->mailService->entitySubmitDraft( $transportId = $this->mailService->entitySubmitDraft(
$identityId, $identityId,
(string)$source->entity(), (string)$source->entity(),
(string)$source->collection(),
$postSentTarget->collection(),
$nativeMessage, $nativeMessage,
$nativeAttachments, $nativeAttachments,
); );
+10 -2
View File
@@ -1007,11 +1007,14 @@ class RemoteMailService {
} }
/** /**
* Submit an existing draft message. * Submit an existing draft message. On success, the draft Email is moved
* from the drafts mailbox to the sent mailbox and its \Draft keyword is
* cleared in the same request, so the submitted draft becomes the sent
* copy rather than lingering as an unsent draft.
* *
* @since Release 2.0.0 * @since Release 2.0.0
*/ */
public function entitySubmitDraft(string $identityId, string $draftId, ?array $patch = null, array $attachments = []): string { public function entitySubmitDraft(string $identityId, string $draftId, string $preSendTarget, string $postSentTarget, ?array $patch = null, array $attachments = []): string {
if ($draftId === '') { if ($draftId === '') {
throw new Exception('Draft identifier is required for draft submission', 1); throw new Exception('Draft identifier is required for draft submission', 1);
} }
@@ -1029,6 +1032,11 @@ class RemoteMailService {
$submissionId = 's_' . uniqid(); $submissionId = 's_' . uniqid();
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r1->completionUpdate($draftId, [
'mailboxIds/' . $postSentTarget => true,
'mailboxIds/' . $preSendTarget => null,
'keywords/$draft' => null,
]);
$s0 = $r1->create($submissionId); $s0 = $r1->create($submissionId);
$s0->identity($identityId); $s0->identity($identityId);
$s0->message($draftId); $s0->message($draftId);