generated from Nodarx/template
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 179ed7205a |
Generated
+2
-2
@@ -273,7 +273,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/mime",
|
"name": "symfony/mime",
|
||||||
"version": "v7.4.18",
|
"version": "v7.4.17",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/mime.git",
|
"url": "https://github.com/symfony/mime.git",
|
||||||
@@ -338,7 +338,7 @@
|
|||||||
"mime-type"
|
"mime-type"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/mime/tree/v7.4.18"
|
"source": "https://github.com/symfony/mime/tree/v7.4.17"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ namespace KTXM\ProviderImap\Providers;
|
|||||||
|
|
||||||
use KTXM\ProviderImap\Client\Message;
|
use KTXM\ProviderImap\Client\Message;
|
||||||
use KTXF\Mail\Entity\EntityMutableAbstract;
|
use KTXF\Mail\Entity\EntityMutableAbstract;
|
||||||
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mail Entity Resource Implementation
|
* Mail Entity Resource Implementation
|
||||||
@@ -43,26 +42,6 @@ class EntityResource extends EntityMutableAbstract {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate an entity returned by a create or replacement operation.
|
|
||||||
*/
|
|
||||||
public function fromMutation(
|
|
||||||
string $mailbox,
|
|
||||||
string|int $identifier,
|
|
||||||
MessagePropertiesMutableInterface $properties,
|
|
||||||
): static {
|
|
||||||
$this->data['collection'] = $mailbox;
|
|
||||||
$this->data['identifier'] = $identifier;
|
|
||||||
|
|
||||||
if ($properties instanceof MessageProperties) {
|
|
||||||
$this->setProperties($properties);
|
|
||||||
} else {
|
|
||||||
$this->getProperties()->jsonDeserialize($properties->jsonSerialize());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
],
|
],
|
||||||
self::CAPABILITY_ENTITY_FETCH => true,
|
self::CAPABILITY_ENTITY_FETCH => true,
|
||||||
self::CAPABILITY_ENTITY_EXTANT => true,
|
self::CAPABILITY_ENTITY_EXTANT => true,
|
||||||
self::CAPABILITY_ENTITY_CREATE => true,
|
self::CAPABILITY_ENTITY_CREATE => false,
|
||||||
self::CAPABILITY_ENTITY_MODIFY => true,
|
self::CAPABILITY_ENTITY_MODIFY => false,
|
||||||
self::CAPABILITY_ENTITY_PATCH => true,
|
self::CAPABILITY_ENTITY_PATCH => true,
|
||||||
self::CAPABILITY_ENTITY_DELETE => true,
|
self::CAPABILITY_ENTITY_DELETE => true,
|
||||||
self::CAPABILITY_ENTITY_MOVE => true,
|
self::CAPABILITY_ENTITY_MOVE => true,
|
||||||
@@ -675,27 +675,10 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
// ignore — the message was already delivered
|
// 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(
|
return new EntitySubmitResult(
|
||||||
disposition: EntitySubmitResult::DISPOSITION_SENT,
|
disposition: EntitySubmitResult::DISPOSITION_SENT,
|
||||||
transportId: $queueId !== '' ? $queueId : null,
|
transportId: $queueId !== '' ? $queueId : null,
|
||||||
sentEntity: $sentEntity,
|
sentEntity: $sentEntity,
|
||||||
sourceDraft: $source instanceof EntityIdentifier ? $source : null,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -718,45 +701,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
|
|
||||||
public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource
|
public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource
|
||||||
{
|
{
|
||||||
if ($target->provider() !== $this->provider() || (string)$target->service() !== (string)$this->identifier()) {
|
throw new \RuntimeException('Entity creation is not supported in this service');
|
||||||
throw new \InvalidArgumentException('Target collection does not belong to this service: ' . (string)$target);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
[$nativeMessage, $nativeFlags] = $this->messagePayload($properties, $options);
|
|
||||||
$created = $this->remoteService->entityCreate(
|
|
||||||
(string)$target->collection(),
|
|
||||||
$nativeMessage,
|
|
||||||
$nativeFlags,
|
|
||||||
);
|
|
||||||
if ($created === null || $created <= 0) {
|
|
||||||
throw new \RuntimeException('IMAP APPEND did not return a valid UID');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->entityFresh()->fromMutation((string)$target->collection(), $created, $properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityModify(EntityIdentifier $target, MessagePropertiesMutableInterface $properties): EntityResource
|
public function entityModify(EntityIdentifier $target, MessagePropertiesMutableInterface $properties): EntityResource
|
||||||
{
|
{
|
||||||
if ($target->provider() !== $this->provider() || (string)$target->service() !== (string)$this->identifier()) {
|
throw new \RuntimeException('Entity modification is not supported in this service');
|
||||||
throw new \InvalidArgumentException('Target entity does not belong to this service: ' . (string)$target);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
[$nativeMessage, $nativeFlags] = $this->messagePayload($properties);
|
|
||||||
$modified = $this->remoteService->entityReplace(
|
|
||||||
(string)$target->collection(),
|
|
||||||
(int)$target->entity(),
|
|
||||||
$nativeMessage,
|
|
||||||
$nativeFlags,
|
|
||||||
);
|
|
||||||
if ($modified === null || $modified <= 0) {
|
|
||||||
throw new \RuntimeException('IMAP replacement did not return a valid UID');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->entityFresh()->fromMutation((string)$target->collection(), $modified, $properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
|
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
|
||||||
@@ -941,46 +891,5 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert canonical message flags to IMAP system flags.
|
|
||||||
*
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
private function messageFlags(MessagePropertiesMutableInterface $properties): array
|
|
||||||
{
|
|
||||||
$flags = [];
|
|
||||||
foreach ($properties->getFlags() as $flag => $enabled) {
|
|
||||||
if ($enabled !== true) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$flags[] = match (strtolower((string)$flag)) {
|
|
||||||
'seen' => '\\Seen',
|
|
||||||
'flagged' => '\\Flagged',
|
|
||||||
'answered' => '\\Answered',
|
|
||||||
'draft' => '\\Draft',
|
|
||||||
'deleted' => '\\Deleted',
|
|
||||||
default => (string)$flag,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values(array_unique($flags));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert message properties into the native IMAP append payload.
|
|
||||||
*
|
|
||||||
* @return array{0: string, 1: string[]}
|
|
||||||
*/
|
|
||||||
private function messagePayload(MessagePropertiesMutableInterface $properties, array $options = []): array
|
|
||||||
{
|
|
||||||
$flags = $this->messageFlags($properties);
|
|
||||||
if (isset($options['flags']) && is_array($options['flags'])) {
|
|
||||||
$flags = array_values(array_unique([...$flags, ...$options['flags']]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return [(new MessageBuilder())->build($properties), $flags];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class RemoteMailService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logDir = dirname(__DIR__, 5) . '/var/logs/provider_imap';
|
$logDir = dirname(__DIR__, 5) . '/var/log';
|
||||||
|
|
||||||
return new PlainFileLogger($logDir . '/' . $channel, $this->service->identifier());
|
return new PlainFileLogger($logDir . '/' . $channel, $this->service->identifier());
|
||||||
}
|
}
|
||||||
@@ -490,44 +490,6 @@ class RemoteMailService
|
|||||||
return $this->imapClient()->perform(new AppendCommand($collection, $rawMessage, $flags));
|
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.
|
* Modify message flags for one or more messages.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace KTXT\ProviderImap\Tests\Unit;
|
|
||||||
|
|
||||||
use KTXM\ProviderImap\Providers\Service;
|
|
||||||
use KTXM\ProviderImap\Service\Remote\RemoteMailService;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
final class RemoteMailServiceTest extends TestCase {
|
|
||||||
|
|
||||||
public function testEntityReplaceReturnsAuthoritativeReplacementUid(): void {
|
|
||||||
$service = new RemoteMailServiceStub($this->createStub(Service::class));
|
|
||||||
$service->appendUid = 202;
|
|
||||||
$service->destroyResults = [[101 => true]];
|
|
||||||
|
|
||||||
$result = $service->entityReplace('Drafts', 101, 'raw message', ['\\Draft']);
|
|
||||||
|
|
||||||
$this->assertSame(202, $result);
|
|
||||||
$this->assertSame([
|
|
||||||
['Drafts', 'raw message', ['\\Draft']],
|
|
||||||
], $service->createCalls);
|
|
||||||
$this->assertSame([
|
|
||||||
['Drafts', [101]],
|
|
||||||
], $service->destroyCalls);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testEntityReplaceRemovesReplacementWhenOldUidCannotBeDeleted(): void {
|
|
||||||
$service = new RemoteMailServiceStub($this->createStub(Service::class));
|
|
||||||
$service->appendUid = 202;
|
|
||||||
$service->destroyResults = [
|
|
||||||
[101 => false],
|
|
||||||
[202 => true],
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
$service->entityReplace('Drafts', 101, 'raw message', ['\\Draft']);
|
|
||||||
$this->fail('Expected superseded message cleanup failure');
|
|
||||||
} catch (RuntimeException $exception) {
|
|
||||||
$this->assertSame('Failed to delete the superseded IMAP entity', $exception->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertSame([
|
|
||||||
['Drafts', [101]],
|
|
||||||
['Drafts', [202]],
|
|
||||||
], $service->destroyCalls);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class RemoteMailServiceStub extends RemoteMailService {
|
|
||||||
|
|
||||||
public ?int $appendUid = null;
|
|
||||||
public array $createCalls = [];
|
|
||||||
public array $destroyCalls = [];
|
|
||||||
public array $destroyResults = [];
|
|
||||||
|
|
||||||
public function entityCreate(string $collection, string $rawMessage, array $flags = []): ?int {
|
|
||||||
$this->createCalls[] = [$collection, $rawMessage, $flags];
|
|
||||||
return $this->appendUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityDestroy(string $collection, int ...$uids): array {
|
|
||||||
$this->destroyCalls[] = [$collection, $uids];
|
|
||||||
return array_shift($this->destroyResults) ?? [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user