Initial commit
This commit is contained in:
82
lib/Providers/Mail/EntityResource.php
Normal file
82
lib/Providers/Mail/EntityResource.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers\Mail;
|
||||
|
||||
use KTXF\Mail\Entity\EntityMutableAbstract;
|
||||
|
||||
/**
|
||||
* Mail Entity Resource Implementation
|
||||
*/
|
||||
class EntityResource extends EntityMutableAbstract {
|
||||
|
||||
public function __construct(
|
||||
string $provider = 'jmapc',
|
||||
string|int|null $service = null,
|
||||
) {
|
||||
parent::__construct($provider, $service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JMAP parameters array to mail entity object
|
||||
*
|
||||
* @param array $parameters JMAP parameters array
|
||||
*/
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
if (isset($parameters['mailboxIds'])) {
|
||||
$this->data['collection'] = array_keys($parameters['mailboxIds'])[0];
|
||||
}
|
||||
if (isset($parameters['id'])) {
|
||||
$this->data['identifier'] = $parameters['id'];
|
||||
}
|
||||
if (isset($parameters['signature'])) {
|
||||
$this->data['signature'] = $parameters['signature'];
|
||||
}
|
||||
if (isset($parameters['receivedAt']) || isset($parameters['sentAt'])) {
|
||||
$this->data['created'] = $parameters['receivedAt'] ?? $parameters['sentAt'];
|
||||
}
|
||||
if (isset($parameters['updated'])) {
|
||||
$this->data['modified'] = $parameters['updated'];
|
||||
}
|
||||
|
||||
$this->getProperties()->fromJmap($parameters);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mail entity object to JMAP parameters array
|
||||
*/
|
||||
public function toJmap(): array {
|
||||
|
||||
$parameters = [];
|
||||
|
||||
if (isset($this->data['collection'])) {
|
||||
$parameters['mailboxIds'] = [$this->data['collection']];
|
||||
}
|
||||
if (isset($this->data['identifier'])) {
|
||||
$parameters['id'] = $this->data['identifier'];
|
||||
}
|
||||
|
||||
$parameters = array_merge($parameters, $this->getProperties()->toJmap());
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): MessageProperties {
|
||||
if (!isset($this->properties)) {
|
||||
$this->properties = new MessageProperties([]);
|
||||
}
|
||||
return $this->properties;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user