fix: message sending

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-30 21:03:59 -04:00
parent 4cd249d019
commit b60341f62d
+28 -32
View File
@@ -912,21 +912,29 @@ class RemoteMailService {
* *
* @since Release 2.0.0 * @since Release 2.0.0
*/ */
public function entitySubmitFresh(string $identityId, array $message, string $preSendTarget, string $postSentTarget): string { public function entitySubmitFresh(string $identityId, array $data, string $preSendTarget, string $postSentTarget): string {
$mail = new MailParametersRequest(); $message = new MailParametersRequest();
$mail->parametersRaw($message); $message->parametersRaw($data);
$messageCreateId = 'm_' . uniqid(); $messageId = 'm_' . uniqid();
$submissionCreateId = 's_' . uniqid(); $submissionId = 's_' . uniqid();
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$createdMessage = $r0->create($messageCreateId, $mail); $m0 = $r0->create($messageId, $message);
$createdMessage->in($preSendTarget); $m0->in($preSendTarget);
$m0->draft(true);
$m0->seen(true);
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$submission = $r1->create($submissionCreateId); $r1->completionUpdate('#' . $messageId, [
$submission->identity($identityId); 'mailboxIds/' . $postSentTarget => true,
$submission->message('#' . $messageCreateId); 'mailboxIds/' . $preSendTarget => null,
'keywords/$draft' => null,
]);
$s0 = $r1->create($submissionId);
$s0->identity($identityId);
$s0->message('#' . $messageId);
$bundle = $this->dataStore->perform([$r0, $r1]); $bundle = $this->dataStore->perform([$r0, $r1]);
$messageResponse = $bundle->response(0); $messageResponse = $bundle->response(0);
@@ -934,7 +942,7 @@ class RemoteMailService {
throw new Exception($messageResponse->type() . ': ' . $messageResponse->description(), 1); throw new Exception($messageResponse->type() . ': ' . $messageResponse->description(), 1);
} }
if (method_exists($messageResponse, 'createFailure')) { if (method_exists($messageResponse, 'createFailure')) {
$failure = $messageResponse->createFailure($messageCreateId); $failure = $messageResponse->createFailure($messageId);
if (is_array($failure)) { if (is_array($failure)) {
$type = $failure['type'] ?? 'unknownError'; $type = $failure['type'] ?? 'unknownError';
$description = $failure['description'] ?? 'Email creation failed'; $description = $failure['description'] ?? 'Email creation failed';
@@ -950,7 +958,7 @@ class RemoteMailService {
throw new Exception($response->type() . ': ' . $response->description(), 1); throw new Exception($response->type() . ': ' . $response->description(), 1);
} }
return $this->extractSubmissionIdentifier($response, $submissionCreateId); return $this->extractSubmissionIdentifier($response, $submissionId);
} }
/** /**
@@ -978,18 +986,18 @@ class RemoteMailService {
$requests = []; $requests = [];
if ($patch !== null && $patch !== []) { if ($patch !== null && $patch !== []) {
$draftMutation = new MailParametersRequest(); $m0 = new MailParametersRequest();
$draftMutation->parametersRaw($patch); $m0->parametersRaw($patch);
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($draftId, $draftMutation); $r0->update($draftId, $m0);
$requests[] = $r0; $requests[] = $r0;
} }
$submissionCreateId = '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);
$submission = $r1->create($submissionCreateId); $s0 = $r1->create($submissionId);
$submission->identity($identityId); $s0->identity($identityId);
$submission->message($draftId); $s0->message($draftId);
$requests[] = $r1; $requests[] = $r1;
$bundle = $this->dataStore->perform($requests); $bundle = $this->dataStore->perform($requests);
@@ -1002,19 +1010,7 @@ class RemoteMailService {
throw new Exception($response->type() . ': ' . $response->description(), 1); throw new Exception($response->type() . ': ' . $response->description(), 1);
} }
return $this->extractSubmissionIdentifier($response, $submissionCreateId); return $this->extractSubmissionIdentifier($response, $submissionId);
}
private function collectionByRole(string $role): ?string {
$filter = $this->collectionListFilter();
$filter->condition('role', $role);
$collections = $this->collectionList(null, $filter, null);
if ($collections === []) {
return null;
}
return (string)array_key_first($collections);
} }
private function extractSubmissionIdentifier(object $response, string $createId): string { private function extractSubmissionIdentifier(object $response, string $createId): string {