diff --git a/lib/Providers/Service.php b/lib/Providers/Service.php index 41e3ffa..4b97ba3 100644 --- a/lib/Providers/Service.php +++ b/lib/Providers/Service.php @@ -675,10 +675,27 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC // ignore — the message was already delivered } + // Best-effort: IMAP has no native "submit existing draft" operation, so the + // message above was always sent fresh. If it originated from a synced draft, + // remove the now-superseded draft UID. A failure here must not turn a + // successful delivery into an error; the draft is simply left for a later + // discard or retry. + if ($source !== null + && $source->provider() === $this->provider() + && $source->service() === $this->identifier()) { + try { + $this->initialize(); + $this->remoteService->entityDestroy($source->collection(), (int) $source->entity()); + } catch (\Throwable) { + // ignore — the message was already delivered + } + } + return new EntitySubmitResult( disposition: EntitySubmitResult::DISPOSITION_SENT, transportId: $queueId !== '' ? $queueId : null, sentEntity: $sentEntity, + sourceDraft: $source instanceof EntityIdentifier ? $source : null, ); }