refactor: mailbox resolution
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -468,21 +468,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
$this->initialize();
|
$this->initialize();
|
||||||
|
|
||||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
|
||||||
|
|
||||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||||
}
|
}
|
||||||
|
|
||||||
$deleteTargetIdentifier = null;
|
$deleteTargetIdentifier = $deleteMode === 'soft' ? $this->resolveDeleteDestination() : null;
|
||||||
if ($deleteMode === 'soft') {
|
|
||||||
$deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
|
|
||||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
|
|
||||||
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
|
|
||||||
if ($deleteTargetIdentifier === null) {
|
|
||||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deleteMode === 'soft') {
|
if ($deleteMode === 'soft') {
|
||||||
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
||||||
@@ -737,7 +728,6 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
|
|
||||||
// determine delete mode and target collection (e.g. Trash) if applicable
|
// determine delete mode and target collection (e.g. Trash) if applicable
|
||||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
|
||||||
|
|
||||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||||
@@ -746,15 +736,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
// connect to remote store
|
// connect to remote store
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
|
|
||||||
$deleteTargetIdentifier = null;
|
$deleteTargetIdentifier = $deleteMode === 'soft' ? $this->resolveDeleteDestination() : null;
|
||||||
if ($deleteMode === 'soft') {
|
|
||||||
$deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
|
|
||||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
|
|
||||||
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
|
|
||||||
if ($deleteTargetIdentifier === null) {
|
|
||||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$deleteTargetNative = $deleteTargetIdentifier?->collection();
|
$deleteTargetNative = $deleteTargetIdentifier?->collection();
|
||||||
|
|
||||||
@@ -1036,6 +1018,29 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
return [$native->toJmap(), $uploads];
|
return [$native->toJmap(), $uploads];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the collection soft-deleted messages and collections are moved to
|
||||||
|
*/
|
||||||
|
private function resolveDeleteDestination(): CollectionIdentifier
|
||||||
|
{
|
||||||
|
$destination = trim((string) ($this->auxiliary['deleteDestination'] ?? ''));
|
||||||
|
|
||||||
|
if ($destination === '') {
|
||||||
|
return $this->resolveCollectionByRole(CollectionRoles::Trash->value)
|
||||||
|
?? throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||||
|
}
|
||||||
|
|
||||||
|
$role = CollectionRoles::tryFrom(strtolower($destination));
|
||||||
|
if ($role !== null && $role !== CollectionRoles::None) {
|
||||||
|
$resolved = $this->resolveCollectionByRole($role->value);
|
||||||
|
if ($resolved !== null) {
|
||||||
|
return $resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CollectionIdentifier($this->provider(), (string) $this->identifier(), $destination);
|
||||||
|
}
|
||||||
|
|
||||||
private function resolveCollectionByRole(string $role): ?CollectionIdentifier
|
private function resolveCollectionByRole(string $role): ?CollectionIdentifier
|
||||||
{
|
{
|
||||||
$filter = $this->collectionListFilter();
|
$filter = $this->collectionListFilter();
|
||||||
|
|||||||
Reference in New Issue
Block a user