Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b01cd0a1a | |||
| 88fae64c86 | |||
| 0d6bf36441 | |||
| 09622e08c3 | |||
| 8d2129f00c | |||
| 7f5a0a3792 | |||
| f904b36a53 | |||
| 190f118589 | |||
| b5e15bdefe | |||
| 1896214026 | |||
| 77d145eede | |||
| 17cc703c68 | |||
| 30782ba07f | |||
| c92950dcc1 | |||
| 089c5db4e2 | |||
| 8c767b3481 | |||
| 947a1ec246 | |||
| 5c52ba177e | |||
| 2f0e5d83b7 | |||
| a6d1ba5f10 | |||
| 17d3115374 | |||
| 4a4406c1ed | |||
| 46b2e97d4b | |||
| bcc277eec8 | |||
| 55b9369710 | |||
| aecbd1dc3c | |||
| 284d7fee0e | |||
| 7b79535fd3 | |||
| 9ee1169d82 | |||
| 28e8b886c8 | |||
| 933d40e9dc | |||
| 3309ca594b |
@@ -25,6 +25,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"guzzlehttp/psr7": "^2.0",
|
||||
"php": ">=8.2 <=8.5",
|
||||
"sebastiankrupinski/jmap-client-php": "dev-main"
|
||||
},
|
||||
|
||||
Generated
+235
-50
@@ -4,29 +4,30 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "922dd87cbee28a0587b20aee3c8645bf",
|
||||
"content-hash": "301e594c1dc2f6abe2a152da4e6076aa",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "7.10.0",
|
||||
"version": "7.13.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4"
|
||||
"reference": "a4decaa9745dc567467970e43f183e260cfa51fd"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/b51ac707cfa420b7bfd4e4d5e510ba8008e822b4",
|
||||
"reference": "b51ac707cfa420b7bfd4e4d5e510ba8008e822b4",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/a4decaa9745dc567467970e43f183e260cfa51fd",
|
||||
"reference": "a4decaa9745dc567467970e43f183e260cfa51fd",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/promises": "^2.3",
|
||||
"guzzlehttp/psr7": "^2.8",
|
||||
"guzzlehttp/promises": "^2.5",
|
||||
"guzzlehttp/psr7": "^2.12.3",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/deprecation-contracts": "^2.2 || ^3.0"
|
||||
"symfony/deprecation-contracts": "^2.5 || ^3.0",
|
||||
"symfony/polyfill-php80": "^1.25"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-client-implementation": "1.0"
|
||||
@@ -35,8 +36,9 @@
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-curl": "*",
|
||||
"guzzle/client-integration-tests": "3.0.2",
|
||||
"guzzlehttp/test-server": "^0.6",
|
||||
"php-http/message-factory": "^1.1",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
|
||||
"phpunit/phpunit": "^8.5.52 || ^9.6.34",
|
||||
"psr/log": "^1.1 || ^2.0 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
@@ -114,7 +116,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/guzzle/issues",
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.10.0"
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.13.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -130,28 +132,29 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-08-23T22:36:01+00:00"
|
||||
"time": "2026-06-29T13:31:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "2.3.0",
|
||||
"version": "2.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "481557b130ef3790cf82b713667b43030dc9c957"
|
||||
"reference": "4360e982f87f5f258bf872d094647791db2f4c8e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/481557b130ef3790cf82b713667b43030dc9c957",
|
||||
"reference": "481557b130ef3790cf82b713667b43030dc9c957",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/4360e982f87f5f258bf872d094647791db2f4c8e",
|
||||
"reference": "4360e982f87f5f258bf872d094647791db2f4c8e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"symfony/deprecation-contracts": "^2.5 || ^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.44 || ^9.6.25"
|
||||
"phpunit/phpunit": "^8.5.52 || ^9.6.34"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
@@ -197,7 +200,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/promises/issues",
|
||||
"source": "https://github.com/guzzle/promises/tree/2.3.0"
|
||||
"source": "https://github.com/guzzle/promises/tree/2.5.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -213,27 +216,29 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-08-22T14:34:08+00:00"
|
||||
"time": "2026-06-02T12:23:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "2.8.0",
|
||||
"version": "2.12.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "21dc724a0583619cd1652f673303492272778051"
|
||||
"reference": "7ec62dc3f44aa218487dbed81a9bf9bc647be55d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/21dc724a0583619cd1652f673303492272778051",
|
||||
"reference": "21dc724a0583619cd1652f673303492272778051",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/7ec62dc3f44aa218487dbed81a9bf9bc647be55d",
|
||||
"reference": "7ec62dc3f44aa218487dbed81a9bf9bc647be55d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/http-message": "^1.1 || ^2.0",
|
||||
"ralouphie/getallheaders": "^3.0"
|
||||
"ralouphie/getallheaders": "^3.0",
|
||||
"symfony/deprecation-contracts": "^2.5 || ^3.0",
|
||||
"symfony/polyfill-php80": "^1.25"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-factory-implementation": "1.0",
|
||||
@@ -241,8 +246,9 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"http-interop/http-factory-tests": "0.9.0",
|
||||
"phpunit/phpunit": "^8.5.44 || ^9.6.25"
|
||||
"http-interop/http-factory-tests": "1.1.0",
|
||||
"jshttp/mime-db": "1.54.0.1",
|
||||
"phpunit/phpunit": "^8.5.52 || ^9.6.34"
|
||||
},
|
||||
"suggest": {
|
||||
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
|
||||
@@ -313,7 +319,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/psr7/issues",
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.8.0"
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.12.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -329,7 +335,86 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-08-23T21:21:41+00:00"
|
||||
"time": "2026-06-23T15:21:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-http/discovery",
|
||||
"version": "1.20.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-http/discovery.git",
|
||||
"reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-http/discovery/zipball/82fe4c73ef3363caed49ff8dd1539ba06044910d",
|
||||
"reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.0|^2.0",
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"conflict": {
|
||||
"nyholm/psr7": "<1.0",
|
||||
"zendframework/zend-diactoros": "*"
|
||||
},
|
||||
"provide": {
|
||||
"php-http/async-client-implementation": "*",
|
||||
"php-http/client-implementation": "*",
|
||||
"psr/http-client-implementation": "*",
|
||||
"psr/http-factory-implementation": "*",
|
||||
"psr/http-message-implementation": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^1.0.2|^2.0",
|
||||
"graham-campbell/phpspec-skip-example-extension": "^5.0",
|
||||
"php-http/httplug": "^1.0 || ^2.0",
|
||||
"php-http/message-factory": "^1.0",
|
||||
"phpspec/phpspec": "^5.1 || ^6.1 || ^7.3",
|
||||
"sebastian/comparator": "^3.0.5 || ^4.0.8",
|
||||
"symfony/phpunit-bridge": "^6.4.4 || ^7.0.1"
|
||||
},
|
||||
"type": "composer-plugin",
|
||||
"extra": {
|
||||
"class": "Http\\Discovery\\Composer\\Plugin",
|
||||
"plugin-optional": true
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Http\\Discovery\\": "src/"
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"src/Composer/Plugin.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations",
|
||||
"homepage": "http://php-http.org",
|
||||
"keywords": [
|
||||
"adapter",
|
||||
"client",
|
||||
"discovery",
|
||||
"factory",
|
||||
"http",
|
||||
"message",
|
||||
"psr17",
|
||||
"psr7"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-http/discovery/issues",
|
||||
"source": "https://github.com/php-http/discovery/tree/1.20.0"
|
||||
},
|
||||
"time": "2024-10-02T11:20:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
@@ -541,21 +626,26 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/SebastianKrupinski/jmap-client-php.git",
|
||||
"reference": "bd754c3364a44273682e94a0118a0770aa3b7449"
|
||||
"reference": "720ba6ee0579202e5fedab39847680cc5c7ebf58"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/SebastianKrupinski/jmap-client-php/zipball/bd754c3364a44273682e94a0118a0770aa3b7449",
|
||||
"reference": "bd754c3364a44273682e94a0118a0770aa3b7449",
|
||||
"url": "https://api.github.com/repos/SebastianKrupinski/jmap-client-php/zipball/720ba6ee0579202e5fedab39847680cc5c7ebf58",
|
||||
"reference": "720ba6ee0579202e5fedab39847680cc5c7ebf58",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"php": "^8.0"
|
||||
"php": "^8.0",
|
||||
"php-http/discovery": "^1.19",
|
||||
"psr/http-client": "^1.0",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/http-message": "^1.1 || ^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.89"
|
||||
"friendsofphp/php-cs-fixer": "^3.89",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"phpunit/phpunit": "^11.0"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
@@ -572,10 +662,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test:unit": [
|
||||
"phpunit --testsuite 'Unit Tests'"
|
||||
"./vendor/bin/phpunit --testsuite 'Unit Tests'"
|
||||
],
|
||||
"test:integration": [
|
||||
"phpunit --testsuite 'Integration Tests'"
|
||||
"./vendor/bin/phpunit --testsuite 'Integration Tests'"
|
||||
],
|
||||
"cs:check": [
|
||||
"php-cs-fixer fix --dry-run --diff"
|
||||
@@ -585,7 +675,7 @@
|
||||
]
|
||||
},
|
||||
"license": [
|
||||
"AGL3"
|
||||
"AGPL-3.0-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
@@ -595,29 +685,36 @@
|
||||
"role": "Just another Minion in the cogs of time"
|
||||
}
|
||||
],
|
||||
"description": "JMAP PHP Client",
|
||||
"description": "Type-safe PHP client for JMAP mail, calendar, contacts, files, and tasks APIs",
|
||||
"homepage": "https://github.com/SebastianKrupinski/jmap-client-php",
|
||||
"keywords": [
|
||||
"enum"
|
||||
"api-client",
|
||||
"calendar",
|
||||
"contacts",
|
||||
"email",
|
||||
"files",
|
||||
"jmap",
|
||||
"mail",
|
||||
"tasks"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/SebastianKrupinski/jmap-client-php/tree/main",
|
||||
"issues": "https://github.com/SebastianKrupinski/jmap-client-php/issues"
|
||||
"issues": "https://github.com/SebastianKrupinski/jmap-client-php/issues",
|
||||
"source": "https://github.com/SebastianKrupinski/jmap-client-php"
|
||||
},
|
||||
"time": "2025-11-07T22:31:45+00:00"
|
||||
"time": "2026-06-27T23:55:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"version": "v3.6.0",
|
||||
"version": "v3.7.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
|
||||
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/f3202fa1b5097b0af062dc978b32ecf63404e31d",
|
||||
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -630,7 +727,7 @@
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.6-dev"
|
||||
"dev-main": "3.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@@ -655,7 +752,7 @@
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -666,12 +763,100 @@
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-25T14:21:43+00:00"
|
||||
"time": "2026-06-05T06:23:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.37.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php80.git",
|
||||
"reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dfb55726c3a76ea3b6459fcfda1ec2d80a682411",
|
||||
"reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php80\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Resources/stubs"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php80/tree/v1.37.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-04-10T16:19:22+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
@@ -2471,5 +2656,5 @@
|
||||
"platform-overrides": {
|
||||
"php": "8.2"
|
||||
},
|
||||
"plugin-api-version": "2.9.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
||||
@@ -24,23 +24,23 @@ class EntityProperties extends EntityPropertiesMutableAbstract {
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
if (isset($data['size'])) {
|
||||
$this->data[self::JSON_PROPERTY_SIZE] = (int) $data['size'];
|
||||
$this->data[self::PROPERTY_SIZE] = (int) $data['size'];
|
||||
}
|
||||
|
||||
if (isset($data['label'])) {
|
||||
$this->data[self::JSON_PROPERTY_LABEL] = (string) $data['name'];
|
||||
$this->data[self::PROPERTY_LABEL] = (string) $data['name'];
|
||||
}
|
||||
|
||||
if (isset($data['mime'])) {
|
||||
$this->data[self::JSON_PROPERTY_MIME] = (string) $data['type'];
|
||||
$this->data[self::PROPERTY_MIME] = (string) $data['type'];
|
||||
}
|
||||
|
||||
if (isset($data['format'])) {
|
||||
$this->data[self::JSON_PROPERTY_FORMAT] = null;
|
||||
$this->data[self::PROPERTY_FORMAT] = null;
|
||||
}
|
||||
|
||||
if (isset($data['encoding'])) {
|
||||
$this->data[self::JSON_PROPERTY_ENCODING] = null;
|
||||
$this->data[self::PROPERTY_ENCODING] = null;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -52,8 +52,8 @@ class EntityProperties extends EntityPropertiesMutableAbstract {
|
||||
public function toJmap(): array {
|
||||
|
||||
$parameters = array_filter([
|
||||
'name' => $this->data[self::JSON_PROPERTY_LABEL],
|
||||
'type' => $this->data[self::JSON_PROPERTY_MIME] ?? 'application/octet-stream'
|
||||
'name' => $this->data[self::PROPERTY_LABEL],
|
||||
'type' => $this->data[self::PROPERTY_MIME] ?? 'application/octet-stream'
|
||||
], static fn($value) => $value !== null);
|
||||
|
||||
return $parameters;
|
||||
|
||||
@@ -49,10 +49,10 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInt
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
||||
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL,
|
||||
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities,
|
||||
self::PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
||||
self::PROPERTY_LABEL => self::PROVIDER_LABEL,
|
||||
self::PROPERTY_CAPABILITIES => $this->providerAbilities,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -125,15 +125,15 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter([
|
||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||
self::JSON_PROPERTY_IDENTIFIER => $this->serviceIdentifier,
|
||||
self::JSON_PROPERTY_LABEL => $this->serviceLabel,
|
||||
self::JSON_PROPERTY_ENABLED => $this->serviceEnabled,
|
||||
self::JSON_PROPERTY_CAPABILITIES => $this->serviceAbilities,
|
||||
self::JSON_PROPERTY_LOCATION => $this->location?->jsonSerialize(),
|
||||
self::JSON_PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
|
||||
self::JSON_PROPERTY_AUXILIARY => $this->auxiliary,
|
||||
self::PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||
self::PROPERTY_IDENTIFIER => $this->serviceIdentifier,
|
||||
self::PROPERTY_LABEL => $this->serviceLabel,
|
||||
self::PROPERTY_ENABLED => $this->serviceEnabled,
|
||||
self::PROPERTY_CAPABILITIES => $this->serviceAbilities,
|
||||
self::PROPERTY_LOCATION => $this->location?->jsonSerialize(),
|
||||
self::PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
|
||||
self::PROPERTY_AUXILIARY => $this->auxiliary,
|
||||
], fn($v) => $v !== null);
|
||||
}
|
||||
|
||||
@@ -142,20 +142,20 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
if (isset($data[self::JSON_PROPERTY_LABEL])) {
|
||||
$this->setLabel($data[self::JSON_PROPERTY_LABEL]);
|
||||
if (isset($data[self::PROPERTY_LABEL])) {
|
||||
$this->setLabel($data[self::PROPERTY_LABEL]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]);
|
||||
if (isset($data[self::PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::PROPERTY_ENABLED]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_LOCATION])) {
|
||||
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION]));
|
||||
if (isset($data[self::PROPERTY_LOCATION])) {
|
||||
$this->setLocation($this->freshLocation(null, $data[self::PROPERTY_LOCATION]));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_IDENTITY])) {
|
||||
$this->setIdentity($this->freshIdentity(null, $data[self::JSON_PROPERTY_IDENTITY]));
|
||||
if (isset($data[self::PROPERTY_IDENTITY])) {
|
||||
$this->setIdentity($this->freshIdentity(null, $data[self::PROPERTY_IDENTITY]));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_AUXILIARY]) && is_array($data[self::JSON_PROPERTY_AUXILIARY])) {
|
||||
$this->setAuxiliary($data[self::JSON_PROPERTY_AUXILIARY]);
|
||||
if (isset($data[self::PROPERTY_AUXILIARY]) && is_array($data[self::PROPERTY_AUXILIARY])) {
|
||||
$this->setAuxiliary($data[self::PROPERTY_AUXILIARY]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Mail Attachment Object
|
||||
*
|
||||
* @since 30.0.0
|
||||
*/
|
||||
class MessageAttachment implements MessagePart {
|
||||
protected MessagePart $_meta;
|
||||
protected ?string $_contents = null;
|
||||
|
||||
public function __construct(?MessagePart $meta = null, ?string $contents = null) {
|
||||
// determine if meta data exists
|
||||
// if meta data is missing create new
|
||||
if ($meta === null) {
|
||||
$meta = new MessagePart();
|
||||
$meta->setDisposition('attachment');
|
||||
$meta->setType('application/octet-stream');
|
||||
}
|
||||
$this->setParameters($meta);
|
||||
// determine if attachment contents exists
|
||||
// if contents exists set the contents
|
||||
if ($contents !== null) {
|
||||
$this->setContents($contents);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the attachments parameters
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MessagePart|null $meta collection of all message parameters
|
||||
*
|
||||
* @return self return this object for command chaining
|
||||
*/
|
||||
public function setParameters(?MessagePart $meta): self {
|
||||
|
||||
// replace meta data store
|
||||
$this->_meta = $meta;
|
||||
// return this object for command chaining
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the attachments of this message
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array collection of all message parameters
|
||||
*/
|
||||
public function getParameters(): MessagePart {
|
||||
// evaluate if data store field exists and return value(s) or null otherwise
|
||||
return $this->_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* arbitrary unique text string identifying this message
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string id of this message
|
||||
*/
|
||||
public function id(): string {
|
||||
// return id of message
|
||||
return $this->_meta->getBlobId();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the attachment file name
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @param string $value file name (e.g example.txt)
|
||||
*
|
||||
* @return self return this object for command chaining
|
||||
*/
|
||||
public function setName(string $value): self {
|
||||
$this->_meta->setName($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the attachment file name
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @return string | null returns the attachment file name or null if not set
|
||||
*/
|
||||
public function getName(): ?string {
|
||||
return $this->_meta->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the attachment mime type
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @param string $value mime type (e.g. text/plain)
|
||||
*
|
||||
* @return self return this object for command chaining
|
||||
*/
|
||||
public function setType(string $value): self {
|
||||
$this->_meta->setType($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the attachment mime type
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @return string | null returns the attachment mime type or null if not set
|
||||
*/
|
||||
public function getType(): ?string {
|
||||
return $this->_meta->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the attachment contents (actual data)
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @param string $value binary contents of file
|
||||
*
|
||||
* @return self return this object for command chaining
|
||||
*/
|
||||
public function setContents(string $value): self {
|
||||
$this->_contents = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the attachment contents (actual data)
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @return string | null returns the attachment contents or null if not set
|
||||
*/
|
||||
public function getContents(): ?string {
|
||||
return $this->_contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the embedded status of the attachment
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @param bool $value true - embedded / false - not embedded
|
||||
*
|
||||
* @return self return this object for command chaining
|
||||
*/
|
||||
public function setEmbedded(bool $value): self {
|
||||
if ($value) {
|
||||
$this->_meta->setDisposition('inline');
|
||||
} else {
|
||||
$this->_meta->setDisposition('attachment');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the embedded status of the attachment
|
||||
*
|
||||
* @since 30.0.0
|
||||
*
|
||||
* @return bool embedded status of the attachment
|
||||
*/
|
||||
public function getEmbedded(): bool {
|
||||
if ($this->_meta->getDisposition() === 'inline') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,142 @@ use KTXF\Mail\Object\MessagePropertiesMutableAbstract;
|
||||
*/
|
||||
class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
|
||||
private function buildJmapBodyStructure(array &$bodyValues): ?array {
|
||||
$counter = 0;
|
||||
$body = isset($this->data[static::PROPERTY_BODY]) && is_array($this->data[static::PROPERTY_BODY])
|
||||
? $this->serializeBodyPartForJmap($this->data[static::PROPERTY_BODY], $bodyValues, $counter)
|
||||
: null;
|
||||
|
||||
$attachments = [];
|
||||
if (isset($this->data[static::PROPERTY_ATTACHMENTS]) && is_array($this->data[static::PROPERTY_ATTACHMENTS])) {
|
||||
foreach ($this->data[static::PROPERTY_ATTACHMENTS] as $attachment) {
|
||||
if (!is_array($attachment)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$serialized = $this->serializeBodyPartForJmap($attachment, $bodyValues, $counter);
|
||||
if ($serialized !== null) {
|
||||
$attachments[] = $serialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($body === null) {
|
||||
if ($attachments === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count($attachments) === 1) {
|
||||
return $attachments[0];
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'multipart/mixed',
|
||||
'subParts' => $attachments,
|
||||
];
|
||||
}
|
||||
|
||||
if ($attachments === []) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'multipart/mixed',
|
||||
'subParts' => array_merge([$body], $attachments),
|
||||
];
|
||||
}
|
||||
|
||||
private function serializeBodyPartForJmap(array $part, array &$bodyValues, int &$counter): ?array {
|
||||
$type = isset($part['type']) && is_string($part['type']) && $part['type'] !== ''
|
||||
? strtolower($part['type'])
|
||||
: null;
|
||||
|
||||
if ($type === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$isMultipart = str_starts_with($type, 'multipart/');
|
||||
$serialized = [
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
if (isset($part['name']) && is_string($part['name']) && $part['name'] !== '') {
|
||||
$serialized['name'] = $part['name'];
|
||||
}
|
||||
|
||||
if (isset($part['disposition']) && is_string($part['disposition']) && $part['disposition'] !== '') {
|
||||
$serialized['disposition'] = $part['disposition'];
|
||||
}
|
||||
|
||||
if (isset($part['cid']) && is_string($part['cid']) && $part['cid'] !== '') {
|
||||
$serialized['cid'] = $part['cid'];
|
||||
}
|
||||
|
||||
if (isset($part['language']) && is_array($part['language']) && $part['language'] !== []) {
|
||||
$serialized['language'] = $part['language'];
|
||||
}
|
||||
|
||||
if (isset($part['location']) && is_string($part['location']) && $part['location'] !== '') {
|
||||
$serialized['location'] = $part['location'];
|
||||
}
|
||||
|
||||
if ($isMultipart) {
|
||||
$subParts = [];
|
||||
foreach ($part['subParts'] ?? [] as $subPart) {
|
||||
if (!is_array($subPart)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$serializedSubPart = $this->serializeBodyPartForJmap($subPart, $bodyValues, $counter);
|
||||
if ($serializedSubPart !== null) {
|
||||
$subParts[] = $serializedSubPart;
|
||||
}
|
||||
}
|
||||
|
||||
if ($subParts !== []) {
|
||||
$serialized['subParts'] = $subParts;
|
||||
}
|
||||
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
$blobId = isset($part['blobId']) && is_string($part['blobId']) && $part['blobId'] !== ''
|
||||
? $part['blobId']
|
||||
: null;
|
||||
$content = isset($part['content']) && is_string($part['content']) ? $part['content'] : null;
|
||||
|
||||
if ($blobId !== null) {
|
||||
$serialized['blobId'] = $blobId;
|
||||
|
||||
if (isset($part['charset']) && is_string($part['charset']) && $part['charset'] !== '' && str_starts_with($type, 'text/')) {
|
||||
$serialized['charset'] = $part['charset'];
|
||||
}
|
||||
|
||||
if (isset($part['size']) && is_int($part['size'])) {
|
||||
$serialized['size'] = $part['size'];
|
||||
}
|
||||
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
if ($content !== null && str_starts_with($type, 'text/')) {
|
||||
$partId = isset($part['partId']) && is_string($part['partId']) && $part['partId'] !== ''
|
||||
? $part['partId']
|
||||
: 'part-' . (++$counter);
|
||||
|
||||
$serialized['partId'] = $partId;
|
||||
$bodyValues[$partId] = [
|
||||
'value' => $content,
|
||||
'isEncodingProblem' => false,
|
||||
'isTruncated' => false,
|
||||
];
|
||||
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert JMAP parameters array to mail message properties object
|
||||
*
|
||||
@@ -23,91 +159,91 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
*/
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
if (isset($parameters['messageId'])) {
|
||||
$this->data['urid'] = $parameters['messageId'][0];
|
||||
}
|
||||
if (isset($parameters['size'])) {
|
||||
$this->data['size'] = $parameters['size'];
|
||||
$this->data[static::PROPERTY_SIZE] = $parameters['size'];
|
||||
}
|
||||
|
||||
if (isset($parameters['headers']) && is_array($parameters['headers'])) {
|
||||
$this->data[static::PROPERTY_HEADERS] = $parameters['headers'];
|
||||
}
|
||||
|
||||
if (isset($parameters['messageId'])) {
|
||||
$this->data[static::PROPERTY_URID] = $parameters['messageId'][0];
|
||||
}
|
||||
|
||||
if (isset($parameters['receivedAt'])) {
|
||||
$this->data['received'] = $parameters['receivedAt'];
|
||||
$this->data[static::PROPERTY_RECEIVED] = $parameters['receivedAt'];
|
||||
}
|
||||
|
||||
if (isset($parameters['sentAt'])) {
|
||||
$this->data['date'] = $parameters['sentAt'];
|
||||
$this->data[static::PROPERTY_SENT] = $parameters['sentAt'];
|
||||
}
|
||||
|
||||
if (isset($parameters['inReplyTo'])) {
|
||||
$this->data['inReplyTo'] = $parameters['inReplyTo'];
|
||||
$this->data[static::PROPERTY_IN_REPLY_TO] = $parameters['inReplyTo'];
|
||||
}
|
||||
|
||||
if (isset($parameters['references'])) {
|
||||
$this->data['references'] = is_array($parameters['references']) ? $parameters['references'] : [];
|
||||
}
|
||||
if (isset($parameters['subject'])) {
|
||||
$this->data['subject'] = $parameters['subject'];
|
||||
}
|
||||
if (isset($parameters['preview'])) {
|
||||
$this->data['snippet'] = $parameters['preview'];
|
||||
$this->data[static::PROPERTY_REFERENCES] = is_array($parameters['references']) ? $parameters['references'] : [];
|
||||
}
|
||||
|
||||
if (isset($parameters['sender'])) {
|
||||
$this->data['sender'] = $parameters['sender'];
|
||||
$this->data[static::PROPERTY_SENDER] = $parameters['sender'];
|
||||
}
|
||||
|
||||
if (isset($parameters['from']) && is_array($parameters['from']) && !empty($parameters['from'])) {
|
||||
$this->data['from'] = [
|
||||
$this->data[static::PROPERTY_FROM] = [
|
||||
'address' => $parameters['from'][0]['email'] ?? '',
|
||||
'label' => $parameters['from'][0]['name'] ?? null
|
||||
];
|
||||
}
|
||||
if (isset($parameters['to']) && is_array($parameters['to'])) {
|
||||
$this->data['to'] = [];
|
||||
foreach ($parameters['to'] as $addr) {
|
||||
$this->data['to'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
if (isset($parameters['cc']) && is_array($parameters['cc'])) {
|
||||
$this->data['cc'] = [];
|
||||
foreach ($parameters['cc'] as $addr) {
|
||||
$this->data['cc'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
if (isset($parameters['bcc']) && is_array($parameters['bcc'])) {
|
||||
$this->data['bcc'] = [];
|
||||
foreach ($parameters['bcc'] as $addr) {
|
||||
$this->data['bcc'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['replyTo']) && is_array($parameters['replyTo'])) {
|
||||
$this->data['replyTo'] = [];
|
||||
$this->data[static::PROPERTY_REPLY_TO] = [];
|
||||
foreach ($parameters['replyTo'] as $addr) {
|
||||
$this->data['replyTo'][] = [
|
||||
$this->data[static::PROPERTY_REPLY_TO][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
if (isset($parameters['keywords']) && is_array($parameters['keywords'])) {
|
||||
$this->data['flags'] = [];
|
||||
foreach ($parameters['keywords'] as $keyword => $value) {
|
||||
$flag = match($keyword) {
|
||||
'$seen' => 'read',
|
||||
'$flagged' => 'flagged',
|
||||
'$answered' => 'answered',
|
||||
'$draft' => 'draft',
|
||||
'$deleted' => 'deleted',
|
||||
default => $keyword
|
||||
};
|
||||
$this->data['flags'][$flag] = $value;
|
||||
|
||||
if (isset($parameters['to']) && is_array($parameters['to'])) {
|
||||
$this->data[static::PROPERTY_TO] = [];
|
||||
foreach ($parameters['to'] as $addr) {
|
||||
$this->data[static::PROPERTY_TO][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['cc']) && is_array($parameters['cc'])) {
|
||||
$this->data[static::PROPERTY_CC] = [];
|
||||
foreach ($parameters['cc'] as $addr) {
|
||||
$this->data[static::PROPERTY_CC][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['bcc']) && is_array($parameters['bcc'])) {
|
||||
$this->data[static::PROPERTY_BCC] = [];
|
||||
foreach ($parameters['bcc'] as $addr) {
|
||||
$this->data[static::PROPERTY_BCC][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['subject'])) {
|
||||
$this->data[static::PROPERTY_SUBJECT] = $parameters['subject'];
|
||||
}
|
||||
|
||||
if (isset($parameters['bodyStructure'])) {
|
||||
$this->data['body'] = $parameters['bodyStructure'];
|
||||
$this->data[static::PROPERTY_BODY] = $parameters['bodyStructure'];
|
||||
// Recursively add content from bodyValues to matching parts
|
||||
if (isset($parameters['bodyValues']) && is_array($parameters['bodyValues'])) {
|
||||
$addContentToParts = function(&$structure, $bodyValues) use (&$addContentToParts) {
|
||||
@@ -123,14 +259,27 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
}
|
||||
};
|
||||
|
||||
$addContentToParts($this->data['body'], $parameters['bodyValues']);
|
||||
$addContentToParts($this->data[static::PROPERTY_BODY], $parameters['bodyValues']);
|
||||
}
|
||||
}
|
||||
if (isset($parameters['headers']) && is_array($parameters['headers'])) {
|
||||
$this->data['headers'] = $parameters['headers'];
|
||||
}
|
||||
|
||||
if (isset($parameters['attachments'])) {
|
||||
$this->data['attachments'] = $parameters['attachments'];
|
||||
$this->data[static::PROPERTY_ATTACHMENTS] = $parameters['attachments'];
|
||||
}
|
||||
|
||||
if (isset($parameters['keywords']) && is_array($parameters['keywords'])) {
|
||||
$this->data[static::PROPERTY_FLAGS] = [];
|
||||
foreach ($parameters['keywords'] as $keyword => $value) {
|
||||
$flag = match($keyword) {
|
||||
'$seen' => 'seen',
|
||||
'$flagged' => 'flagged',
|
||||
'$answered' => 'answered',
|
||||
'$draft' => 'draft',
|
||||
'$deleted' => 'deleted',
|
||||
default => $keyword
|
||||
};
|
||||
$this->data[static::PROPERTY_FLAGS][$flag] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -149,11 +298,11 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
if (isset($this->data['size'])) {
|
||||
$parameters['size'] = $this->data['size'];
|
||||
}
|
||||
if (isset($this->data['receivedDate'])) {
|
||||
$parameters['receivedAt'] = $this->data['receivedDate'];
|
||||
if (isset($this->data['received'])) {
|
||||
$parameters['receivedAt'] = $this->data['received'];
|
||||
}
|
||||
if (isset($this->data['date'])) {
|
||||
$parameters['sentAt'] = $this->data['date'];
|
||||
if (isset($this->data['sent'])) {
|
||||
$parameters['sentAt'] = $this->data['sent'];
|
||||
}
|
||||
if (isset($this->data['inReplyTo'])) {
|
||||
$parameters['inReplyTo'] = $this->data['inReplyTo'];
|
||||
@@ -216,7 +365,7 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
$parameters['keywords'] = [];
|
||||
foreach ($this->data['flags'] as $flag => $value) {
|
||||
$keyword = match($flag) {
|
||||
'read' => '$seen',
|
||||
'seen' => '$seen',
|
||||
'flagged' => '$flagged',
|
||||
'answered' => '$answered',
|
||||
'draft' => '$draft',
|
||||
@@ -226,37 +375,17 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
$parameters['keywords'][$keyword] = $value;
|
||||
}
|
||||
}
|
||||
if (isset($this->data['bodyStructure'])) {
|
||||
$parameters['bodyStructure'] = $this->data['bodyStructure'];
|
||||
}
|
||||
if (isset($this->data['body'])) {
|
||||
$parameters['bodyValues'] = [];
|
||||
|
||||
if (isset($this->data['body']['text']['content'])) {
|
||||
$parameters['bodyValues']['0'] = [
|
||||
'value' => $this->data['body']['text']['content'],
|
||||
'isEncodingProblem' => false,
|
||||
'isTruncated' => false
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->data['body']['html']['content'])) {
|
||||
$parameters['bodyValues']['1'] = [
|
||||
'value' => $this->data['body']['html']['content'],
|
||||
'isEncodingProblem' => false,
|
||||
'isTruncated' => false
|
||||
];
|
||||
}
|
||||
|
||||
$bodyValues = [];
|
||||
$bodyStructure = $this->buildJmapBodyStructure($bodyValues);
|
||||
if ($bodyStructure !== null) {
|
||||
$parameters['bodyStructure'] = $bodyStructure;
|
||||
$parameters['bodyValues'] = $bodyValues;
|
||||
}
|
||||
|
||||
if (isset($this->data['headers'])) {
|
||||
$parameters['headers'] = $this->data['headers'];
|
||||
}
|
||||
if (isset($this->data['attachments'])) {
|
||||
$parameters['attachments'] = $this->data['attachments'];
|
||||
$parameters['hasAttachment'] = !empty($this->data['attachments']);
|
||||
} else {
|
||||
$parameters['hasAttachment'] = false;
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
@@ -14,19 +14,16 @@ use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceMutateInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceTestInterface;
|
||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceMutateInterface;
|
||||
use KTXM\ProviderJmapc\Service\Discovery;
|
||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
||||
use KTXM\ProviderJmapc\Stores\ServiceStore;
|
||||
|
||||
/**
|
||||
* JMAP Mail Provider
|
||||
*/
|
||||
class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
||||
class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
||||
{
|
||||
|
||||
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
|
||||
protected const PROVIDER_IDENTIFIER = 'jmap';
|
||||
protected const PROVIDER_LABEL = 'JMAP Mail Provider';
|
||||
protected const PROVIDER_DESCRIPTION = 'Provides mail services via JMAP protocol (RFC 8620)';
|
||||
@@ -49,10 +46,10 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
||||
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL,
|
||||
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities,
|
||||
self::PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
||||
self::PROPERTY_LABEL => self::PROVIDER_LABEL,
|
||||
self::PROPERTY_CAPABILITIES => $this->providerAbilities,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -155,7 +152,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
||||
}
|
||||
|
||||
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
||||
return (string) $updated['id'];
|
||||
return (string) $updated['sid'];
|
||||
}
|
||||
|
||||
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
||||
@@ -180,7 +177,8 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
||||
return $discovery->discover($identity, $location, $secret, $verifySSL);
|
||||
}
|
||||
|
||||
public function serviceTest(ServiceBaseInterface $service, array $options = []): array {
|
||||
public function serviceTest(ServiceBaseInterface|ServiceMutableInterface $service, array $options = []): array
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
@@ -199,8 +197,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
||||
. ' (Account ID: ' . ($session->username() ?? 'N/A') . ')'
|
||||
. ' (Latency: ' . $latency . ' ms)',
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
$latency = round((microtime(true) - $startTime) * 1000);
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Test failed: ' . $e->getMessage(),
|
||||
|
||||
+582
-152
@@ -12,14 +12,18 @@ namespace KTXM\ProviderJmapc\Providers\Mail;
|
||||
use Generator;
|
||||
use KTXF\Mail\Collection\CollectionBaseInterface;
|
||||
use KTXF\Mail\Collection\CollectionRoles;
|
||||
use KTXF\Mail\Collection\CollectionMutableInterface;
|
||||
use KTXF\Mail\Collection\CollectionPropertiesBaseInterface;
|
||||
use KTXF\Mail\Object\Address;
|
||||
use KTXF\Mail\Object\AddressInterface;
|
||||
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceConfigurableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntityMutableInterface;
|
||||
use KTXF\Mail\Service\ServiceEntitySubmitInterface;
|
||||
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||
use KTXF\Mail\Submission\EntitySubmitResult;
|
||||
use KTXF\Resource\BinaryResource;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Delta\Delta;
|
||||
@@ -27,6 +31,7 @@ use KTXF\Resource\Filter\Filter;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifierInterface;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Range\Range;
|
||||
use KTXF\Resource\Range\RangeType;
|
||||
@@ -37,9 +42,8 @@ use KTXM\ProviderJmapc\Providers\ServiceLocation;
|
||||
use KTXM\ProviderJmapc\Service\Remote\RemoteMailService;
|
||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
||||
|
||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface
|
||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface, ServiceEntityMutableInterface, ServiceEntitySubmitInterface
|
||||
{
|
||||
public const JSON_TYPE = ServiceBaseInterface::JSON_TYPE;
|
||||
|
||||
private const PROVIDER_IDENTIFIER = 'jmap';
|
||||
|
||||
@@ -48,8 +52,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
private ?string $serviceIdentifier = null;
|
||||
private ?string $serviceLabel = null;
|
||||
private bool $serviceEnabled = false;
|
||||
private bool $serviceDebug = false;
|
||||
private string $primaryAddress = '';
|
||||
private array $primaryAddress = [];
|
||||
private array $secondaryAddresses = [];
|
||||
private ?ServiceLocation $location = null;
|
||||
private ?ServiceIdentityBasic $identity = null;
|
||||
@@ -58,18 +61,20 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
private array $serviceAbilities = [
|
||||
self::CAPABILITY_COLLECTION_LIST => true,
|
||||
self::CAPABILITY_COLLECTION_LIST_FILTER => [
|
||||
self::CAPABILITY_COLLECTION_FILTER_LABEL => 's:100:256:256',
|
||||
self::CAPABILITY_COLLECTION_FILTER_ROLE => 's:100:256:256',
|
||||
self::CAPABILITY_COLLECTION_FILTER_LABEL => 's:128:256:256',
|
||||
self::CAPABILITY_COLLECTION_FILTER_ROLE => 's:32:1:1',
|
||||
self::CAPABILITY_COLLECTION_FILTER_SUBSCRIBED => 'b:0:1:1',
|
||||
],
|
||||
self::CAPABILITY_COLLECTION_LIST_SORT => [
|
||||
self::CAPABILITY_COLLECTION_SORT_LABEL,
|
||||
self::CAPABILITY_COLLECTION_SORT_RANK,
|
||||
],
|
||||
self::CAPABILITY_COLLECTION_EXTANT => true,
|
||||
self::CAPABILITY_COLLECTION_FETCH => true,
|
||||
self::CAPABILITY_COLLECTION_EXTANT => true,
|
||||
self::CAPABILITY_COLLECTION_CREATE => true,
|
||||
self::CAPABILITY_COLLECTION_UPDATE => true,
|
||||
self::CAPABILITY_COLLECTION_DELETE => true,
|
||||
self::CAPABILITY_COLLECTION_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_LIST => true,
|
||||
self::CAPABILITY_ENTITY_LIST_FILTER => [
|
||||
self::CAPABILITY_ENTITY_FILTER_ALL => 's:200:256:256',
|
||||
@@ -95,11 +100,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
self::CAPABILITY_ENTITY_LIST_RANGE => [
|
||||
'tally' => ['absolute', 'relative']
|
||||
],
|
||||
self::CAPABILITY_ENTITY_DELTA => true,
|
||||
self::CAPABILITY_ENTITY_EXTANT => true,
|
||||
self::CAPABILITY_ENTITY_FETCH => true,
|
||||
//self::CAPABILITY_ENTITY_DELETE => true,
|
||||
//self::CAPABILITY_ENTITY_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_EXTANT => true,
|
||||
self::CAPABILITY_ENTITY_CREATE => false,
|
||||
self::CAPABILITY_ENTITY_MODIFY => false,
|
||||
self::CAPABILITY_ENTITY_PATCH => true,
|
||||
self::CAPABILITY_ENTITY_DELETE => true,
|
||||
self::CAPABILITY_ENTITY_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_COPY => false,
|
||||
self::CAPABILITY_ENTITY_SUBMIT_FRESH => true,
|
||||
self::CAPABILITY_ENTITY_SUBMIT_DRAFT => true,
|
||||
'EntityTransmit' => true,
|
||||
];
|
||||
|
||||
private readonly RemoteMailService $mailService;
|
||||
@@ -107,21 +118,22 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
public function __construct(
|
||||
) {}
|
||||
|
||||
private function initialize(): void {
|
||||
private function initialize(): void
|
||||
{
|
||||
if (!isset($this->mailService)) {
|
||||
$client = RemoteService::freshClient($this);
|
||||
$this->mailService = RemoteService::mailService($client);
|
||||
}
|
||||
}
|
||||
|
||||
public function toStore(): array {
|
||||
public function toStore(): array
|
||||
{
|
||||
return array_filter([
|
||||
'tid' => $this->serviceTenantId,
|
||||
'uid' => $this->serviceUserId,
|
||||
'sid' => $this->serviceIdentifier,
|
||||
'label' => $this->serviceLabel,
|
||||
'enabled' => $this->serviceEnabled,
|
||||
'debug' => $this->serviceDebug,
|
||||
'label' => $this->serviceLabel,
|
||||
'primaryAddress' => $this->primaryAddress,
|
||||
'secondaryAddresses' => $this->secondaryAddresses,
|
||||
'location' => $this->location?->toStore(),
|
||||
@@ -130,13 +142,13 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
], fn($v) => $v !== null);
|
||||
}
|
||||
|
||||
public function fromStore(array $data): static {
|
||||
public function fromStore(array $data): static
|
||||
{
|
||||
$this->serviceTenantId = $data['tid'] ?? null;
|
||||
$this->serviceUserId = $data['uid'] ?? null;
|
||||
$this->serviceIdentifier = $data['sid'];
|
||||
$this->serviceLabel = $data['label'] ?? '';
|
||||
$this->serviceEnabled = $data['enabled'] ?? false;
|
||||
$this->serviceDebug = $data['debug'] ?? false;
|
||||
|
||||
if (isset($data['primaryAddress'])) {
|
||||
$this->primaryAddress = $data['primaryAddress'];
|
||||
@@ -159,50 +171,52 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return array_filter([
|
||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||
self::JSON_PROPERTY_IDENTIFIER => $this->serviceIdentifier,
|
||||
self::JSON_PROPERTY_LABEL => $this->serviceLabel,
|
||||
self::JSON_PROPERTY_ENABLED => $this->serviceEnabled,
|
||||
self::JSON_PROPERTY_CAPABILITIES => $this->serviceAbilities,
|
||||
self::JSON_PROPERTY_PRIMARY_ADDRESS => $this->primaryAddress,
|
||||
self::JSON_PROPERTY_SECONDARY_ADDRESSES => $this->secondaryAddresses,
|
||||
self::JSON_PROPERTY_LOCATION => $this->location?->jsonSerialize(),
|
||||
self::JSON_PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
|
||||
self::JSON_PROPERTY_AUXILIARY => $this->auxiliary,
|
||||
self::PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||
self::PROPERTY_IDENTIFIER => $this->serviceIdentifier,
|
||||
self::PROPERTY_LABEL => $this->serviceLabel,
|
||||
self::PROPERTY_ENABLED => $this->serviceEnabled,
|
||||
self::PROPERTY_CAPABILITIES => $this->serviceAbilities,
|
||||
self::PROPERTY_PRIMARY_ADDRESS => $this->primaryAddress,
|
||||
self::PROPERTY_SECONDARY_ADDRESSES => $this->secondaryAddresses,
|
||||
self::PROPERTY_LOCATION => $this->location?->jsonSerialize(),
|
||||
self::PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
|
||||
self::PROPERTY_AUXILIARY => $this->auxiliary,
|
||||
], fn($v) => $v !== null);
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data, bool $delta = false): static {
|
||||
public function jsonDeserialize(array|string $data, bool $delta = false): static
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
if (isset($data[self::JSON_PROPERTY_LABEL])) {
|
||||
$this->setLabel($data[self::JSON_PROPERTY_LABEL]);
|
||||
if (isset($data[self::PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::PROPERTY_ENABLED]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]);
|
||||
if (isset($data[self::PROPERTY_LABEL])) {
|
||||
$this->setLabel($data[self::PROPERTY_LABEL]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_LOCATION])) {
|
||||
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION]));
|
||||
if (isset($data[self::PROPERTY_LOCATION])) {
|
||||
$this->setLocation($this->freshLocation(null, $data[self::PROPERTY_LOCATION]));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_IDENTITY])) {
|
||||
$this->setIdentity($this->freshIdentity(null, $data[self::JSON_PROPERTY_IDENTITY]));
|
||||
if (isset($data[self::PROPERTY_IDENTITY])) {
|
||||
$this->setIdentity($this->freshIdentity(null, $data[self::PROPERTY_IDENTITY]));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_PRIMARY_ADDRESS]) && is_string($data[self::JSON_PROPERTY_PRIMARY_ADDRESS])) {
|
||||
$this->setPrimaryAddress(new Address($data[self::JSON_PROPERTY_PRIMARY_ADDRESS]));
|
||||
if (isset($data[self::PROPERTY_PRIMARY_ADDRESS]) && is_string($data[self::PROPERTY_PRIMARY_ADDRESS])) {
|
||||
$this->setPrimaryAddress(new Address($data[self::PROPERTY_PRIMARY_ADDRESS]));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_SECONDARY_ADDRESSES]) && is_array($data[self::JSON_PROPERTY_SECONDARY_ADDRESSES])) {
|
||||
if (isset($data[self::PROPERTY_SECONDARY_ADDRESSES]) && is_array($data[self::PROPERTY_SECONDARY_ADDRESSES])) {
|
||||
$this->setSecondaryAddresses(array_map(
|
||||
fn($addr) => new Address(is_array($addr) ? ($addr['address'] ?? $addr) : $addr),
|
||||
$data[self::JSON_PROPERTY_SECONDARY_ADDRESSES]
|
||||
$data[self::PROPERTY_SECONDARY_ADDRESSES]
|
||||
));
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_AUXILIARY]) && is_array($data[self::JSON_PROPERTY_AUXILIARY])) {
|
||||
$this->setAuxiliary($data[self::JSON_PROPERTY_AUXILIARY]);
|
||||
if (isset($data[self::PROPERTY_AUXILIARY]) && is_array($data[self::PROPERTY_AUXILIARY])) {
|
||||
$this->setAuxiliary($data[self::PROPERTY_AUXILIARY]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -213,7 +227,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return isset($this->serviceAbilities[$value]);
|
||||
}
|
||||
|
||||
public function capabilities(): array {
|
||||
public function capabilities(): array
|
||||
{
|
||||
return $this->serviceAbilities;
|
||||
}
|
||||
|
||||
@@ -251,41 +266,47 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function getPrimaryAddress(): AddressInterface
|
||||
{
|
||||
return new Address($this->primaryAddress);
|
||||
return Address::fromArray($this->primaryAddress);
|
||||
}
|
||||
|
||||
public function setPrimaryAddress(AddressInterface $value): static
|
||||
{
|
||||
$this->primaryAddress = $value->getAddress();
|
||||
$this->primaryAddress = $value->toArray();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSecondaryAddresses(): array
|
||||
{
|
||||
return $this->secondaryAddresses;
|
||||
return array_map(
|
||||
fn($addr) => $addr instanceof AddressInterface ? $addr : Address::fromArray(is_array($addr) ? $addr : ['address' => (string) $addr])
|
||||
, $this->secondaryAddresses);
|
||||
}
|
||||
|
||||
public function setSecondaryAddresses(array $addresses): static
|
||||
{
|
||||
$this->secondaryAddresses = $addresses;
|
||||
$this->secondaryAddresses = array_map(
|
||||
fn($addr) => $addr instanceof AddressInterface ? $addr : Address::fromArray(is_array($addr) ? $addr : ['address' => (string) $addr]),
|
||||
$addresses
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasAddress(string $address): bool
|
||||
{
|
||||
$address = strtolower(trim($address));
|
||||
|
||||
if ($this->primaryAddress && strtolower($this->primaryAddress) === $address) {
|
||||
|
||||
if ($this->primaryAddress && strtolower($this->primaryAddress['address'] ?? '') === $address) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->secondaryAddresses as $secondaryAddress) {
|
||||
if (strtolower($secondaryAddress->getAddress()) === $address) {
|
||||
foreach ($this->secondaryAddresses as $secondary) {
|
||||
$secondaryAddr = $secondary instanceof AddressInterface ? $secondary->getAddress() : (string) $secondary;
|
||||
if (strtolower($secondaryAddr) === $address) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function getLocation(): ServiceLocation
|
||||
@@ -326,12 +347,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function getDebug(): bool
|
||||
{
|
||||
return $this->serviceDebug;
|
||||
return ($this->auxiliary['debug'] ?? false) === true;
|
||||
}
|
||||
|
||||
public function setDebug(bool $debug): static
|
||||
{
|
||||
$this->serviceDebug = $debug;
|
||||
$this->auxiliary['debug'] = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -346,8 +367,6 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Collection operations
|
||||
|
||||
public function collectionList(string|int|null $location, ?IFilter $filter = null, ?ISort $sort = null): array
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -375,6 +394,22 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []);
|
||||
}
|
||||
|
||||
public function collectionFetch(string|int $identifier): ?CollectionResource
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$mailbox = $this->mailService->collectionFetch($identifier);
|
||||
|
||||
if (!is_array($mailbox) || !isset($mailbox['id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$collection = $this->collectionFresh();
|
||||
$collection->fromJmap($mailbox);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function collectionExtant(string|int ...$identifiers): array
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -382,82 +417,109 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this->mailService->collectionExtant(...$identifiers);
|
||||
}
|
||||
|
||||
public function collectionFetch(string|int $identifier): ?CollectionBaseInterface
|
||||
public function collectionFresh(): CollectionResource
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$collection = $this->mailService->collectionFetch($identifier);
|
||||
|
||||
if (is_array($collection) && isset($collection['id'])) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($collection);
|
||||
$collection = $object;
|
||||
}
|
||||
|
||||
return $collection;
|
||||
return new CollectionResource($this->provider(), $this->identifier());
|
||||
}
|
||||
|
||||
public function collectionFresh(): CollectionMutableInterface
|
||||
{
|
||||
return new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
}
|
||||
|
||||
public function collectionCreate(string|int|null $location, CollectionMutableInterface $collection, array $options = []): CollectionBaseInterface
|
||||
public function collectionCreate(CollectionIdentifier|null $target, CollectionPropertiesBaseInterface $properties, array $options = []): CollectionBaseInterface
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
if ($collection instanceof CollectionResource === false) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->jsonDeserialize($collection->jsonSerialize());
|
||||
$collection = $object;
|
||||
if ($properties instanceof CollectionProperties === false) {
|
||||
$native = new CollectionProperties([]);
|
||||
$native->jsonDeserialize($properties->jsonSerialize());
|
||||
} else {
|
||||
$native = $properties;
|
||||
}
|
||||
|
||||
$collection = $collection->toJmap();
|
||||
$collection = $this->mailService->collectionCreate($location, $collection, $options);
|
||||
$collection = $native->toJmap();
|
||||
$collection = $this->mailService->collectionCreate($target?->collection(), $collection, $options);
|
||||
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object = $this->collectionFresh();
|
||||
$object->fromJmap($collection);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function collectionUpdate(string|int $identifier, CollectionMutableInterface $collection): CollectionBaseInterface
|
||||
public function collectionUpdate(CollectionIdentifier $target, CollectionPropertiesBaseInterface $properties): CollectionBaseInterface
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
if ($collection instanceof CollectionResource === false) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->jsonDeserialize($collection->jsonSerialize());
|
||||
$collection = $object;
|
||||
if ($properties instanceof CollectionProperties === false) {
|
||||
$native = new CollectionProperties([]);
|
||||
$native->jsonDeserialize($properties->jsonSerialize());
|
||||
} else {
|
||||
$native = $properties;
|
||||
}
|
||||
|
||||
$collection = $collection->toJmap();
|
||||
$collection = $this->mailService->collectionModify($identifier, $collection);
|
||||
$collection = $native->toJmap();
|
||||
$collection = $this->mailService->collectionModify($target->collection(), $collection);
|
||||
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object = $this->collectionFresh();
|
||||
$object->fromJmap($collection);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function collectionDelete(string|int $identifier, bool $force = false, bool $recursive = false): bool
|
||||
public function collectionDelete(CollectionIdentifier $target, bool $force = false): CollectionBaseInterface | true
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
return $this->mailService->collectionDestroy($identifier, $force, $recursive) !== null;
|
||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
||||
|
||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||
}
|
||||
|
||||
$deleteTargetIdentifier = null;
|
||||
if ($deleteMode === 'soft') {
|
||||
$deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
|
||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
|
||||
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
|
||||
if ($deleteTargetIdentifier === null) {
|
||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||
}
|
||||
}
|
||||
|
||||
// we need to determine if the folder being deleted is already in the trash
|
||||
if (str_starts_with((string) $target->collection(), (string) $deleteTargetIdentifier?->collection())) {
|
||||
// if so, we should hard delete instead of moving to avoid duplicates in the trash
|
||||
$deleteMode = 'hard';
|
||||
}
|
||||
|
||||
$result = match ($deleteMode) {
|
||||
'soft' => $this->collectionMove($deleteTargetIdentifier, $target),
|
||||
'hard' => $this->mailService->collectionDestroy($target->collection(), $force),
|
||||
};
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function collectionMove(string|int $identifier, string|int|null $targetLocation): CollectionBaseInterface
|
||||
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
|
||||
{
|
||||
// TODO: Implement collection move
|
||||
$this->initialize();
|
||||
$collection = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
|
||||
$sourceMailbox = $this->mailService->collectionFetch((string) $source->collection());
|
||||
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
||||
if ($sourceMailbox === null) {
|
||||
throw new \RuntimeException('Source collection not found for move operation');
|
||||
}
|
||||
if ($targetMailbox === null) {
|
||||
throw new \RuntimeException('Target collection not found for move operation');
|
||||
}
|
||||
|
||||
$mutation['parentId'] = $targetMailbox['id'];
|
||||
$mutation = $this->mailService->collectionModify($sourceMailbox['id'], $mutation);
|
||||
$mutation = array_merge($sourceMailbox, $mutation);
|
||||
|
||||
$collection = $this->collectionFresh();
|
||||
$collection->fromJmap($mutation);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
// Entity operations
|
||||
|
||||
public function entityList(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
||||
public function entityListBulk(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
@@ -466,9 +528,9 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
$list = [];
|
||||
foreach ($result['list'] as $index => $entry) {
|
||||
if (is_array($entry) && isset($entry['id'])) {
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object = $this->entityFresh();
|
||||
$object->fromJmap($entry);
|
||||
$list[$object->identifier()] = $object;
|
||||
$list[$object->urn()] = $object;
|
||||
}
|
||||
unset($result['list'][$index]);
|
||||
}
|
||||
@@ -478,17 +540,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function entityListStream(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$result = $this->mailService->entityList($collection, $filter, $sort, $range, $properties);
|
||||
|
||||
foreach ($result['list'] as $index => $entry) {
|
||||
if (is_array($entry) && isset($entry['id'])) {
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($entry);
|
||||
yield $object;
|
||||
}
|
||||
unset($result['list'][$index]);
|
||||
foreach ($this->entityListBulk($collection, $filter, $sort, $range, $properties) as $urn => $entity) {
|
||||
yield $urn => $entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,6 +560,45 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return new Range();
|
||||
}
|
||||
|
||||
public function entityFetchBulk(EntityIdentifierInterface ...$identifiers): array
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
|
||||
$entities = $this->mailService->entityFetch(...$ids);
|
||||
|
||||
$list = [];
|
||||
foreach ($entities as $entity) {
|
||||
if (is_array($entity) && isset($entity['id'])) {
|
||||
$object = $this->entityFresh();
|
||||
$object->fromJmap($entity);
|
||||
$list[$object->urn()] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityFetchStream(EntityIdentifierInterface ...$identifiers): Generator
|
||||
{
|
||||
foreach ($this->entityFetchBulk(...$identifiers) as $urn => $entity) {
|
||||
yield $urn => $entity;
|
||||
}
|
||||
}
|
||||
|
||||
public function entityDownload(EntityIdentifierInterface $target, array|null $part): BinaryResource
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$blobId = isset($part['blobId']) ? (string) $part['blobId'] : null;
|
||||
|
||||
return $this->mailService->entityDownload($target->entity(), $blobId);
|
||||
}
|
||||
|
||||
public function entityDelta(string|int $collection, string $signature, string $detail = 'ids'): Delta
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -521,53 +613,158 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this->mailService->entityExtant(...$identifiers);
|
||||
}
|
||||
|
||||
public function entityFetch(string|int $collection, string|int ...$identifiers): array
|
||||
public function entityFresh(): EntityResource
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$entities = $this->mailService->entityFetch(...$identifiers);
|
||||
|
||||
foreach ($entities as &$entity) {
|
||||
if (is_array($entity) && isset($entity['id'])) {
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($entity);
|
||||
$entity = $object;
|
||||
}
|
||||
}
|
||||
|
||||
return $entities;
|
||||
return new EntityResource($this->provider(), $this->identifier());
|
||||
}
|
||||
|
||||
public function entityDelete(EntityIdentifier ...$identifiers): array
|
||||
public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource
|
||||
{
|
||||
// TODO: Implement entity create
|
||||
return $this->entityFresh();
|
||||
}
|
||||
|
||||
public function entityModify(EntityIdentifier $identifier, MessagePropertiesMutableInterface $properties): EntityResource
|
||||
{
|
||||
// TODO: Implement entity modify
|
||||
return $this->entityFresh();
|
||||
}
|
||||
|
||||
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
|
||||
{
|
||||
// validate identifiers and construct ID list
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
$targets = $this->mapEntities(...$targets);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$deleteMode = strtolower(trim((string) ($this->getAuxiliary()['deleteMode'] ?? 'soft')));
|
||||
if ($deleteMode === 'soft') {
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', 'trash');
|
||||
$targets = $this->collectionList(null, $filter);
|
||||
$patch = $this->mailService->entityFresh();
|
||||
$flags = $properties->getFlags();
|
||||
foreach ($flags as $flag => $value) {
|
||||
// translate canonical flag names to JMAP keywords
|
||||
$keyword = match($flag) {
|
||||
'seen' => '$seen',
|
||||
'flagged' => '$flagged',
|
||||
'answered' => '$answered',
|
||||
'draft' => '$draft',
|
||||
'deleted' => '$deleted',
|
||||
default => $flag
|
||||
};
|
||||
$patch->keyword($keyword, $value);
|
||||
}
|
||||
|
||||
if (empty($targets)) {
|
||||
throw new \RuntimeException('No trash collection found for soft delete');
|
||||
$dispositions = $this->mailService->entityPatch($patch, ...array_keys($targets));
|
||||
|
||||
$list = [];
|
||||
foreach ($targets as $target) {
|
||||
$entityId = $target->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->mailService->entityMove(reset($targets)->identifier(), ...$ids);
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'patched'
|
||||
];
|
||||
unset($targets[$entityId]);
|
||||
}
|
||||
|
||||
return $this->mailService->entityDelete(...$ids);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array
|
||||
public function entityDelete(EntityIdentifier ...$targets): array
|
||||
{
|
||||
// validate identifiers and construct ID list
|
||||
$targets = $this->mapEntities(...$targets);
|
||||
|
||||
// determine delete mode and target collection (e.g. Trash) if applicable
|
||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
||||
|
||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||
}
|
||||
|
||||
// connect to remote store
|
||||
$this->initialize();
|
||||
|
||||
$deleteTargetIdentifier = null;
|
||||
if ($deleteMode === 'soft') {
|
||||
$deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
|
||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
|
||||
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
|
||||
if ($deleteTargetIdentifier === null) {
|
||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||
}
|
||||
}
|
||||
|
||||
$deleteTargetNative = $deleteTargetIdentifier?->collection();
|
||||
|
||||
// if all targets are already in the delete target collection, we should hard delete instead of moving to avoid duplicates in the trash
|
||||
$targetCollections = [];
|
||||
foreach ($targets as $target) {
|
||||
$targetCollections[$target->collection()] = true;
|
||||
}
|
||||
if (array_keys($targetCollections) === [$deleteTargetNative]) {
|
||||
$deleteMode = 'hard';
|
||||
}
|
||||
|
||||
// move or delete target entities on remote store and construct result map
|
||||
$dispositions = match ($deleteMode) {
|
||||
'soft' => $this->mailService->entityMove($deleteTargetNative, ...array_keys($targets)),
|
||||
'hard' => $this->mailService->entityDelete(...array_keys($targets)),
|
||||
};
|
||||
|
||||
$list = [];
|
||||
foreach ($targets as $target) {
|
||||
$entityId = $target->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($deleteMode === 'soft') {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'moved',
|
||||
'destination' => $deleteTargetIdentifier,
|
||||
'mutation' => new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $entityId),
|
||||
];
|
||||
} else {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'deleted',
|
||||
];
|
||||
}
|
||||
unset($targets[$entityId]);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
{
|
||||
// validate target belongs to this service
|
||||
if ($target->provider() !== $this->provider() || $target->service() !== (string)$this->identifier()) {
|
||||
@@ -575,16 +772,249 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
}
|
||||
|
||||
// validate identifiers and construct ID list
|
||||
$ids = [];
|
||||
$sources = $this->mapEntities(...$sources);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$dispositions = $this->mailService->entityMove($target->collection(), ...array_keys($sources));
|
||||
|
||||
$list = [];
|
||||
foreach ($sources as $source) {
|
||||
$entityId = $source->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'moved',
|
||||
'destination' => $target,
|
||||
'mutation' => new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $entityId),
|
||||
];
|
||||
unset($sources[$entityId]);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityCopy(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
{
|
||||
// TODO: Implement entity copy
|
||||
return [];
|
||||
}
|
||||
|
||||
public function entitySubmit(AddressInterface $sender, EntityIdentifierInterface|null $source = null, MessagePropertiesMutableInterface|null $message = null): EntitySubmitResult
|
||||
{
|
||||
try {
|
||||
$this->initialize();
|
||||
|
||||
if ($source === null && $message === null) {
|
||||
throw new \InvalidArgumentException('At least one of source or message must be provided for submission');
|
||||
}
|
||||
|
||||
if ($source !== null) {
|
||||
if ($source->provider() !== $this->provider() || (string)$source->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Source entity does not belong to this service');
|
||||
}
|
||||
|
||||
return $this->entityTransmitDraft($sender, $source, $message);
|
||||
}
|
||||
|
||||
if ($message === null) {
|
||||
throw new \InvalidArgumentException('Message properties are required for fresh submission');
|
||||
}
|
||||
|
||||
return $this->entityTransmitFresh($sender, $message);
|
||||
} catch (\Throwable $e) {
|
||||
return new EntitySubmitResult(
|
||||
EntitySubmitResult::DISPOSITION_ERROR,
|
||||
errorCode: 'submit_failed',
|
||||
errorMessage: $e->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function entityTransmitFresh(AddressInterface $sender, MessagePropertiesMutableInterface $message): EntitySubmitResult
|
||||
{
|
||||
// determine the drafts folder
|
||||
// if no explicit drafts folder is configured, we will attempt to find a folder with the "drafts" role.
|
||||
$preSendTarget = $this->auxiliary['draftTarget'] ?? null;
|
||||
$preSendTarget = $preSendTarget !== null && (string) $preSendTarget !== ''
|
||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $preSendTarget)
|
||||
: $this->resolveCollectionByRole(CollectionRoles::Drafts->value);
|
||||
|
||||
if ($preSendTarget->provider() !== $this->provider() || $preSendTarget->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Drafts target collection does not belong to this service');
|
||||
}
|
||||
// determine the sent folder
|
||||
// if no explicit sent folder is configured, we will attempt to find a folder with the "sent" role.
|
||||
$postSentTarget = $this->auxiliary['sentTarget'] ?? null;
|
||||
$postSentTarget = $postSentTarget !== null && (string) $postSentTarget !== ''
|
||||
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $postSentTarget)
|
||||
: $this->resolveCollectionByRole(CollectionRoles::Sent->value);
|
||||
|
||||
if ($postSentTarget->provider() !== $this->provider() || $postSentTarget->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Sent target collection does not belong to this service');
|
||||
}
|
||||
// determine the identity to submit with based on the sender address
|
||||
$identityId = $this->resolveIdentityId($sender);
|
||||
if ($identityId === null) {
|
||||
return new EntitySubmitResult(
|
||||
EntitySubmitResult::DISPOSITION_ERROR,
|
||||
errorCode: 'identity_not_found',
|
||||
errorMessage: sprintf('No matching JMAP identity found for sender %s', $sender->getAddress()),
|
||||
);
|
||||
}
|
||||
|
||||
$nativeMessage = $this->normalizeMessageProperties($message)->toJmap();
|
||||
$transportId = $this->mailService->entitySubmitFresh($identityId, $nativeMessage, $preSendTarget->collection(), $postSentTarget->collection());
|
||||
|
||||
return new EntitySubmitResult(
|
||||
EntitySubmitResult::DISPOSITION_SENT,
|
||||
transportId: $transportId,
|
||||
);
|
||||
}
|
||||
|
||||
public function entityTransmitDraft(AddressInterface $sender, EntityIdentifierInterface $source, MessagePropertiesMutableInterface|null $message = null): EntitySubmitResult {
|
||||
$identityId = $this->resolveIdentityId($sender);
|
||||
if ($identityId === null) {
|
||||
return new EntitySubmitResult(
|
||||
EntitySubmitResult::DISPOSITION_ERROR,
|
||||
errorCode: 'identity_not_found',
|
||||
errorMessage: sprintf('No matching JMAP identity found for sender %s', $sender->getAddress()),
|
||||
);
|
||||
}
|
||||
|
||||
$patch = null;
|
||||
if ($message !== null) {
|
||||
$patch = $this->normalizeMessageProperties($message)->toJmap();
|
||||
}
|
||||
|
||||
$transportId = $this->mailService->entitySubmitDraft($identityId, (string)$source->entity(), $patch);
|
||||
|
||||
return new EntitySubmitResult(
|
||||
EntitySubmitResult::DISPOSITION_SENT,
|
||||
transportId: $transportId,
|
||||
sourceDraft: new EntityIdentifier($this->provider(), $this->identifier(), $source->collection(), $source->entity()),
|
||||
);
|
||||
}
|
||||
|
||||
private function normalizeMessageProperties(MessagePropertiesMutableInterface $message): MessageProperties
|
||||
{
|
||||
if ($message instanceof MessageProperties) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
$native = new MessageProperties([]);
|
||||
$native->jsonDeserialize($message->jsonSerialize());
|
||||
|
||||
return $native;
|
||||
}
|
||||
|
||||
private function resolveCollectionByRole(string $role): ?CollectionIdentifier
|
||||
{
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', $role);
|
||||
|
||||
$collections = iterator_to_array($this->mailService->collectionList(null, $filter, null));
|
||||
if (empty($collections)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($collections as $key => $collection) {
|
||||
$collectionId = $this->extractCollectionId($collection, $key);
|
||||
if ($collectionId !== null) {
|
||||
return new CollectionIdentifier($this->provider(), (string) $this->identifier(), $collectionId);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function extractCollectionId(mixed $collection, string|int|null $fallback = null): ?string
|
||||
{
|
||||
if (is_object($collection) && method_exists($collection, 'id')) {
|
||||
$collectionId = $collection->id();
|
||||
if (is_string($collectionId) || is_int($collectionId)) {
|
||||
return (string) $collectionId;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($collection) && isset($collection['id']) && (is_string($collection['id']) || is_int($collection['id']))) {
|
||||
return (string) $collection['id'];
|
||||
}
|
||||
|
||||
if (is_string($fallback) || is_int($fallback)) {
|
||||
$fallback = (string) $fallback;
|
||||
return $fallback !== '' ? $fallback : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveIdentityId(AddressInterface $sender): ?string
|
||||
{
|
||||
$identities = $this->mailService->identityFetch();
|
||||
$senderAddress = strtolower(trim($sender->getAddress()));
|
||||
$fallbackIdentity = null;
|
||||
|
||||
foreach ($identities as $identity) {
|
||||
$identityId = null;
|
||||
$identityAddress = null;
|
||||
|
||||
if (is_object($identity)) {
|
||||
if (method_exists($identity, 'id')) {
|
||||
$identityId = (string)$identity->id();
|
||||
}
|
||||
if (method_exists($identity, 'email')) {
|
||||
$email = $identity->email();
|
||||
$identityAddress = is_string($email) ? $email : null;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($identity)) {
|
||||
$identityId = isset($identity['id']) ? (string)$identity['id'] : $identityId;
|
||||
$identityAddress = isset($identity['email']) && is_string($identity['email']) ? $identity['email'] : $identityAddress;
|
||||
}
|
||||
|
||||
if ($identityId === null || $identityId === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fallbackIdentity ??= $identityId;
|
||||
|
||||
if ($identityAddress !== null && strtolower(trim($identityAddress)) === $senderAddress) {
|
||||
return $identityId;
|
||||
}
|
||||
}
|
||||
|
||||
return $fallbackIdentity;
|
||||
|
||||
}
|
||||
|
||||
private function mapEntities(EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$ids[] = $identifier->entity();
|
||||
$list[$identifier->entity()] = $identifier;
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
|
||||
return $this->mailService->entityMove($target->collection(), ...$ids);
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace KTXM\ProviderJmapc\Service\Remote;
|
||||
|
||||
use Exception;
|
||||
use JmapClient\Client;
|
||||
use JmapClient\Requests\Blob\BlobGet;
|
||||
use JmapClient\Requests\Blob\BlobSet;
|
||||
use JmapClient\Requests\Mail\MailboxGet;
|
||||
use JmapClient\Requests\Mail\MailboxParameters as MailboxParametersRequest;
|
||||
use JmapClient\Requests\Mail\MailboxQuery;
|
||||
@@ -25,17 +23,16 @@ use JmapClient\Requests\Mail\MailQuery;
|
||||
use JmapClient\Requests\Mail\MailQueryChanges;
|
||||
use JmapClient\Requests\Mail\MailSet;
|
||||
use JmapClient\Requests\Mail\MailSubmissionSet;
|
||||
use JmapClient\Requests\RequestBundle;
|
||||
use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse;
|
||||
use JmapClient\Responses\Mail\MailPart;
|
||||
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
|
||||
use JmapClient\Responses\ResponseException;
|
||||
use KTXF\Resource\BinaryResource;
|
||||
use KTXF\Resource\Delta\Delta;
|
||||
use KTXF\Resource\Delta\DeltaCollection;
|
||||
use KTXF\Resource\Filter\Filter;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Range\IRangeTally;
|
||||
use KTXF\Resource\Range\Range;
|
||||
use KTXF\Resource\Range\RangeAnchorType;
|
||||
use KTXF\Resource\Range\RangeTally;
|
||||
use KTXF\Resource\Sort\ISort;
|
||||
@@ -496,6 +493,103 @@ class RemoteMailService {
|
||||
return new RangeTally();
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve entity from remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*/
|
||||
public function entityFetch(string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target(...$identifiers);
|
||||
// select properties to return
|
||||
$r0->property(...$this->defaultMailProperties);
|
||||
$r0->bodyAll(true);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
// convert json objects to message objects
|
||||
$list = [];
|
||||
foreach ($response->objects() as $so) {
|
||||
if (!$so instanceof MailParametersResponse) {
|
||||
continue;
|
||||
}
|
||||
$id = $so->id();
|
||||
$list[$id] = $so->parametersRaw();
|
||||
$list[$id]['signature'] = $response->state();
|
||||
}
|
||||
// return message collection
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityDownload(string $identifier, string|null $blobId = null): BinaryResource {
|
||||
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target($identifier);
|
||||
// select properties to return
|
||||
$r0->property(...['id', 'blobId', 'bodyStructure']);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
|
||||
$parameters = $response->object(0);
|
||||
if (!$parameters instanceof MailParametersResponse) {
|
||||
throw new Exception('Unexpected response type received from server.', 1);
|
||||
}
|
||||
|
||||
if ($blobId === null) {
|
||||
$blobId = $parameters->blob();
|
||||
$filename = 'message.eml';
|
||||
$mimeType = 'text/plain';
|
||||
} else {
|
||||
$walk = function (?MailPart $part) use (&$walk, $blobId): ?MailPart {
|
||||
if ($part === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($part->blob() === $blobId) {
|
||||
return $part;
|
||||
}
|
||||
|
||||
foreach ($part->parts() ?? [] as $subPart) {
|
||||
$subPartResult = $walk($subPart);
|
||||
if ($subPartResult !== null) {
|
||||
return $subPartResult;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
$part = $walk($parameters->bodyPartStructure());
|
||||
$filename = $part->name() ?? 'file.bin';
|
||||
$mimeType = $part->type() ?? 'application/octet-stream';
|
||||
}
|
||||
|
||||
$streamResource = $this->dataStore->downloadStream($this->dataAccount, $blobId, $mimeType, $filename);
|
||||
|
||||
$stream = (function () use ($streamResource): \Generator {
|
||||
try {
|
||||
while (!$streamResource->eof()) {
|
||||
$chunk = $streamResource->read(8192);
|
||||
if ($chunk === '' && !$streamResource->eof()) {
|
||||
throw new Exception('Unable to read from download stream.', 1);
|
||||
}
|
||||
if ($chunk !== '') {
|
||||
yield $chunk;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
$streamResource->close();
|
||||
}
|
||||
})();
|
||||
|
||||
return new BinaryResource($filename, $mimeType, $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* check existence of entities in remote storage
|
||||
*
|
||||
@@ -624,34 +718,8 @@ class RemoteMailService {
|
||||
return $delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve entity from remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*/
|
||||
public function entityFetch(string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target(...$identifiers);
|
||||
// select properties to return
|
||||
$r0->property(...$this->defaultMailProperties);
|
||||
$r0->bodyAll(true);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
// convert json objects to message objects
|
||||
$list = [];
|
||||
foreach ($response->objects() as $so) {
|
||||
if (!$so instanceof MailParametersResponse) {
|
||||
continue;
|
||||
}
|
||||
$id = $so->id();
|
||||
$list[$id] = $so->parametersRaw();
|
||||
$list[$id]['signature'] = $response->state();
|
||||
}
|
||||
// return message collection
|
||||
return $list;
|
||||
public function entityFresh(): MailParametersRequest {
|
||||
return new MailParametersRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,6 +792,37 @@ class RemoteMailService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function entityPatch(MailParametersRequest $properties, string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailSet($this->dataAccount);
|
||||
foreach ($identifiers as $id) {
|
||||
$r0->patch($id, $properties);
|
||||
}
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->first();
|
||||
// check for command error
|
||||
if ($response instanceof ResponseException) {
|
||||
if ($response->type() === 'unknownMethod') {
|
||||
throw new JmapUnknownMethod($response->description(), 1);
|
||||
} else {
|
||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||
}
|
||||
}
|
||||
$results = [];
|
||||
// check for success
|
||||
foreach ($response->updateSuccesses() as $id => $data) {
|
||||
$results[$id] = true;
|
||||
}
|
||||
// check for failure
|
||||
foreach ($response->updateFailures() as $id => $data) {
|
||||
$results[$id] = $data['type'] ?? 'unknownError';
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete entities from remote storage
|
||||
*
|
||||
@@ -761,16 +860,6 @@ class RemoteMailService {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy entity in remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*
|
||||
*/
|
||||
public function entityCopy(string $target, string ...$identifiers): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* move entity in remote storage
|
||||
*
|
||||
@@ -809,99 +898,116 @@ class RemoteMailService {
|
||||
}
|
||||
|
||||
/**
|
||||
* send entity
|
||||
* copy entity in remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*
|
||||
*/
|
||||
public function entitySend(string $identity, MailMessageObject $message, ?string $presendLocation = null, ?string $postsendLocation = null): string {
|
||||
// determine if pre-send location is present
|
||||
if ($presendLocation === null || empty($presendLocation)) {
|
||||
throw new Exception('Pre-Send Location is missing', 1);
|
||||
}
|
||||
// determine if post-send location is present
|
||||
if ($postsendLocation === null || empty($postsendLocation)) {
|
||||
throw new Exception('Post-Send Location is missing', 1);
|
||||
}
|
||||
// determine if we have the basic required data and fail otherwise
|
||||
if (empty($message->getFrom())) {
|
||||
throw new Exception('Missing Requirements: Message MUST have a From address', 1);
|
||||
}
|
||||
if (empty($message->getTo())) {
|
||||
throw new Exception('Missing Requirements: Message MUST have a To address(es)', 1);
|
||||
}
|
||||
// determine if message has attachments
|
||||
if (count($message->getAttachments()) > 0) {
|
||||
// process attachments first
|
||||
$message = $this->depositAttachmentsFromMessage($message);
|
||||
}
|
||||
// convert from address object to string
|
||||
$from = $message->getFrom()->getAddress();
|
||||
// convert to, cc and bcc address object arrays to single strings array
|
||||
$to = array_map(
|
||||
function ($entry) { return $entry->getAddress(); },
|
||||
array_merge($message->getTo(), $message->getCc(), $message->getBcc())
|
||||
);
|
||||
unset($cc, $bcc);
|
||||
// construct set request
|
||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->create('1', $message)->in($presendLocation);
|
||||
// construct set request
|
||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
// construct envelope
|
||||
$e1 = $r1->create('2');
|
||||
$e1->identity($identity);
|
||||
$e1->message('#1');
|
||||
$e1->from($from);
|
||||
$e1->to($to);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0, $r1]);
|
||||
// extract response
|
||||
$response = $bundle->response(1);
|
||||
// return collection information
|
||||
return (string)$response->created()['2']['id'];
|
||||
public function entityCopy(string $target, string ...$identifiers): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve collection entity attachment from remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
* Submit a fresh message by creating it as a draft and then creating a submission.
|
||||
*
|
||||
* @since Release 2.0.0
|
||||
*/
|
||||
public function depositAttachmentsFromMessage(MailMessageObject $message): MailMessageObject {
|
||||
public function entitySubmitFresh(string $identityId, array $message, string $preSendTarget, string $postSentTarget): string {
|
||||
|
||||
$parameters = $message->toJmap();
|
||||
$attachments = $message->getAttachments();
|
||||
$matches = [];
|
||||
$mail = new MailParametersRequest();
|
||||
$mail->parametersRaw($message);
|
||||
|
||||
$this->findAttachmentParts($parameters['bodyStructure'], $matches);
|
||||
$messageCreateId = 'm_' . uniqid();
|
||||
$submissionCreateId = 's_' . uniqid();
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$part = $attachment->toJmap();
|
||||
if (isset($matches[$part->getId()])) {
|
||||
// deposit attachment in data store
|
||||
$response = $this->blobDeposit($account, $part->getType(), $attachment->getContents());
|
||||
// transfer blobId and size to mail part
|
||||
$matches[$part->getId()]->blobId = $response['blobId'];
|
||||
$matches[$part->getId()]->size = $response['size'];
|
||||
unset($matches[$part->getId()]->partId);
|
||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$createdMessage = $r0->create($messageCreateId, $mail);
|
||||
$createdMessage->in($preSendTarget);
|
||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$submission = $r1->create($submissionCreateId);
|
||||
$submission->identity($identityId);
|
||||
$submission->message('#' . $messageCreateId);
|
||||
|
||||
$bundle = $this->dataStore->perform([$r0, $r1]);
|
||||
$response = $bundle->response(1);
|
||||
if ($response instanceof ResponseException) {
|
||||
if ($response->type() === 'unknownMethod') {
|
||||
throw new JmapUnknownMethod($response->description(), 1);
|
||||
}
|
||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||
}
|
||||
|
||||
return $this->extractSubmissionIdentifier($response, $submissionCreateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit an existing draft message.
|
||||
*
|
||||
* @since Release 2.0.0
|
||||
*/
|
||||
public function entitySubmitDraft(string $identityId, string $draftId, ?array $patch = null): string {
|
||||
if ($draftId === '') {
|
||||
throw new Exception('Draft identifier is required for draft submission', 1);
|
||||
}
|
||||
|
||||
$requests = [];
|
||||
|
||||
if ($patch !== null && $patch !== []) {
|
||||
$draftMutation = new MailParametersRequest();
|
||||
$draftMutation->parametersRaw($patch);
|
||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->update($draftId, $draftMutation);
|
||||
$requests[] = $r0;
|
||||
}
|
||||
|
||||
$submissionCreateId = 's_' . uniqid();
|
||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$submission = $r1->create($submissionCreateId);
|
||||
$submission->identity($identityId);
|
||||
$submission->message($draftId);
|
||||
$requests[] = $r1;
|
||||
|
||||
$bundle = $this->dataStore->perform($requests);
|
||||
$responseIndex = count($requests) - 1;
|
||||
$response = $bundle->response($responseIndex);
|
||||
if ($response instanceof ResponseException) {
|
||||
if ($response->type() === 'unknownMethod') {
|
||||
throw new JmapUnknownMethod($response->description(), 1);
|
||||
}
|
||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||
}
|
||||
|
||||
return $this->extractSubmissionIdentifier($response, $submissionCreateId);
|
||||
}
|
||||
|
||||
private function collectionByRole(string $role): ?string {
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', $role);
|
||||
|
||||
$collections = $this->collectionList(null, $filter, null);
|
||||
if ($collections === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string)array_key_first($collections);
|
||||
}
|
||||
|
||||
private function extractSubmissionIdentifier(object $response, string $createId): string {
|
||||
if (method_exists($response, 'createSuccess')) {
|
||||
$success = $response->createSuccess($createId);
|
||||
if (is_array($success) && isset($success['id'])) {
|
||||
return (string)$success['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return (new MailMessageObject())->fromJmap($parameters);
|
||||
|
||||
}
|
||||
|
||||
protected function findAttachmentParts(object &$part, array &$matches) {
|
||||
|
||||
if ($part->disposition === 'attachment' || $part->disposition === 'inline') {
|
||||
$matches[$part->partId] = $part;
|
||||
}
|
||||
|
||||
foreach ($part->subParts as $entry) {
|
||||
$this->findAttachmentParts($entry, $matches);
|
||||
if (method_exists($response, 'created')) {
|
||||
$created = $response->created();
|
||||
if (is_array($created) && isset($created[$createId]['id'])) {
|
||||
return (string)$created[$createId]['id'];
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('Submission succeeded without a returned identifier', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,16 +9,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderJmapc\Service\Remote;
|
||||
|
||||
use GuzzleHttp\Client as HttpClient;
|
||||
use GuzzleHttp\Psr7\HttpFactory;
|
||||
use JmapClient\Authentication\Basic;
|
||||
use JmapClient\Authentication\Bearer;
|
||||
use JmapClient\Authentication\JsonBasic;
|
||||
use JmapClient\Authentication\JsonBasicCookie;
|
||||
use JmapClient\Client as JmapClient;
|
||||
use KTXC\Server;
|
||||
use KTXF\Resource\Provider\ResourceServiceBaseInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityBearer;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityOAuth;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationUri;
|
||||
use KTXM\ProviderJmapc\Providers\Mail\Service as MailService;
|
||||
use KTXM\ProviderJmapc\Providers\Contacts\Service as ContactsService;
|
||||
@@ -40,9 +36,6 @@ class RemoteService {
|
||||
*/
|
||||
public static function freshClient(MailService|FilesService $service): JmapClient {
|
||||
|
||||
// defaults
|
||||
$client = new JmapClient();
|
||||
$client->setTransportAgent(self::$clientTransportAgent);
|
||||
$location = $service->getLocation();
|
||||
$identity = $service->getIdentity();
|
||||
|
||||
@@ -50,12 +43,23 @@ class RemoteService {
|
||||
if ($location instanceof ResourceServiceLocationUri === false) {
|
||||
throw new \InvalidArgumentException('Service location is not a valid URI');
|
||||
}
|
||||
|
||||
// The JMAP client accepts transport abstractions only. Guzzle supplies the
|
||||
// PSR-18 client, while HttpFactory supplies both required PSR-17 factories.
|
||||
$httpFactory = new HttpFactory();
|
||||
$client = new JmapClient(
|
||||
transportClient: new HttpClient([
|
||||
'verify' => $location->getVerifyPeer(),
|
||||
]),
|
||||
requestFactory: $httpFactory,
|
||||
streamFactory: $httpFactory,
|
||||
);
|
||||
$client->setTransportAgent(self::$clientTransportAgent);
|
||||
$client->configureTransportMode($location->getScheme());
|
||||
$client->setHost($location->getHost() . ':' . $location->getPort());
|
||||
if (!empty($location->getPath())) {
|
||||
$client->setDiscoveryPath($location->getPath());
|
||||
}
|
||||
$client->configureTransportVerification((bool)$location->getVerifyPeer());
|
||||
// authentication
|
||||
if (($identity instanceof ResourceServiceIdentityBasic) === false) {
|
||||
throw new \InvalidArgumentException('Service identity is not a valid Basic or Bearer authentication');
|
||||
|
||||
Generated
+264
-292
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ServiceObject } from '@KTXM/MailManager/models/service'
|
||||
import { ServiceAddressObject } from '@KTXM/MailManager/models/address'
|
||||
|
||||
type AuxiliaryTab = 'addresses' | 'messages' | 'sync'
|
||||
type DeleteMode = 'soft' | 'hard'
|
||||
@@ -16,8 +17,8 @@ const emit = defineEmits<{
|
||||
const activeTab = ref<AuxiliaryTab>('addresses')
|
||||
const deleteMode = ref<DeleteMode>('soft')
|
||||
const deleteDestination = ref('Trash')
|
||||
const primaryAddress = ref('')
|
||||
const secondaryAddresses = ref('')
|
||||
const primaryAddress = ref<ServiceAddressObject>(new ServiceAddressObject())
|
||||
const secondaryAddresses = ref<ServiceAddressObject[]>([])
|
||||
|
||||
const settingGroups = [
|
||||
{
|
||||
@@ -61,10 +62,6 @@ const destinationHint = computed(() => {
|
||||
return 'Mailbox identifier or well-known role target, for example Trash.'
|
||||
})
|
||||
|
||||
const secondaryAddressesHint = computed(() => {
|
||||
return 'Use one address per line. Commas are also accepted.'
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.service,
|
||||
service => {
|
||||
@@ -86,17 +83,17 @@ watch(
|
||||
}
|
||||
|
||||
if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) {
|
||||
if (sameAddresses(nextService, primaryAddress.value, secondaryAddresses.value)) {
|
||||
if (sameAddresses(nextService)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
nextService.primaryAddress = normalizePrimaryAddress(primaryAddress.value)
|
||||
nextService.secondaryAddresses = normalizeSecondaryAddresses(secondaryAddresses.value)
|
||||
nextService.primaryAddress = primaryAddress.value.empty ? null : primaryAddress.value
|
||||
nextService.secondaryAddresses = dedupeAddresses(secondaryAddresses.value)
|
||||
nextService.auxiliary = nextAuxiliary
|
||||
emit('update:service', nextService)
|
||||
},
|
||||
{ immediate: true }
|
||||
{ deep: true, immediate: true }
|
||||
)
|
||||
|
||||
function syncFromService(service?: ServiceObject) {
|
||||
@@ -105,8 +102,8 @@ function syncFromService(service?: ServiceObject) {
|
||||
deleteDestination.value = typeof auxiliary.deleteDestination === 'string' && auxiliary.deleteDestination.length > 0
|
||||
? auxiliary.deleteDestination
|
||||
: 'Trash'
|
||||
primaryAddress.value = service?.primaryAddress ?? ''
|
||||
secondaryAddresses.value = (service?.secondaryAddresses ?? []).join('\n')
|
||||
primaryAddress.value = service?.primaryAddress ?? new ServiceAddressObject()
|
||||
secondaryAddresses.value = service?.secondaryAddresses ?? []
|
||||
}
|
||||
|
||||
function normalizeDeleteDestination(value: string): string {
|
||||
@@ -114,16 +111,23 @@ function normalizeDeleteDestination(value: string): string {
|
||||
return trimmedValue.length > 0 ? trimmedValue : 'Trash'
|
||||
}
|
||||
|
||||
function normalizePrimaryAddress(value: string): string | null {
|
||||
const trimmedValue = value.trim()
|
||||
return trimmedValue.length > 0 ? trimmedValue : null
|
||||
function dedupeAddresses(entries: ServiceAddressObject[]): ServiceAddressObject[] {
|
||||
const populated = entries.filter(entry => !entry.empty)
|
||||
return populated.filter((entry, index) =>
|
||||
populated.findIndex(candidate => candidate.matches(entry.address)) === index)
|
||||
}
|
||||
|
||||
function normalizeSecondaryAddresses(value: string): string[] {
|
||||
return value
|
||||
.split(/\r?\n|,/)
|
||||
.map(entry => entry.trim())
|
||||
.filter((entry, index, entries) => entry.length > 0 && entries.indexOf(entry) === index)
|
||||
function addSecondaryAddress() {
|
||||
secondaryAddresses.value.push(new ServiceAddressObject())
|
||||
}
|
||||
|
||||
function removeSecondaryAddress(index: number) {
|
||||
secondaryAddresses.value.splice(index, 1)
|
||||
}
|
||||
|
||||
function validAddress(value: string): boolean | string {
|
||||
const trimmedValue = value.trim()
|
||||
return trimmedValue.length === 0 || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedValue) || 'Invalid email address'
|
||||
}
|
||||
|
||||
function sameAuxiliary(current: Record<string, any>, next: Record<string, any>): boolean {
|
||||
@@ -131,9 +135,19 @@ function sameAuxiliary(current: Record<string, any>, next: Record<string, any>):
|
||||
&& (current.deleteDestination ?? undefined) === (next.deleteDestination ?? undefined)
|
||||
}
|
||||
|
||||
function sameAddresses(service: ServiceObject, nextPrimaryAddress: string, nextSecondaryAddresses: string): boolean {
|
||||
return (service.primaryAddress ?? null) === normalizePrimaryAddress(nextPrimaryAddress)
|
||||
&& JSON.stringify(service.secondaryAddresses) === JSON.stringify(normalizeSecondaryAddresses(nextSecondaryAddresses))
|
||||
function sameAddresses(service: ServiceObject): boolean {
|
||||
const nextPrimary = primaryAddress.value.empty ? null : primaryAddress.value
|
||||
const nextSecondary = dedupeAddresses(secondaryAddresses.value)
|
||||
return sameAddress(service.primaryAddress, nextPrimary)
|
||||
&& service.secondaryAddresses.length === nextSecondary.length
|
||||
&& service.secondaryAddresses.every((entry, index) => sameAddress(entry, nextSecondary[index]))
|
||||
}
|
||||
|
||||
function sameAddress(current: ServiceAddressObject | null, next: ServiceAddressObject | null): boolean {
|
||||
if (current === null || next === null) {
|
||||
return current === next
|
||||
}
|
||||
return current.equals(next)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -165,23 +179,66 @@ function sameAddresses(service: ServiceObject, nextPrimaryAddress: string, nextS
|
||||
Configure the primary mailbox identity and any additional sender aliases exposed by this service.
|
||||
</p>
|
||||
|
||||
<v-text-field
|
||||
v-model="primaryAddress"
|
||||
label="Primary Address"
|
||||
variant="outlined"
|
||||
prepend-inner-icon="mdi-email-outline"
|
||||
class="mb-4"
|
||||
/>
|
||||
<div class="text-subtitle-2 mb-2">Primary Address</div>
|
||||
<div class="d-flex ga-2 mb-6">
|
||||
<v-text-field
|
||||
v-model="primaryAddress.label"
|
||||
label="Display Name"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
hide-details="auto"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="primaryAddress.address"
|
||||
label="Email Address"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
prepend-inner-icon="mdi-email-outline"
|
||||
:rules="[validAddress]"
|
||||
hide-details="auto"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<v-textarea
|
||||
v-model="secondaryAddresses"
|
||||
label="Secondary Addresses"
|
||||
variant="outlined"
|
||||
prepend-inner-icon="mdi-email-multiple-outline"
|
||||
rows="4"
|
||||
:hint="secondaryAddressesHint"
|
||||
persistent-hint
|
||||
/>
|
||||
<div class="text-subtitle-2 mb-2">Secondary Addresses</div>
|
||||
<div
|
||||
v-for="(entry, index) in secondaryAddresses"
|
||||
:key="index"
|
||||
class="d-flex ga-2 mb-2"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="entry.label"
|
||||
label="Display Name"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
hide-details="auto"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="entry.address"
|
||||
label="Email Address"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
prepend-inner-icon="mdi-email-multiple-outline"
|
||||
:rules="[validAddress]"
|
||||
hide-details="auto"
|
||||
/>
|
||||
<v-btn
|
||||
icon
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="removeSecondaryAddress(index)"
|
||||
>
|
||||
<v-icon>mdi-delete-outline</v-icon>
|
||||
<v-tooltip activator="parent" location="bottom">Remove Alias</v-tooltip>
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
<v-btn
|
||||
variant="tonal"
|
||||
prepend-icon="mdi-plus"
|
||||
@click="addSecondaryAddress"
|
||||
>
|
||||
Add Alias
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-window-item>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user