feat: initial version

Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
Sebastian Krupinski
2026-02-20 16:41:19 -05:00
committed by Sebastian Krupinski
parent a313767846
commit e51c65bf19
139 changed files with 11256 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderImapMail\Providers;
use DateTimeInterface;
use Gricob\IMAP\Mime\Part\Part;
use Gricob\IMAP\Protocol\Response\Line\Data\FetchData;
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 gricob FetchData to mail entity object
*
* @param FetchData $fetchData result from IMAP FETCH command
* @param string $mailbox IMAP mailbox name (used as collection)
* @param Part|null $bodyPart MIME Part tree for body content (optional)
*/
public function fromImap(FetchData $fetchData, string $mailbox, ?Part $bodyPart = null): static {
// Collection = the IMAP mailbox name
$this->data['collection'] = $mailbox;
// Identifier = UID (preferred) or sequence number as fallback
$this->data['identifier'] = $fetchData->uid ?? $fetchData->id;
// Created = INTERNALDATE (server arrival time)
if ($fetchData->internalDate !== null) {
$this->data['created'] = $fetchData->internalDate->format(DateTimeInterface::ATOM);
}
$this->getProperties()->fromImap(
flags: $fetchData->flags ?? [],
envelope: $fetchData->envelope,
bodyStructure: $fetchData->bodyStructure,
size: $fetchData->rfc822Size ?? 0,
bodyPart: $bodyPart,
);
return $this;
}
/**
* Convert mail entity object to store array
*/
public function toStore(): array {
return array_merge(
$this->data,
['properties' => $this->getProperties()->toStore()]
);
}
/**
* Hydrate mail entity object from store array
*/
public function fromStore(array $data): static {
$properties = $data['properties'] ?? [];
unset($data['properties']);
$this->data = $data;
$this->getProperties()->fromStore($properties);
return $this;
}
/**
* @inheritDoc
*/
public function getProperties(): MessageProperties {
if (!isset($this->properties)) {
$this->properties = new MessageProperties([]);
}
return $this->properties;
}
}