fix: folder deletion while in trash
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -484,17 +484,34 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to determine if the folder being deleted is already in the trash
|
if ($deleteMode === 'soft') {
|
||||||
if (str_starts_with((string) $target->collection(), (string) $deleteTargetIdentifier?->collection())) {
|
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
||||||
// if so, we should hard delete instead of moving to avoid duplicates in the trash
|
if ($targetMailbox === null) {
|
||||||
$deleteMode = 'hard';
|
throw new \RuntimeException('Collection not found for delete operation');
|
||||||
|
}
|
||||||
|
|
||||||
|
$targetIdentifier = (string) $target->collection();
|
||||||
|
$trashIdentifier = (string) $deleteTargetIdentifier->collection();
|
||||||
|
$parentIdentifier = isset($targetMailbox['parentId'])
|
||||||
|
? (string) $targetMailbox['parentId']
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// JMAP mailbox IDs are opaque, so containment must be determined
|
||||||
|
// from parentId rather than by comparing ID prefixes.
|
||||||
|
if ($targetIdentifier === $trashIdentifier || $parentIdentifier === $trashIdentifier) {
|
||||||
|
$deleteMode = 'hard';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = match ($deleteMode) {
|
if ($deleteMode === 'soft') {
|
||||||
'soft' => $this->collectionMove($deleteTargetIdentifier, $target),
|
return $this->collectionMove($deleteTargetIdentifier, $target);
|
||||||
'hard' => $this->mailService->collectionDestroy($target->collection(), $force),
|
}
|
||||||
};
|
|
||||||
return $result;
|
if ($this->mailService->collectionDestroy((string) $target->collection(), $force) === null) {
|
||||||
|
throw new \RuntimeException("Failed to delete collection: {$target->collection()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
|
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user