Files
provider_imap/lib/Providers/EntityResource.php
2026-05-14 22:50:21 -04:00

55 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderImap\Providers;
use KTXM\ProviderImap\Client\Message;
use KTXF\Mail\Entity\EntityMutableAbstract;
/**
* Mail Entity Resource Implementation
*/
class EntityResource extends EntityMutableAbstract {
public function __construct(
string $provider = 'imap',
string|int|null $service = null,
) {
parent::__construct($provider, $service);
}
/**
* Convert IMAP data to a mail entity object.
*/
public function fromImap(Message $message, string $mailbox): static
{
$this->data['collection'] = $mailbox;
$this->data['identifier'] = $message->uid() ?: $message->sequence();
if ($message->internalDate() !== null) {
$this->data['created'] = $message->internalDate();
}
$this->getProperties()->fromImap($message);
return $this;
}
/**
* @inheritDoc
*/
public function getProperties(): MessageProperties {
if (!isset($this->properties)) {
$this->properties = new MessageProperties([]);
}
return $this->properties;
}
}