Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/public/Json/JsonDeserializable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\Json;

interface JsonDeserializable {

Check failure on line 12 in lib/public/Json/JsonDeserializable.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Json/JsonDeserializable.php:12:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)

public function jsonDeserialize(array $data): void;

}
31 changes: 30 additions & 1 deletion lib/public/Mail/Provider/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
namespace OCP\Mail\Provider;

use JsonSerializable;
use OCP\Json\JsonDeserializable;

/**
* Mail Address Object
*
Expand All @@ -16,7 +19,7 @@
* @since 30.0.0
*
*/
class Address implements \OCP\Mail\Provider\IAddress {
class Address implements IAddress, JsonSerializable, JsonDeserializable {

/**
* initialize the mail address object
Expand All @@ -32,6 +35,32 @@ public function __construct(
) {
}

/**
* export this objects data as an array
*
* @since 33.0.0
*
* @return array representation of this object as an array
*/
public function jsonSerialize(): array {
return [
'address' => $this->address,
'label' => $this->label,
];
}

/**
* import this objects data from an array
*
* @since 33.0.0
*
* @param array array representation of this object
*/
public function jsonDeserialize(array $data): void {
$this->address = $data['address'] ?? null;
$this->label = $data['label'] ?? null;
}

/**
* sets the mail address
*
Expand Down
35 changes: 34 additions & 1 deletion lib/public/Mail/Provider/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
namespace OCP\Mail\Provider;

use JsonSerializable;
use OCP\Json\JsonDeserializable;

/**
* Mail Attachment Object
*
Expand All @@ -16,7 +19,7 @@
* @since 30.0.0
*
*/
class Attachment implements \OCP\Mail\Provider\IAttachment {
class Attachment implements IAttachment, JsonSerializable, JsonDeserializable {

/**
* initialize the mail attachment object
Expand All @@ -36,6 +39,36 @@ public function __construct(
) {
}

/**
* export this objects data as an array
*
* @since 33.0.0
*
* @return array representation of this object as an array
*/
public function jsonSerialize(): array {
return [
'contents' => base64_encode($this->contents ?? ''),
'name' => $this->name,
'type' => $this->type,
'embedded' => $this->embedded,
];
}

/**
* import this objects data from an array
*
* @since 33.0.0
*
* @param array array representation of this object
*/
public function jsonDeserialize(array $data): void {
$this->contents = base64_decode($data['contents'] ?? '');
$this->name = $data['name'] ?? null;
$this->type = $data['type'] ?? null;
$this->embedded = $data['embedded'] ?? false;
}

/**
* sets the attachment file name
*
Expand Down
63 changes: 62 additions & 1 deletion lib/public/Mail/Provider/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
namespace OCP\Mail\Provider;

use JsonSerializable;
use OCP\Json\JsonDeserializable;

/**
* Mail Message Object
*
Expand All @@ -16,7 +19,7 @@
* @since 30.0.0
*
*/
class Message implements \OCP\Mail\Provider\IMessage {
class Message implements IMessage, JsonSerializable, JsonDeserializable {

/**
* initialize the mail message object
Expand All @@ -30,6 +33,64 @@ public function __construct(
) {
}

/**
* export this objects data as an array
*
* @since 33.0.0
*
* @return array representation of this object as an array
*/
public function jsonSerialize(): array {
$data = $this->data;
$data['bodyHtml'] = base64_encode($this->data['bodyHtml'] ?? '');
$data['bodyPlain'] = base64_encode($this->data['bodyPlain'] ?? '');
$data['subject'] = base64_encode($this->data['subject'] ?? '');
return $data;
}

/**
* import this objects data from an array
*
* @since 33.0.0
*
* @param array array representation of this object
*/
public function jsonDeserialize(array $data): void {
$this->data = $data;
// decode encoded fields
$this->data['bodyHtml'] = base64_decode($data['bodyHtml'] ?? '');
$this->data['bodyPlain'] = base64_decode($data['bodyPlain'] ?? '');
$this->data['subject'] = base64_decode($data['subject'] ?? '');
// convert object fields
foreach (['from', 'replyTo'] as $field) {
if (isset($data[$field]) && is_array($data[$field])) {
$address = new Address();
$address->jsonDeserialize($data[$field]);
$this->data[$field] = $address;
} else {
$this->data[$field] = null;
}
}
foreach (['to', 'cc', 'bcc', 'attachments'] as $field) {
$this->data[$field] = [];
if (isset($data[$field]) && is_array($data[$field])) {
foreach ($data[$field] as $item) {
if (is_array($item)) {
if ($field === 'attachments') {
$attachment = new Attachment(null, null, null);
$attachment->jsonDeserialize($item);
$this->data[$field][] = $attachment;
} else {
$address = new Address();
$address->jsonDeserialize($item);
$this->data[$field][] = $address;
}
}
}
}
}
}

/**
* arbitrary unique text string identifying this message
*
Expand Down
8 changes: 8 additions & 0 deletions lib/public/TaskProcessing/EShapeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum EShapeType: int {
case ListOfAudios = 13;
case ListOfVideos = 14;
case ListOfFiles = 15;
Case Array = 20;
Case Object = 21;

/**
* @param mixed $value
Expand Down Expand Up @@ -106,6 +108,12 @@ public function validateInput(mixed $value): void {
if ($this === EShapeType::ListOfFiles && (!is_array($value) || count(array_filter($value, fn ($item) => !is_numeric($item))) > 0)) {
throw new ValidationException('Non-audio list item provided for ListOfFiles slot');
}
if ($this === EShapeType::Array && !is_array($value)) {
throw new ValidationException('Non-array item provided for Array slot');
}
if ($this === EShapeType::Object && !is_object($value)) {
throw new ValidationException('Non-object item provided for Object slot');
}
}

/**
Expand Down
Loading