generated from Nodarx/template
feat: mail entity download
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -46,9 +46,7 @@ use KTXF\Resource\Range\IRangeTally;
|
||||
use KTXF\Resource\Range\RangeAnchorType;
|
||||
use KTXF\Resource\Range\RangeTally;
|
||||
use KTXF\Resource\Sort\ISort;
|
||||
use KTXF\Mail\Service\DownloadResult;
|
||||
use KTXM\ProviderImap\Providers\CollectionResource;
|
||||
use KTXM\ProviderImap\Providers\EntityResource;
|
||||
use KTXF\Resource\BinaryResource;
|
||||
|
||||
/**
|
||||
* IMAP Remote Mail Service
|
||||
@@ -307,7 +305,7 @@ class RemoteMailService
|
||||
* @param int $uid Message UID
|
||||
* @param string|null $partId MIME section (e.g. '1', '1.2'); null = full RFC 822
|
||||
*/
|
||||
public function entityDownload(string $collection, int $uid, ?string $partId = null): DownloadResult
|
||||
public function entityDownload(string $collection, int $uid, ?string $partId = null): BinaryResource
|
||||
{
|
||||
$this->client->perform(new SelectCommand($collection, true));
|
||||
|
||||
@@ -338,7 +336,7 @@ class RemoteMailService
|
||||
$encoding
|
||||
);
|
||||
|
||||
return new DownloadResult($filename, $mimeType, $stream);
|
||||
return new BinaryResource($filename, $mimeType, $stream);
|
||||
}
|
||||
|
||||
private function findBodyPart(MessagePart $root, string $partId): ?MessagePart
|
||||
@@ -537,6 +535,36 @@ class RemoteMailService
|
||||
|
||||
}
|
||||
|
||||
public function entityCopy(string $targetCollection, string $sourceCollection, int ...$uids): array
|
||||
{
|
||||
if (empty($uids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->client->perform(new SelectCommand($sourceCollection, false));
|
||||
$response = $this->client->perform(new CopyCommand(
|
||||
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
|
||||
$targetCollection,
|
||||
));
|
||||
|
||||
if (!$response->isOk()) {
|
||||
throw new ImapException('Failed to copy messages: ' . implode(', ', $response->responseCodes()));
|
||||
}
|
||||
|
||||
// construct operation result as a map of source UID to boolean or destination UID, depending on server support
|
||||
$map = $response->copyUidMap();
|
||||
if ($map === []) {
|
||||
$result = array_fill_keys(array_map('strval', $uids), true);
|
||||
} else {
|
||||
$result = array_fill_keys(array_map('strval', $uids), false);
|
||||
foreach ($uids as $uid) {
|
||||
$result[$uid] = $map[$uid] ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function buildEntitySearchCriteria(?IFilter $filter): SearchCriteriaBuilder
|
||||
{
|
||||
if ($filter === null || $filter->conditions() === []) {
|
||||
|
||||
Reference in New Issue
Block a user