76 Commits

Author SHA1 Message Date
Sebastian f39dd75ae5 fix: folder deletion while in trash
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-07 20:45:29 -04:00
Sebastian b60341f62d fix: message sending
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-30 21:03:59 -04:00
Sebastian 4cd249d019 fix: attachment upload on send
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-29 21:24:05 -04:00
Sebastian 152a8141d0 fix: logging
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-29 21:20:05 -04:00
Sebastian 5aa95fa329 feat: sync sending identities
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 21:50:37 -04:00
Sebastian f0b0f87ce2 fix: primary address saving
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 21:02:51 -04:00
Sebastian 75a462ad18 fix: disable auto complete
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 20:52:53 -04:00
Sebastian 8af08d8936 refactor: migrate to scoped execution contexts
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-27 00:52:29 -04:00
Sebastian edc1aece13 Merge pull request 'fix(deps): update dependency pinia to v4' (#57) from renovate/pinia-4.x into main
Reviewed-on: #57
2026-07-24 14:02:16 +00:00
Sebastian b81070338d fix(deps): update dependency pinia to v4
Build Test / test (pull_request) Successful in 35s
JS Unit Tests / test (pull_request) Successful in 37s
PHP Integration Tests / Integration Tests (pull_request) Successful in 56s
PHP Unit Tests / test (pull_request) Successful in 1m9s
2026-07-24 13:58:43 +00:00
Sebastian ab24fe2b54 Merge pull request 'chore(deps): update dependency vue-router to v5.2.0' (#63) from renovate/vue-router-5.x-lockfile into main
Reviewed-on: #63
2026-07-24 13:56:34 +00:00
Sebastian 3073cf9f75 Merge pull request 'chore(deps): update dependency @vitejs/plugin-vue to v6.0.8' (#60) from renovate/vitejs-plugin-vue-6.x-lockfile into main
Reviewed-on: #60
2026-07-24 13:55:54 +00:00
Sebastian 8cf4993107 Merge pull request 'chore(deps): update dependency vue-tsc to v3.3.8' (#61) from renovate/vue-language-tools-monorepo into main
Reviewed-on: #61
2026-07-24 13:55:47 +00:00
Sebastian 5bda58fbb9 Merge pull request 'chore(deps): update dependency vuetify to v4.1.6' (#62) from renovate/vuetify-4.x-lockfile into main
Reviewed-on: #62
2026-07-24 13:55:32 +00:00
Sebastian b6bc83e432 chore(deps): update dependency vue-router to v5.2.0
Build Test / test (pull_request) Successful in 36s
JS Unit Tests / test (pull_request) Successful in 34s
PHP Integration Tests / Integration Tests (pull_request) Successful in 2m33s
PHP Unit Tests / test (pull_request) Successful in 2m18s
2026-07-24 13:51:41 +00:00
Sebastian 02f3662f40 chore(deps): update dependency vuetify to v4.1.6
Build Test / test (pull_request) Successful in 40s
JS Unit Tests / test (pull_request) Successful in 36s
PHP Unit Tests / test (pull_request) Successful in 1m40s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m50s
2026-07-24 13:51:36 +00:00
Sebastian 2dd56e0662 chore(deps): update dependency vue-tsc to v3.3.8
JS Unit Tests / test (pull_request) Successful in 1m17s
Build Test / test (pull_request) Successful in 1m20s
PHP Unit Tests / test (pull_request) Successful in 1m47s
PHP Integration Tests / Integration Tests (pull_request) Successful in 3m10s
2026-07-24 13:51:34 +00:00
Sebastian d449a71e80 chore(deps): update dependency @vitejs/plugin-vue to v6.0.8
JS Unit Tests / test (pull_request) Successful in 1m7s
Build Test / test (pull_request) Successful in 1m23s
PHP Unit Tests / test (pull_request) Successful in 2m23s
PHP Integration Tests / Integration Tests (pull_request) Successful in 4m5s
2026-07-24 13:51:31 +00:00
Sebastian 1310de8a15 Merge pull request 'chore(deps): update mongo docker tag to v8' (#59) from renovate/mongo-8.x into main
Reviewed-on: #59
2026-07-24 04:49:46 +00:00
Sebastian c7eb46c7ac chore(deps): update mongo docker tag to v8
Build Test / test (pull_request) Successful in 1m26s
JS Unit Tests / test (pull_request) Successful in 1m29s
PHP Unit Tests / test (pull_request) Successful in 2m13s
PHP Integration Tests / Integration Tests (pull_request) Successful in 2m22s
2026-07-24 04:38:37 +00:00
Sebastian c58d99988c Merge pull request 'chore: implement js test suites' (#58) from chore/js-test-suites into main
Reviewed-on: #58
2026-07-24 04:37:07 +00:00
Sebastian f5e7fa5f81 chore: implement js test suites
JS Unit Tests / test (pull_request) Successful in 40s
Build Test / test (pull_request) Successful in 42s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m20s
PHP Unit Tests / test (pull_request) Successful in 1m54s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-24 00:34:39 -04:00
Sebastian 9a243e2c61 Merge pull request 'chore(deps): update dependency vue-router to v5.2.0' (#54) from renovate/vue-router-5.x-lockfile into main
Reviewed-on: #54
2026-07-24 03:58:09 +00:00
Sebastian 4a8cea943b Merge pull request 'chore(deps): update dependency vue-tsc to v3.3.8' (#53) from renovate/vue-language-tools-monorepo into main
Reviewed-on: #53
2026-07-24 03:22:10 +00:00
Sebastian 8965c047d1 Merge pull request 'chore(deps): update dependency @vitejs/plugin-vue to v6.0.8' (#49) from renovate/vitejs-plugin-vue-6.x-lockfile into main
Reviewed-on: #49
2026-07-24 03:22:00 +00:00
Sebastian 7fa75dafc9 Merge pull request 'chore(deps): update dependency vuetify to v4.1.6' (#46) from renovate/vuetify-4.x-lockfile into main
Reviewed-on: #46
2026-07-24 03:21:51 +00:00
Sebastian 8eb245f52f Merge pull request 'chore(deps): update dependency vue to v3.5.40' (#50) from renovate/vue-monorepo into main
Reviewed-on: #50
2026-07-24 03:21:20 +00:00
Sebastian 3c4b864339 chore(deps): update dependency vue-router to v5.2.0
JS Unit Tests / test (pull_request) Successful in 45s
Build Test / test (pull_request) Failing after 50s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m37s
PHP Unit Tests / test (pull_request) Successful in 2m46s
2026-07-24 02:56:25 +00:00
Sebastian 64b933534b chore(deps): update dependency vuetify to v4.1.6
Build Test / test (pull_request) Failing after 31s
JS Unit Tests / test (pull_request) Successful in 34s
PHP Unit Tests / test (pull_request) Successful in 1m57s
PHP Integration Tests / Integration Tests (pull_request) Successful in 2m40s
2026-07-24 02:56:16 +00:00
Sebastian d3f383e937 chore(deps): update dependency vue-tsc to v3.3.8
Build Test / test (pull_request) Failing after 36s
JS Unit Tests / test (pull_request) Successful in 29s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m33s
PHP Unit Tests / test (pull_request) Successful in 2m52s
2026-07-24 02:56:11 +00:00
Sebastian 816c1cf931 chore(deps): update dependency vue to v3.5.40
Build Test / test (pull_request) Failing after 41s
JS Unit Tests / test (pull_request) Failing after 31s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m41s
PHP Unit Tests / test (pull_request) Successful in 1m36s
2026-07-24 02:56:08 +00:00
Sebastian 072ea8c450 chore(deps): update dependency @vitejs/plugin-vue to v6.0.8
Build Test / test (pull_request) Failing after 57s
JS Unit Tests / test (pull_request) Successful in 50s
PHP Unit Tests / test (pull_request) Successful in 2m25s
PHP Integration Tests / Integration Tests (pull_request) Successful in 2m53s
2026-07-24 02:56:01 +00:00
Sebastian 44c3b629a2 Merge pull request 'Chore/php83 test suites' (#52) from chore/php83-test-suites into main
Reviewed-on: #52
2026-07-24 02:43:18 +00:00
Sebastian aa0ac2da51 fix: install module dependencies before running integration tests
JS Unit Tests / test (pull_request) Successful in 40s
PHP Unit Tests / test (pull_request) Successful in 1m16s
PHP Integration Tests / Integration Tests (pull_request) Successful in 1m27s
Build Test / test (pull_request) Failing after 25s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-23 22:32:09 -04:00
Sebastian 4ef881e5c1 chore: implement php test suites
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-23 22:20:36 -04:00
Sebastian dc6d6081ee fix: returned identifier on create and modify
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-19 06:45:48 -04:00
Sebastian 1a5339f069 Merge pull request 'chore(deps): update dependency vue-tsc to v3.3.7' (#45) from renovate/vue-language-tools-monorepo into main
Reviewed-on: #45
2026-07-17 23:18:12 +00:00
Sebastian 9d95521247 Merge pull request 'chore(deps): update vitest monorepo to v4.1.10' (#47) from renovate/vitest-monorepo into main
Reviewed-on: #47
2026-07-17 23:17:58 +00:00
Sebastian cfb99dfc01 Merge pull request 'chore(deps): update dependency typescript to v7' (#48) from renovate/typescript-7.x into main
Reviewed-on: #48
2026-07-17 23:17:50 +00:00
Sebastian 609e7e577c Merge pull request 'chore(deps): update dependency vite to v8.1.5' (#44) from renovate/vite-8.x-lockfile into main
Reviewed-on: #44
2026-07-17 23:17:41 +00:00
Sebastian fa5e91f0a9 chore(deps): update dependency vite to v8.1.5
JS Unit Tests / test (pull_request) Failing after 13m2s
Build Test / test (pull_request) Failing after 13m4s
PHP Unit Tests / test (pull_request) Failing after 18m0s
2026-07-17 03:08:36 +00:00
Sebastian 024c9656d4 chore(deps): update dependency typescript to v7
PHP Unit Tests / test (pull_request) Failing after 14m47s
JS Unit Tests / test (pull_request) Failing after 15m6s
Build Test / test (pull_request) Failing after 15m8s
2026-07-10 03:08:12 +00:00
Sebastian b950022081 chore(deps): update vitest monorepo to v4.1.10
JS Unit Tests / test (pull_request) Failing after 11m9s
Build Test / test (pull_request) Failing after 11m33s
PHP Unit Tests / test (pull_request) Failing after 16m6s
2026-07-10 03:08:04 +00:00
Sebastian 2da8bebe61 chore(deps): update dependency vue-tsc to v3.3.7
PHP Unit Tests / test (pull_request) Failing after 12m26s
JS Unit Tests / test (pull_request) Failing after 12m36s
Build Test / test (pull_request) Failing after 12m38s
2026-07-10 03:07:55 +00:00
Sebastian 439eaabce3 fix(renovate): install renovate in runner temp
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-09 20:12:07 -04:00
Sebastian 16df84cb28 Merge pull request 'chore(deps): update dependency vite to v8.1.3' (#41) from renovate/vite-8.x-lockfile into main
Reviewed-on: #41
2026-07-09 23:46:45 +00:00
Sebastian e7ba07bf03 Merge pull request 'chore(deps): update dependency guzzlehttp/psr7 to v2.12.4' (#42) from renovate/guzzlehttp-psr7-2.x-lockfile into main
Reviewed-on: #42
2026-07-09 23:46:37 +00:00
Sebastian 69bbbb6c86 Merge pull request 'chore(deps): update dependency phpunit/phpunit to v11.5.56' (#43) from renovate/phpunit-phpunit-11.x-lockfile into main
Reviewed-on: #43
2026-07-09 23:46:29 +00:00
Sebastian fdfaf562a0 Merge pull request 'chore(deps): update dependency guzzlehttp/guzzle to v7.14.0' (#40) from renovate/guzzlehttp-guzzle-7.x-lockfile into main
Reviewed-on: #40
2026-07-09 23:46:21 +00:00
Sebastian 4cbde63865 refactor: use new documents interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-09 19:39:15 -04:00
Sebastian 808ed192af chore(deps): update dependency phpunit/phpunit to v11.5.56
PHP Unit Tests / test (pull_request) Failing after 14m5s
JS Unit Tests / test (pull_request) Failing after 14m7s
Build Test / test (pull_request) Failing after 14m23s
2026-07-09 03:05:09 +00:00
Sebastian 511a94a0fa chore(deps): update dependency guzzlehttp/psr7 to v2.12.4
PHP Unit Tests / test (pull_request) Failing after 14m30s
JS Unit Tests / test (pull_request) Failing after 14m34s
Build Test / test (pull_request) Failing after 14m47s
2026-07-09 03:05:05 +00:00
Sebastian 52fdb17b09 chore(deps): update dependency vite to v8.1.3
PHP Unit Tests / test (pull_request) Failing after 13m50s
JS Unit Tests / test (pull_request) Failing after 14m0s
Build Test / test (pull_request) Failing after 14m2s
2026-07-05 03:03:14 +00:00
Sebastian 9dc7a90f42 chore(deps): update dependency guzzlehttp/guzzle to v7.13.1
PHP Unit Tests / test (pull_request) Failing after 14m4s
JS Unit Tests / test (pull_request) Failing after 14m10s
Build Test / test (pull_request) Failing after 14m25s
renovate/artifacts Artifact file update failure
2026-07-05 03:03:08 +00:00
Sebastian 88fae64c86 fix: add guzzel dependency
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-29 15:35:19 -04:00
Sebastian 0d6bf36441 Merge pull request 'chore(deps): update dependency vue to v3.5.39' (#38) from renovate/vue-monorepo into main
Reviewed-on: #38
2026-06-28 14:40:42 +00:00
Sebastian 09622e08c3 Merge pull request 'chore(deps): update dependency vite to v8.1.0' (#39) from renovate/vite-8.x-lockfile into main
Reviewed-on: #39
2026-06-28 14:40:34 +00:00
Sebastian 8d2129f00c chore(deps): update dependency vite to v8.1.0
PHP Unit Tests / test (pull_request) Failing after 14m26s
JS Unit Tests / test (pull_request) Failing after 14m28s
Build Test / test (pull_request) Failing after 14m46s
2026-06-27 03:02:59 +00:00
Sebastian 7f5a0a3792 chore(deps): update dependency vue to v3.5.39
PHP Unit Tests / test (pull_request) Failing after 14m48s
JS Unit Tests / test (pull_request) Failing after 15m17s
Build Test / test (pull_request) Failing after 15m19s
2026-06-27 03:02:53 +00:00
Sebastian f904b36a53 fix: use seen insstead of read flag
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-25 23:40:26 -04:00
Sebastian 190f118589 Merge pull request 'chore(deps): update vitest monorepo to v4.1.9' (#37) from renovate/vitest-monorepo into main
Reviewed-on: #37
2026-06-24 15:23:27 +00:00
Sebastian b5e15bdefe chore(deps): update vitest monorepo to v4.1.9
PHP Unit Tests / test (pull_request) Failing after 11m45s
JS Unit Tests / test (pull_request) Failing after 11m53s
Build Test / test (pull_request) Failing after 11m55s
2026-06-22 03:05:08 +00:00
Sebastian 1896214026 Merge pull request 'chore(deps): update dependency vite to v8.0.16' (#35) from renovate/vite-8.x-lockfile into main
Reviewed-on: #35
2026-06-20 22:59:30 +00:00
Sebastian 77d145eede refactor: cosmetic
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-20 18:59:20 -04:00
Sebastian 17cc703c68 Merge pull request 'chore(deps): update dependency vuetify to v4.1.2' (#36) from renovate/vuetify-4.x-lockfile into main
Reviewed-on: #36
2026-06-20 22:58:37 +00:00
Sebastian 30782ba07f chore(deps): update dependency vuetify to v4.1.2
PHP Unit Tests / test (pull_request) Failing after 13m54s
JS Unit Tests / test (pull_request) Failing after 13m56s
Build Test / test (pull_request) Failing after 14m10s
2026-06-20 03:07:16 +00:00
Sebastian c92950dcc1 chore(deps): update dependency vite to v8.0.16
PHP Unit Tests / test (pull_request) Successful in 1m3s
JS Unit Tests / test (pull_request) Failing after 14m28s
Build Test / test (pull_request) Failing after 14m30s
2026-06-20 03:07:13 +00:00
Sebastian 089c5db4e2 Merge pull request 'chore(deps): update dependency vuetify to v4.1.1' (#32) from renovate/vuetify-4.x-lockfile into main
Reviewed-on: #32
2026-06-16 17:40:36 +00:00
Sebastian 8c767b3481 Merge pull request 'chore(deps): update dependency vue-router to v5.1.0' (#33) from renovate/vue-router-5.x-lockfile into main
Reviewed-on: #33
2026-06-16 17:40:26 +00:00
Sebastian 947a1ec246 Merge pull request 'chore(deps): update vue monorepo to v3.5.38' (#30) from renovate/vue-monorepo into main
Reviewed-on: #30
2026-06-16 17:40:15 +00:00
Sebastian 5c52ba177e Merge pull request 'chore(deps): update vue-language-tools monorepo to v3.3.5' (#31) from renovate/vue-language-tools-monorepo into main
Reviewed-on: #31
2026-06-16 17:38:17 +00:00
Sebastian 2f0e5d83b7 Merge pull request 'feat: message send' (#34) from feat/message-send into main
Reviewed-on: #34
2026-06-16 17:34:38 +00:00
Sebastian a6d1ba5f10 feat: message send
Build Test / test (pull_request) Successful in 37s
JS Unit Tests / test (pull_request) Successful in 36s
PHP Unit Tests / test (pull_request) Successful in 59s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-16 13:34:11 -04:00
Sebastian 17d3115374 chore(deps): update vue-language-tools monorepo to v3.3.5
Build Test / test (pull_request) Successful in 33s
JS Unit Tests / test (pull_request) Successful in 32s
PHP Unit Tests / test (pull_request) Successful in 1m7s
2026-06-14 03:03:36 +00:00
Sebastian 46b2e97d4b chore(deps): update dependency vuetify to v4.1.1
JS Unit Tests / test (pull_request) Successful in 39s
Build Test / test (pull_request) Successful in 43s
PHP Unit Tests / test (pull_request) Successful in 1m7s
2026-06-09 03:04:59 +00:00
Sebastian bcc277eec8 chore(deps): update dependency vue-router to v5.1.0
Build Test / test (pull_request) Successful in 45s
JS Unit Tests / test (pull_request) Successful in 44s
PHP Unit Tests / test (pull_request) Successful in 46s
2026-06-01 03:05:37 +00:00
26 changed files with 2767 additions and 1617 deletions
@@ -0,0 +1,59 @@
name: PHP Integration Tests
on:
pull_request:
workflow_dispatch:
jobs:
test:
name: Integration Tests
runs-on: ubuntu-latest
services:
mongo:
image: mongo:8
options: >-
--health-cmd "mongosh --quiet --eval \"db.adminCommand('ping')\""
--health-interval 5s
--health-timeout 5s
--health-retries 12
steps:
- name: Retrieve Server Install Action
uses: actions/checkout@v6.0.2
with:
repository: Nodarx/action-server-install
ref: main
path: action-server-install
github-server-url: https://git.ktrix.dev
- name: Install server
uses: ./action-server-install
with:
install-php: 'true'
php-version: '8.5'
server-path: './server'
database-uri: 'mongodb://mongo:27017/?tls=false'
database-name: 'ktrix_ci'
app-environment: 'test'
- name: Checkout module under test
uses: actions/checkout@v6.0.2
with:
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}
path: server/modules/provider_jmapc
github-server-url: https://git.ktrix.dev
- name: Install module dependencies
run: composer install --prefer-dist --no-progress
working-directory: server/modules/provider_jmapc
- name: Install and enable module
working-directory: server
run: |
php bin/console module:install provider_jmapc
php bin/console module:enable provider_jmapc
- name: Run integration tests
working-directory: server/modules/provider_jmapc
run: composer test:integration
+8 -2
View File
@@ -25,11 +25,17 @@ jobs:
tools: composer:v2 tools: composer:v2
- name: Install Renovate - name: Install Renovate
run: npm install -g renovate run: |
npm install --global --no-audit --fund=false \
--prefix "${{ runner.temp }}/renovate-npm" \
--cache "${{ runner.temp }}/renovate-npm-cache" \
renovate
"${{ runner.temp }}/renovate-npm/bin/renovate" --version
- name: Run Renovate - name: Run Renovate
env: env:
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
RENOVATE_PLATFORM: gitea RENOVATE_PLATFORM: gitea
RENOVATE_ENDPOINT: https://git.ktrix.dev/api/v1 RENOVATE_ENDPOINT: https://git.ktrix.dev/api/v1
run: renovate ${{ gitea.repository }} run: |
"${{ runner.temp }}/renovate-npm/bin/renovate" ${{ gitea.repository }}
+1 -5
View File
@@ -14,11 +14,7 @@ node_modules/
# Backend development # Backend development
/lib/vendor/ /lib/vendor/
coverage/ coverage/
phpunit.xml.cache *.cache
.phpunit.cache
.phpunit.result.cache
.php-cs-fixer.cache
.phpstan.cache
.phpactor/ .phpactor/
# Editors # Editors
+8 -5
View File
@@ -10,7 +10,7 @@
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,
"platform": { "platform": {
"php": "8.2" "php": "8.3"
}, },
"autoloader-suffix": "ProviderJmapc", "autoloader-suffix": "ProviderJmapc",
"vendor-dir": "lib/vendor", "vendor-dir": "lib/vendor",
@@ -25,11 +25,13 @@
} }
], ],
"require": { "require": {
"php": ">=8.2 <=8.5", "guzzlehttp/guzzle": "^7.0",
"guzzlehttp/psr7": "^2.0",
"php": ">=8.3 <=8.5",
"sebastiankrupinski/jmap-client-php": "dev-main" "sebastiankrupinski/jmap-client-php": "dev-main"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^11.0" "phpunit/phpunit": "^12.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@@ -46,7 +48,8 @@
], ],
"post-update-cmd": [ "post-update-cmd": [
], ],
"test:unit": "phpunit --configuration tests/php/phpunit.unit.xml --colors=always --testdox", "test:unit": "phpunit --configuration tests/php/phpunit.xml --testsuite \"Unit Tests\" --colors=always --testdox",
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.unit.xml --coverage-html .phpunit.coverage --coverage-text" "test:integration": "phpunit --configuration tests/php/phpunit.xml --testsuite \"Integration Tests\" --colors=always --testdox",
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.xml --testsuite \"Unit Tests\" --coverage-html .phpunit.coverage --coverage-text"
} }
} }
Generated
+486 -401
View File
File diff suppressed because it is too large Load Diff
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use KTXF\Resource\Documents\Collection\CollectionPropertiesMutableAbstract; use KTXF\Documents\Collection\CollectionPropertiesMutableAbstract;
/** /**
* Document Collection Properties Implementation * Document Collection Properties Implementation
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use KTXF\Resource\Documents\Collection\CollectionMutableAbstract; use KTXF\Documents\Collection\CollectionMutableAbstract;
/** /**
* Document Collection Resource Implementation * Document Collection Resource Implementation
+8 -8
View File
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use KTXF\Resource\Documents\Entity\EntityPropertiesMutableAbstract; use KTXF\Documents\Entity\EntityPropertiesMutableAbstract;
/** /**
* Document Collection Properties Implementation * Document Collection Properties Implementation
@@ -24,23 +24,23 @@ class EntityProperties extends EntityPropertiesMutableAbstract {
public function fromJmap(array $parameters): static { public function fromJmap(array $parameters): static {
if (isset($data['size'])) { 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'])) { 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'])) { 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'])) { if (isset($data['format'])) {
$this->data[self::JSON_PROPERTY_FORMAT] = null; $this->data[self::PROPERTY_FORMAT] = null;
} }
if (isset($data['encoding'])) { if (isset($data['encoding'])) {
$this->data[self::JSON_PROPERTY_ENCODING] = null; $this->data[self::PROPERTY_ENCODING] = null;
} }
return $this; return $this;
@@ -52,8 +52,8 @@ class EntityProperties extends EntityPropertiesMutableAbstract {
public function toJmap(): array { public function toJmap(): array {
$parameters = array_filter([ $parameters = array_filter([
'name' => $this->data[self::JSON_PROPERTY_LABEL], 'name' => $this->data[self::PROPERTY_LABEL],
'type' => $this->data[self::JSON_PROPERTY_MIME] ?? 'application/octet-stream' 'type' => $this->data[self::PROPERTY_MIME] ?? 'application/octet-stream'
], static fn($value) => $value !== null); ], static fn($value) => $value !== null);
return $parameters; return $parameters;
+1 -1
View File
@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use KTXF\Resource\Documents\Entity\EntityMutableAbstract; use KTXF\Documents\Entity\EntityMutableAbstract;
/** /**
* Mail Entity Resource Implementation * Mail Entity Resource Implementation
+13 -13
View File
@@ -9,11 +9,11 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use KTXF\Resource\Documents\Provider\ProviderBaseInterface; use KTXF\Documents\Provider\ProviderBaseInterface;
use KTXF\Resource\Documents\Provider\ProviderServiceMutateInterface; use KTXF\Documents\Provider\ProviderServiceMutateInterface;
use KTXF\Resource\Documents\Provider\ProviderServiceTestInterface; use KTXF\Documents\Provider\ProviderServiceTestInterface;
use KTXF\Resource\Documents\Service\ServiceBaseInterface; use KTXF\Documents\Service\ServiceBaseInterface;
use KTXF\Resource\Documents\Service\ServiceMutableInterface; use KTXF\Documents\Service\ServiceMutableInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface;
use KTXF\Resource\Provider\ResourceServiceMutateInterface; use KTXF\Resource\Provider\ResourceServiceMutateInterface;
use KTXM\ProviderJmapc\Service\Discovery; use KTXM\ProviderJmapc\Service\Discovery;
@@ -21,9 +21,9 @@ use KTXM\ProviderJmapc\Service\Remote\RemoteService;
use KTXM\ProviderJmapc\Stores\ServiceStore; use KTXM\ProviderJmapc\Stores\ServiceStore;
/** /**
* JMAP Mail Provider * JMAP Documents Provider
*/ */
class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInterface class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, ProviderServiceTestInterface
{ {
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE; public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
@@ -49,10 +49,10 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInt
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
self::JSON_PROPERTY_TYPE => self::JSON_TYPE, self::PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER, self::PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL, self::PROPERTY_LABEL => self::PROVIDER_LABEL,
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities, self::PROPERTY_CAPABILITIES => $this->providerAbilities,
]; ];
} }
@@ -63,7 +63,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInt
public function type(): string public function type(): string
{ {
return self::TYPE_MAIL; return self::TYPE_DOCUMENT;
} }
public function identifier(): string public function identifier(): string
@@ -170,7 +170,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInt
return $discovery->discover($identity, $location, $secret, $verifySSL); 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); $startTime = microtime(true);
try { try {
+91 -71
View File
@@ -10,17 +10,20 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Document; namespace KTXM\ProviderJmapc\Providers\Document;
use Generator; use Generator;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Documents\Collection\CollectionBaseInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Documents\Collection\CollectionMutableInterface;
use KTXF\Documents\Collection\CollectionPropertiesBaseInterface;
use KTXF\Documents\Service\ServiceBaseInterface;
use KTXF\Documents\Service\ServiceCollectionMutableInterface;
use KTXF\Documents\Service\ServiceConfigurableInterface;
use KTXF\Documents\Service\ServiceMutableInterface;
use KTXF\Resource\Delta\Delta; use KTXF\Resource\Delta\Delta;
use KTXF\Resource\Documents\Collection\CollectionBaseInterface;
use KTXF\Resource\Documents\Collection\CollectionMutableInterface;
use KTXF\Resource\Documents\Service\ServiceBaseInterface;
use KTXF\Resource\Documents\Service\ServiceCollectionMutableInterface;
use KTXF\Resource\Documents\Service\ServiceConfigurableInterface;
use KTXF\Resource\Documents\Service\ServiceMutableInterface;
use KTXF\Resource\Filter\Filter; use KTXF\Resource\Filter\Filter;
use KTXF\Resource\Filter\IFilter; use KTXF\Resource\Filter\IFilter;
use KTXF\Resource\Identifier\CollectionIdentifierInterface;
use KTXF\Resource\Identifier\EntityIdentifierInterface;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
use KTXF\Resource\Range\IRange; use KTXF\Resource\Range\IRange;
use KTXF\Resource\Range\Range; use KTXF\Resource\Range\Range;
use KTXF\Resource\Range\RangeType; use KTXF\Resource\Range\RangeType;
@@ -125,15 +128,15 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
public function jsonSerialize(): array { public function jsonSerialize(): array {
return array_filter([ return array_filter([
self::JSON_PROPERTY_TYPE => self::JSON_TYPE, self::PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER, self::PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
self::JSON_PROPERTY_IDENTIFIER => $this->serviceIdentifier, self::PROPERTY_IDENTIFIER => $this->serviceIdentifier,
self::JSON_PROPERTY_LABEL => $this->serviceLabel, self::PROPERTY_LABEL => $this->serviceLabel,
self::JSON_PROPERTY_ENABLED => $this->serviceEnabled, self::PROPERTY_ENABLED => $this->serviceEnabled,
self::JSON_PROPERTY_CAPABILITIES => $this->serviceAbilities, self::PROPERTY_CAPABILITIES => $this->serviceAbilities,
self::JSON_PROPERTY_LOCATION => $this->location?->jsonSerialize(), self::PROPERTY_LOCATION => $this->location?->jsonSerialize(),
self::JSON_PROPERTY_IDENTITY => $this->identity?->jsonSerialize(), self::PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
self::JSON_PROPERTY_AUXILIARY => $this->auxiliary, self::PROPERTY_AUXILIARY => $this->auxiliary,
], fn($v) => $v !== null); ], fn($v) => $v !== null);
} }
@@ -142,20 +145,20 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} }
if (isset($data[self::JSON_PROPERTY_LABEL])) { if (isset($data[self::PROPERTY_LABEL])) {
$this->setLabel($data[self::JSON_PROPERTY_LABEL]); $this->setLabel($data[self::PROPERTY_LABEL]);
} }
if (isset($data[self::JSON_PROPERTY_ENABLED])) { if (isset($data[self::PROPERTY_ENABLED])) {
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]); $this->setEnabled($data[self::PROPERTY_ENABLED]);
} }
if (isset($data[self::JSON_PROPERTY_LOCATION])) { if (isset($data[self::PROPERTY_LOCATION])) {
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION])); $this->setLocation($this->freshLocation(null, $data[self::PROPERTY_LOCATION]));
} }
if (isset($data[self::JSON_PROPERTY_IDENTITY])) { if (isset($data[self::PROPERTY_IDENTITY])) {
$this->setIdentity($this->freshIdentity(null, $data[self::JSON_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])) { if (isset($data[self::PROPERTY_AUXILIARY]) && is_array($data[self::PROPERTY_AUXILIARY])) {
$this->setAuxiliary($data[self::JSON_PROPERTY_AUXILIARY]); $this->setAuxiliary($data[self::PROPERTY_AUXILIARY]);
} }
return $this; return $this;
@@ -316,18 +319,30 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return new CollectionResource(provider: $this->provider(), service: $this->identifier()); return new CollectionResource(provider: $this->provider(), service: $this->identifier());
} }
public function collectionCreate(string|int|null $location, CollectionMutableInterface $collection, array $options = []): CollectionBaseInterface /**
* Convert incoming collection properties into a native CollectionResource
*/
private function collectionNative(CollectionPropertiesBaseInterface $properties, string|int|null $identifier = null): CollectionResource
{
if ($properties instanceof CollectionResource) {
return clone $properties;
}
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
$object->jsonDeserialize(array_filter([
CollectionResource::PROPERTY_IDENTIFIER => $identifier,
CollectionResource::PROPERTY_PROPERTIES => $properties->jsonSerialize(),
], fn($v) => $v !== null));
return $object;
}
public function collectionCreate(CollectionIdentifierInterface|null $target, CollectionPropertiesBaseInterface $properties, array $options = []): CollectionBaseInterface
{ {
$this->initialize(); $this->initialize();
if ($collection instanceof CollectionResource === false) { $collection = $this->collectionNative($properties);
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
$object->jsonDeserialize($collection->jsonSerialize());
$collection = $object;
}
$collection = $collection->toJmap(); $collection = $collection->toJmap();
$collection = $this->remoteService->collectionCreate($location, $collection, $options); $collection = $this->remoteService->collectionCreate($target?->collection(), $collection, $options);
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier()); $object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
$object->fromJmap($collection); $object->fromJmap($collection);
@@ -335,15 +350,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $object; return $object;
} }
public function collectionUpdate(string|int $identifier, CollectionMutableInterface $collection): CollectionBaseInterface public function collectionUpdate(CollectionIdentifierInterface $target, CollectionPropertiesBaseInterface $properties): CollectionBaseInterface
{ {
$this->initialize(); $this->initialize();
if ($collection instanceof CollectionResource === false) { $identifier = $target->collection();
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier()); $collection = $this->collectionNative($properties, $identifier);
$object->jsonDeserialize($collection->jsonSerialize());
$collection = $object;
}
$collection = $collection->toJmap(); $collection = $collection->toJmap();
$collection = $this->remoteService->collectionModify($identifier, $collection); $collection = $this->remoteService->collectionModify($identifier, $collection);
@@ -354,14 +366,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $object; return $object;
} }
public function collectionDelete(string|int $identifier, bool $force = false, bool $recursive = false): bool public function collectionDelete(CollectionIdentifierInterface $target, bool $force = false): CollectionBaseInterface | true
{ {
$this->initialize(); $this->initialize();
return $this->remoteService->collectionDestroy($identifier, $force, $recursive) !== null; if ($this->remoteService->collectionDestroy($target->collection(), $force, $force) === null) {
throw new \RuntimeException("Failed to delete collection: {$target->collection()}");
}
return true;
} }
public function collectionMove(string|int $identifier, string|int|null $targetLocation): CollectionBaseInterface public function collectionMove(CollectionIdentifierInterface|null $target, CollectionIdentifierInterface $source): CollectionBaseInterface
{ {
// TODO: Implement collection move // TODO: Implement collection move
$this->initialize(); $this->initialize();
@@ -369,12 +384,20 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $collection; return $collection;
} }
public function collectionCopy(CollectionIdentifierInterface|null $target, CollectionIdentifierInterface $source): CollectionBaseInterface
{
// TODO: Implement collection copy
$this->initialize();
$collection = new CollectionResource(provider: $this->provider(), service: $this->identifier());
return $collection;
}
// Entity operations // Entity operations
public function entityList(string|int|null $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array public function entityListBulk(string|int|null $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
{ {
$this->initialize(); $this->initialize();
$result = $this->remoteService->entityList($collection, $filter, $sort, $range, $properties); $result = $this->remoteService->entityList($collection, $filter, $sort, $range, $properties);
$list = []; $list = [];
@@ -390,7 +413,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $list; return $list;
} }
public function entityListStream(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator public function entityListStream(string|int|null $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator
{ {
$this->initialize(); $this->initialize();
@@ -421,11 +444,11 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return new Range(); return new Range();
} }
public function entityDelta(string|int|null $collection, string $signature, string $detail = 'ids'): Delta public function entityDelta(string|int|null $collection, string $signature): Delta
{ {
$this->initialize(); $this->initialize();
return $this->remoteService->entityDelta($collection, $signature, $detail); return $this->remoteService->entityDelta($collection, $signature, 'ids');
} }
public function entityExtant(string|int|null $collection, string|int ...$identifiers): array public function entityExtant(string|int|null $collection, string|int ...$identifiers): array
@@ -435,48 +458,45 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $this->remoteService->entityExtant(...$identifiers); return $this->remoteService->entityExtant(...$identifiers);
} }
public function entityFetch(string|int|null $collection, string|int ...$identifiers): array public function entityFetchBulk(EntityIdentifierInterface ...$identifiers): array
{ {
$this->initialize(); $this->initialize();
$entities = $this->remoteService->entityFetch(...$identifiers); $entityIds = array_map(fn($identifier) => $identifier->entity(), $identifiers);
$entities = $this->remoteService->entityFetch(...$entityIds);
foreach ($entities as &$entity) {
$list = [];
foreach ($entities as $key => $entity) {
if (is_array($entity) && isset($entity['id'])) { if (is_array($entity) && isset($entity['id'])) {
$object = new EntityResource(provider: $this->provider(), service: $this->identifier()); $object = new EntityResource(provider: $this->provider(), service: $this->identifier());
$object->fromJmap($entity); $object->fromJmap($entity);
$entity = $object; $list[$object->identifier()] = $object;
} else {
$list[$key] = $entity;
} }
} }
return $entities; return $list;
} }
public function entityRead(string|int|null $collection, string|int $identifier): ?string public function entityFetchStream(EntityIdentifierInterface ...$identifiers): Generator
{
yield from $this->entityFetchBulk(...$identifiers);
}
public function entityRead(EntityIdentifierInterface $target): ?string
{ {
return null; return null;
} }
// Node operations public function entityReadStream(EntityIdentifierInterface $target)
public function nodeList(string|int|null $collection, bool $recursive = false, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
{ {
return []; return null;
} }
public function nodeListFilter(): IFilter public function entityReadChunk(EntityIdentifierInterface $target, int $offset, int $length): ?string
{ {
return new Filter(['']); return null;
}
public function nodeListSort(): ISort
{
return new Sort(['']);
}
public function nodeDelta(string|int|null $collection, string $signature, string $detail = 'ids'): Delta
{
return new Delta();
} }
} }
-186
View File
@@ -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;
}
}
}
+149 -33
View File
@@ -16,6 +16,142 @@ use KTXF\Mail\Object\MessagePropertiesMutableAbstract;
*/ */
class MessageProperties extends 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 * Convert JMAP parameters array to mail message properties object
* *
@@ -135,7 +271,7 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
$this->data[static::PROPERTY_FLAGS] = []; $this->data[static::PROPERTY_FLAGS] = [];
foreach ($parameters['keywords'] as $keyword => $value) { foreach ($parameters['keywords'] as $keyword => $value) {
$flag = match($keyword) { $flag = match($keyword) {
'$seen' => 'read', '$seen' => 'seen',
'$flagged' => 'flagged', '$flagged' => 'flagged',
'$answered' => 'answered', '$answered' => 'answered',
'$draft' => 'draft', '$draft' => 'draft',
@@ -162,11 +298,11 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
if (isset($this->data['size'])) { if (isset($this->data['size'])) {
$parameters['size'] = $this->data['size']; $parameters['size'] = $this->data['size'];
} }
if (isset($this->data['receivedDate'])) { if (isset($this->data['received'])) {
$parameters['receivedAt'] = $this->data['receivedDate']; $parameters['receivedAt'] = $this->data['received'];
} }
if (isset($this->data['date'])) { if (isset($this->data['sent'])) {
$parameters['sentAt'] = $this->data['date']; $parameters['sentAt'] = $this->data['sent'];
} }
if (isset($this->data['inReplyTo'])) { if (isset($this->data['inReplyTo'])) {
$parameters['inReplyTo'] = $this->data['inReplyTo']; $parameters['inReplyTo'] = $this->data['inReplyTo'];
@@ -229,7 +365,7 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
$parameters['keywords'] = []; $parameters['keywords'] = [];
foreach ($this->data['flags'] as $flag => $value) { foreach ($this->data['flags'] as $flag => $value) {
$keyword = match($flag) { $keyword = match($flag) {
'read' => '$seen', 'seen' => '$seen',
'flagged' => '$flagged', 'flagged' => '$flagged',
'answered' => '$answered', 'answered' => '$answered',
'draft' => '$draft', 'draft' => '$draft',
@@ -239,37 +375,17 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
$parameters['keywords'][$keyword] = $value; $parameters['keywords'][$keyword] = $value;
} }
} }
if (isset($this->data['bodyStructure'])) {
$parameters['bodyStructure'] = $this->data['bodyStructure']; $bodyValues = [];
} $bodyStructure = $this->buildJmapBodyStructure($bodyValues);
if (isset($this->data['body'])) { if ($bodyStructure !== null) {
$parameters['bodyValues'] = []; $parameters['bodyStructure'] = $bodyStructure;
$parameters['bodyValues'] = $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
];
}
} }
if (isset($this->data['headers'])) { if (isset($this->data['headers'])) {
$parameters['headers'] = $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; return $parameters;
} }
+66 -10
View File
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Mail; namespace KTXM\ProviderJmapc\Providers\Mail;
use KTXF\Mail\Object\Address;
use KTXF\Mail\Provider\ProviderBaseInterface; use KTXF\Mail\Provider\ProviderBaseInterface;
use KTXF\Mail\Provider\ProviderServiceDiscoverInterface; use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
use KTXF\Mail\Provider\ProviderServiceMutateInterface; use KTXF\Mail\Provider\ProviderServiceMutateInterface;
@@ -21,9 +22,6 @@ use KTXM\ProviderJmapc\Service\Discovery;
use KTXM\ProviderJmapc\Service\Remote\RemoteService; use KTXM\ProviderJmapc\Service\Remote\RemoteService;
use KTXM\ProviderJmapc\Stores\ServiceStore; use KTXM\ProviderJmapc\Stores\ServiceStore;
/**
* JMAP Mail Provider
*/
class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
{ {
@@ -49,10 +47,10 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return [ return [
self::JSON_PROPERTY_TYPE => self::JSON_TYPE, self::PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER, self::PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL, self::PROPERTY_LABEL => self::PROVIDER_LABEL,
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities, self::PROPERTY_CAPABILITIES => $this->providerAbilities,
]; ];
} }
@@ -145,7 +143,64 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
} }
$created = $this->serviceStore->create($tenantId, $userId, $service); $created = $this->serviceStore->create($tenantId, $userId, $service);
return (string) $created['id']; $this->serviceIdentitiesSync($tenantId, $userId, (new Service())->fromStore($created));
return (string) $created['sid'];
}
/**
* Fetches sending identities from the JMAP server and overwrites
* primaryAddress/secondaryAddresses on the service with them.
*/
private function serviceIdentitiesSync(string $tenantId, string $userId, Service $service): void
{
try {
$client = RemoteService::freshClient($service);
$identities = RemoteService::mailService($client)->identityFetch();
// A JMAP server may expose multiple identities sharing the same
// address (e.g. distinct signatures/display names for one
// mailbox) — collapse those down to one entry per address,
// keeping the first label seen.
$addresses = [];
foreach ($identities as $identity) {
if ($identity->address() === null) {
continue;
}
$key = strtolower($identity->address());
if (!isset($addresses[$key])) {
$addresses[$key] = Address::fromArray(['address' => $identity->address(), 'label' => $identity->name()]);
}
}
$addresses = array_values($addresses);
if (empty($addresses)) {
return;
}
$currentAddress = strtolower($service->getPrimaryAddress()->getAddress());
$primaryIndex = 0;
foreach ($addresses as $index => $address) {
if (strtolower($address->getAddress()) === $currentAddress) {
$primaryIndex = $index;
break;
}
}
$secondary = [];
foreach ($addresses as $index => $address) {
if ($index !== $primaryIndex) {
$secondary[] = $address;
}
}
$service->setPrimaryAddress($addresses[$primaryIndex]);
$service->setSecondaryAddresses($secondary);
$this->serviceStore->modify($tenantId, $userId, $service);
} catch (\Throwable) {
// Server may not support urn:ietf:params:jmap:submission, or have
// no identities configured — fall back to what the user entered.
}
} }
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
@@ -154,8 +209,9 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
throw new \InvalidArgumentException('Service must be instance of JMAP Service'); throw new \InvalidArgumentException('Service must be instance of JMAP Service');
} }
$updated = $this->serviceStore->modify($tenantId, $userId, $service); $this->serviceStore->modify($tenantId, $userId, $service);
return (string) $updated['sid']; $this->serviceIdentitiesSync($tenantId, $userId, $service);
return (string) $service->identifier();
} }
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
+320 -86
View File
@@ -12,7 +12,6 @@ namespace KTXM\ProviderJmapc\Providers\Mail;
use Generator; use Generator;
use KTXF\Mail\Collection\CollectionBaseInterface; use KTXF\Mail\Collection\CollectionBaseInterface;
use KTXF\Mail\Collection\CollectionRoles; use KTXF\Mail\Collection\CollectionRoles;
use KTXF\Mail\Collection\CollectionMutableInterface;
use KTXF\Mail\Collection\CollectionPropertiesBaseInterface; use KTXF\Mail\Collection\CollectionPropertiesBaseInterface;
use KTXF\Mail\Object\Address; use KTXF\Mail\Object\Address;
use KTXF\Mail\Object\AddressInterface; use KTXF\Mail\Object\AddressInterface;
@@ -21,7 +20,9 @@ use KTXF\Mail\Service\ServiceBaseInterface;
use KTXF\Mail\Service\ServiceCollectionMutableInterface; use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface; use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface; use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceEntitySubmitInterface;
use KTXF\Mail\Service\ServiceMutableInterface; use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Mail\Submission\EntitySubmitResult;
use KTXF\Resource\BinaryResource; use KTXF\Resource\BinaryResource;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface;
@@ -41,7 +42,7 @@ use KTXM\ProviderJmapc\Providers\ServiceLocation;
use KTXM\ProviderJmapc\Service\Remote\RemoteMailService; use KTXM\ProviderJmapc\Service\Remote\RemoteMailService;
use KTXM\ProviderJmapc\Service\Remote\RemoteService; use KTXM\ProviderJmapc\Service\Remote\RemoteService;
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface, ServiceEntityMutableInterface class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface, ServiceEntityMutableInterface, ServiceEntitySubmitInterface
{ {
private const PROVIDER_IDENTIFIER = 'jmap'; private const PROVIDER_IDENTIFIER = 'jmap';
@@ -51,7 +52,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
private ?string $serviceIdentifier = null; private ?string $serviceIdentifier = null;
private ?string $serviceLabel = null; private ?string $serviceLabel = null;
private bool $serviceEnabled = false; private bool $serviceEnabled = false;
private string $primaryAddress = ''; private array $primaryAddress = [];
private array $secondaryAddresses = []; private array $secondaryAddresses = [];
private ?ServiceLocation $location = null; private ?ServiceLocation $location = null;
private ?ServiceIdentityBasic $identity = null; private ?ServiceIdentityBasic $identity = null;
@@ -107,6 +108,9 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
self::CAPABILITY_ENTITY_DELETE => true, self::CAPABILITY_ENTITY_DELETE => true,
self::CAPABILITY_ENTITY_MOVE => true, self::CAPABILITY_ENTITY_MOVE => true,
self::CAPABILITY_ENTITY_COPY => false, self::CAPABILITY_ENTITY_COPY => false,
self::CAPABILITY_ENTITY_SUBMIT_FRESH => true,
self::CAPABILITY_ENTITY_SUBMIT_DRAFT => true,
'EntityTransmit' => true,
]; ];
private readonly RemoteMailService $mailService; private readonly RemoteMailService $mailService;
@@ -170,17 +174,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
public function jsonSerialize(): array public function jsonSerialize(): array
{ {
return array_filter([ return array_filter([
self::JSON_PROPERTY_TYPE => self::JSON_TYPE, self::PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER, self::PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
self::JSON_PROPERTY_IDENTIFIER => $this->serviceIdentifier, self::PROPERTY_IDENTIFIER => $this->serviceIdentifier,
self::JSON_PROPERTY_LABEL => $this->serviceLabel, self::PROPERTY_LABEL => $this->serviceLabel,
self::JSON_PROPERTY_ENABLED => $this->serviceEnabled, self::PROPERTY_ENABLED => $this->serviceEnabled,
self::JSON_PROPERTY_CAPABILITIES => $this->serviceAbilities, self::PROPERTY_CAPABILITIES => $this->serviceAbilities,
self::JSON_PROPERTY_PRIMARY_ADDRESS => $this->primaryAddress, self::PROPERTY_PRIMARY_ADDRESS => $this->primaryAddress,
self::JSON_PROPERTY_SECONDARY_ADDRESSES => $this->secondaryAddresses, self::PROPERTY_SECONDARY_ADDRESSES => $this->secondaryAddresses,
self::JSON_PROPERTY_LOCATION => $this->location?->jsonSerialize(), self::PROPERTY_LOCATION => $this->location?->jsonSerialize(),
self::JSON_PROPERTY_IDENTITY => $this->identity?->jsonSerialize(), self::PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
self::JSON_PROPERTY_AUXILIARY => $this->auxiliary, self::PROPERTY_AUXILIARY => $this->auxiliary,
], fn($v) => $v !== null); ], fn($v) => $v !== null);
} }
@@ -190,29 +194,30 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} }
if (isset($data[self::JSON_PROPERTY_ENABLED])) { if (isset($data[self::PROPERTY_ENABLED])) {
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]); $this->setEnabled($data[self::PROPERTY_ENABLED]);
} }
if (isset($data[self::JSON_PROPERTY_LABEL])) { if (isset($data[self::PROPERTY_LABEL])) {
$this->setLabel($data[self::JSON_PROPERTY_LABEL]); $this->setLabel($data[self::PROPERTY_LABEL]);
} }
if (isset($data[self::JSON_PROPERTY_LOCATION])) { if (isset($data[self::PROPERTY_LOCATION])) {
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION])); $this->setLocation($this->freshLocation(null, $data[self::PROPERTY_LOCATION]));
} }
if (isset($data[self::JSON_PROPERTY_IDENTITY])) { if (isset($data[self::PROPERTY_IDENTITY])) {
$this->setIdentity($this->freshIdentity(null, $data[self::JSON_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])) { if (isset($data[self::PROPERTY_PRIMARY_ADDRESS])) {
$this->setPrimaryAddress(new Address($data[self::JSON_PROPERTY_PRIMARY_ADDRESS])); $value = $data[self::PROPERTY_PRIMARY_ADDRESS];
$this->setPrimaryAddress(is_array($value) ? Address::fromArray($value) : new Address((string)$value));
} }
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( $this->setSecondaryAddresses(array_map(
fn($addr) => new Address(is_array($addr) ? ($addr['address'] ?? $addr) : $addr), 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])) { if (isset($data[self::PROPERTY_AUXILIARY]) && is_array($data[self::PROPERTY_AUXILIARY])) {
$this->setAuxiliary($data[self::JSON_PROPERTY_AUXILIARY]); $this->setAuxiliary($data[self::PROPERTY_AUXILIARY]);
} }
return $this; return $this;
@@ -262,41 +267,47 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
public function getPrimaryAddress(): AddressInterface public function getPrimaryAddress(): AddressInterface
{ {
return new Address($this->primaryAddress); return Address::fromArray($this->primaryAddress);
} }
public function setPrimaryAddress(AddressInterface $value): static public function setPrimaryAddress(AddressInterface $value): static
{ {
$this->primaryAddress = $value->getAddress(); $this->primaryAddress = $value->toArray();
return $this; return $this;
} }
public function getSecondaryAddresses(): array 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 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; return $this;
} }
public function hasAddress(string $address): bool public function hasAddress(string $address): bool
{ {
$address = strtolower(trim($address)); $address = strtolower(trim($address));
if ($this->primaryAddress && strtolower($this->primaryAddress) === $address) { if ($this->primaryAddress && strtolower($this->primaryAddress['address'] ?? '') === $address) {
return true; return true;
} }
foreach ($this->secondaryAddresses as $secondary) {
foreach ($this->secondaryAddresses as $secondaryAddress) { $secondaryAddr = $secondary instanceof AddressInterface ? $secondary->getAddress() : (string) $secondary;
if (strtolower($secondaryAddress->getAddress()) === $address) { if (strtolower($secondaryAddr) === $address) {
return true; return true;
} }
} }
return false; return false;
} }
public function getLocation(): ServiceLocation public function getLocation(): ServiceLocation
@@ -384,13 +395,6 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []); return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []);
} }
public function collectionExtant(string|int ...$identifiers): array
{
$this->initialize();
return $this->mailService->collectionExtant(...$identifiers);
}
public function collectionFetch(string|int $identifier): ?CollectionResource public function collectionFetch(string|int $identifier): ?CollectionResource
{ {
$this->initialize(); $this->initialize();
@@ -407,6 +411,13 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $collection; return $collection;
} }
public function collectionExtant(string|int ...$identifiers): array
{
$this->initialize();
return $this->mailService->collectionExtant(...$identifiers);
}
public function collectionFresh(): CollectionResource public function collectionFresh(): CollectionResource
{ {
return new CollectionResource($this->provider(), $this->identifier()); return new CollectionResource($this->provider(), $this->identifier());
@@ -463,34 +474,44 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode"); throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
} }
// Move to target collection (e.g. Trash) instead of deleting $deleteTargetIdentifier = null;
if ($deleteMode === 'soft' && $deleteTarget !== null) { if ($deleteMode === 'soft') {
return $this->collectionMove(new CollectionIdentifier($target->provider(), $target->service(), $deleteTarget), $target); $deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
} ? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
if ($deleteMode === 'soft' && $deleteTarget === null) { if ($deleteTargetIdentifier === null) {
$filter = $this->collectionListFilter();
$filter->condition('role', CollectionRoles::Trash->value);
$mailboxes = iterator_to_array($this->mailService->collectionList(null, $filter, null));
if (empty($mailboxes)) {
throw new \RuntimeException('No Trash collection configured or found for deletion'); throw new \RuntimeException('No Trash collection configured or found for deletion');
} }
$deleteTarget = key($mailboxes);
} }
// we need to determine if the folder being deleted is already in the trash if ($deleteMode === 'soft') {
if (str_starts_with((string) $target->collection(), (string) $deleteTarget)) { $targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
// if so, we should hard delete instead of moving to avoid duplicates in the trash if ($targetMailbox === null) {
$deleteMode = 'hard'; throw new \RuntimeException('Collection not found for delete operation');
}
$targetIdentifier = (string) $target->collection();
$trashIdentifier = (string) $deleteTargetIdentifier->collection();
$parentIdentifier = isset($targetMailbox['parentId'])
? (string) $targetMailbox['parentId']
: null;
// JMAP mailbox IDs are opaque, so containment must be determined
// from parentId rather than by comparing ID prefixes.
if ($targetIdentifier === $trashIdentifier || $parentIdentifier === $trashIdentifier) {
$deleteMode = 'hard';
}
} }
$result = match ($deleteMode) { if ($deleteMode === 'soft') {
'soft' => $this->collectionMove(new CollectionIdentifier($target->provider(), $target->service(), $deleteTarget), $target), return $this->collectionMove($deleteTargetIdentifier, $target);
'hard' => $this->mailService->collectionDestroy($target->collection(), $force), }
};
return $result; if ($this->mailService->collectionDestroy((string) $target->collection(), $force) === null) {
throw new \RuntimeException("Failed to delete collection: {$target->collection()}");
}
return true;
} }
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
@@ -638,7 +659,16 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
$patch = $this->mailService->entityFresh(); $patch = $this->mailService->entityFresh();
$flags = $properties->getFlags(); $flags = $properties->getFlags();
foreach ($flags as $flag => $value) { foreach ($flags as $flag => $value) {
$patch->keyword($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);
} }
$dispositions = $this->mailService->entityPatch($patch, ...array_keys($targets)); $dispositions = $this->mailService->entityPatch($patch, ...array_keys($targets));
@@ -688,28 +718,18 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
// connect to remote store // connect to remote store
$this->initialize(); $this->initialize();
// attempt to find a target collection for soft deletion if none was specified $deleteTargetIdentifier = null;
if ($deleteMode === 'soft' && $deleteTarget === null) { if ($deleteMode === 'soft') {
$filter = $this->collectionListFilter(); $deleteTargetIdentifier = $deleteTarget !== null && (string) $deleteTarget !== ''
$filter->condition('role', CollectionRoles::Trash->value); ? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $deleteTarget)
: $this->resolveCollectionByRole(CollectionRoles::Trash->value);
$mailboxes = iterator_to_array($this->mailService->collectionList(null, $filter, null)); if ($deleteTargetIdentifier === null) {
if (empty($mailboxes)) {
throw new \RuntimeException('No Trash collection configured or found for deletion'); throw new \RuntimeException('No Trash collection configured or found for deletion');
} }
$targetMailbox = reset($mailboxes);
if ($targetMailbox === false) {
throw new \RuntimeException('No Trash collection configured or found for deletion');
}
$deleteTargetNative = $targetMailbox->id();
$deleteTargetIdentifier = new CollectionIdentifier($this->provider(), (string) $this->identifier(), $deleteTargetNative);
} else {
$deleteTargetNative = $deleteTarget;
$deleteTargetIdentifier = new CollectionIdentifier($this->provider(), (string) $this->identifier(), $deleteTargetNative);
} }
$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 // if all targets are already in the delete target collection, we should hard delete instead of moving to avoid duplicates in the trash
$targetCollections = []; $targetCollections = [];
foreach ($targets as $target) { foreach ($targets as $target) {
@@ -814,6 +834,219 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return []; 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()),
);
}
$nativeProperties = $this->normalizeMessageProperties($message);
$attachments = $nativeProperties->getAttachments();
foreach ($attachments as $attachment) {
if ($attachment->getBlobId() !== null) {
continue;
}
$content = $attachment->getContent();
if ($content === null) {
throw new \InvalidArgumentException(sprintf(
'Attachment "%s" has neither content nor a JMAP blob identifier',
$attachment->getName() ?? 'unnamed',
));
}
$attachment->setBlobId($this->mailService->blobDeposit(
$attachment->getType() ?? 'application/octet-stream',
$content,
));
}
if ($attachments !== []) {
$nativeProperties->setAttachments(...$attachments);
}
$nativeMessage = $nativeProperties->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 private function mapEntities(EntityIdentifier ...$identifiers): array
{ {
$list = []; $list = [];
@@ -825,4 +1058,5 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
} }
return $list; return $list;
} }
} }
+1 -1
View File
@@ -97,7 +97,7 @@ class Provider implements IProviderBase, IProviderServiceMutate
} }
// Note: This simplified interface doesn't pass tenantId // Note: This simplified interface doesn't pass tenantId
// Will need to get it from SessionTenant in actual implementation // Will need to get it from TenantContextInterface in actual implementation
throw new \RuntimeException('Use Mail Provider interface for service creation'); throw new \RuntimeException('Use Mail Provider interface for service creation');
} }
+106 -78
View File
@@ -908,99 +908,127 @@ class RemoteMailService {
} }
/** /**
* send entity * Submit a fresh message by creating it as a draft and then creating a submission.
*
* @since Release 1.0.0
* *
* @since Release 2.0.0
*/ */
public function entitySend(string $identity, MailMessageObject $message, ?string $presendLocation = null, ?string $postsendLocation = null): string { public function entitySubmitFresh(string $identityId, array $data, string $preSendTarget, string $postSentTarget): string {
// determine if pre-send location is present
if ($presendLocation === null || empty($presendLocation)) { $message = new MailParametersRequest();
throw new Exception('Pre-Send Location is missing', 1); $message->parametersRaw($data);
}
// determine if post-send location is present $messageId = 'm_' . uniqid();
if ($postsendLocation === null || empty($postsendLocation)) { $submissionId = 's_' . uniqid();
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 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->create('1', $message)->in($presendLocation); $m0 = $r0->create($messageId, $message);
// construct set request $m0->in($preSendTarget);
$m0->draft(true);
$m0->seen(true);
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
// construct envelope $r1->completionUpdate('#' . $messageId, [
$e1 = $r1->create('2'); 'mailboxIds/' . $postSentTarget => true,
$e1->identity($identity); 'mailboxIds/' . $preSendTarget => null,
$e1->message('#1'); 'keywords/$draft' => null,
$e1->from($from); ]);
$e1->to($to); $s0 = $r1->create($submissionId);
// transceive $s0->identity($identityId);
$s0->message('#' . $messageId);
$bundle = $this->dataStore->perform([$r0, $r1]); $bundle = $this->dataStore->perform([$r0, $r1]);
// extract response $messageResponse = $bundle->response(0);
$response = $bundle->response(1); if ($messageResponse instanceof ResponseException) {
// return collection information throw new Exception($messageResponse->type() . ': ' . $messageResponse->description(), 1);
return (string)$response->created()['2']['id']; }
} if (method_exists($messageResponse, 'createFailure')) {
$failure = $messageResponse->createFailure($messageId);
/** if (is_array($failure)) {
* retrieve collection entity attachment from remote storage $type = $failure['type'] ?? 'unknownError';
* $description = $failure['description'] ?? 'Email creation failed';
* @since Release 1.0.0 throw new Exception($type . ': ' . $description, 1);
*
*/
public function depositAttachmentsFromMessage(MailMessageObject $message): MailMessageObject {
$parameters = $message->toJmap();
$attachments = $message->getAttachments();
$matches = [];
$this->findAttachmentParts($parameters['bodyStructure'], $matches);
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);
} }
} }
return (new MailMessageObject())->fromJmap($parameters); $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, $submissionId);
} }
protected function findAttachmentParts(object &$part, array &$matches) { /**
* Upload attachment content and return its JMAP blob identifier.
if ($part->disposition === 'attachment' || $part->disposition === 'inline') { */
$matches[$part->partId] = $part; public function blobDeposit(string $type, string $data): string {
$response = json_decode($this->dataStore->upload($this->dataAccount, $type, $data), true);
if (!is_array($response) || !isset($response['blobId']) || !is_string($response['blobId']) || $response['blobId'] === '') {
throw new Exception('JMAP attachment upload did not return a blob identifier', 1);
} }
foreach ($part->subParts as $entry) { return $response['blobId'];
$this->findAttachmentParts($entry, $matches); }
/**
* 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 !== []) {
$m0 = new MailParametersRequest();
$m0->parametersRaw($patch);
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($draftId, $m0);
$requests[] = $r0;
}
$submissionId = 's_' . uniqid();
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$s0 = $r1->create($submissionId);
$s0->identity($identityId);
$s0->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, $submissionId);
}
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'];
}
}
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);
} }
/** /**
+23 -18
View File
@@ -9,16 +9,12 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Service\Remote; namespace KTXM\ProviderJmapc\Service\Remote;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Psr7\HttpFactory;
use JmapClient\Authentication\Basic; use JmapClient\Authentication\Basic;
use JmapClient\Authentication\Bearer;
use JmapClient\Authentication\JsonBasic;
use JmapClient\Authentication\JsonBasicCookie;
use JmapClient\Client as JmapClient; use JmapClient\Client as JmapClient;
use KTXC\Server; use KTXF\Security\Crypto;
use KTXF\Resource\Provider\ResourceServiceBaseInterface;
use KTXF\Resource\Provider\ResourceServiceIdentityBasic; use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
use KTXF\Resource\Provider\ResourceServiceIdentityBearer;
use KTXF\Resource\Provider\ResourceServiceIdentityOAuth;
use KTXF\Resource\Provider\ResourceServiceLocationUri; use KTXF\Resource\Provider\ResourceServiceLocationUri;
use KTXM\ProviderJmapc\Providers\Mail\Service as MailService; use KTXM\ProviderJmapc\Providers\Mail\Service as MailService;
use KTXM\ProviderJmapc\Providers\Contacts\Service as ContactsService; use KTXM\ProviderJmapc\Providers\Contacts\Service as ContactsService;
@@ -40,9 +36,6 @@ class RemoteService {
*/ */
public static function freshClient(MailService|FilesService $service): JmapClient { public static function freshClient(MailService|FilesService $service): JmapClient {
// defaults
$client = new JmapClient();
$client->setTransportAgent(self::$clientTransportAgent);
$location = $service->getLocation(); $location = $service->getLocation();
$identity = $service->getIdentity(); $identity = $service->getIdentity();
@@ -50,12 +43,23 @@ class RemoteService {
if ($location instanceof ResourceServiceLocationUri === false) { if ($location instanceof ResourceServiceLocationUri === false) {
throw new \InvalidArgumentException('Service location is not a valid URI'); 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->configureTransportMode($location->getScheme());
$client->setHost($location->getHost() . ':' . $location->getPort()); $client->setHost($location->getHost() . ':' . $location->getPort());
if (!empty($location->getPath())) { if (!empty($location->getPath())) {
$client->setDiscoveryPath($location->getPath()); $client->setDiscoveryPath($location->getPath());
} }
$client->configureTransportVerification((bool)$location->getVerifyPeer());
// authentication // authentication
if (($identity instanceof ResourceServiceIdentityBasic) === false) { if (($identity instanceof ResourceServiceIdentityBasic) === false) {
throw new \InvalidArgumentException('Service identity is not a valid Basic or Bearer authentication'); throw new \InvalidArgumentException('Service identity is not a valid Basic or Bearer authentication');
@@ -69,10 +73,13 @@ class RemoteService {
} }
// debugging // debugging
if ($service->getDebug()) { if ($service->getDebug()) {
$logDir = Server::getInstance()?->logDir(); $logDirectory = dirname(__DIR__, 5) . '/var/logs/jmap';
$logDir .= '/jmap/' . $service->identifier() . '.json'; if (!is_dir($logDirectory) && !mkdir($logDirectory, 0775, true) && !is_dir($logDirectory)) {
throw new \RuntimeException(sprintf('Unable to create JMAP log directory: %s', $logDirectory));
}
$logFile = $logDirectory . '/' . $service->identifier() . '.json';
$client->configureTransportLogState(true); $client->configureTransportLogState(true);
$client->configureTransportLogLocation($logDir); $client->configureTransportLogLocation($logFile);
} }
// return // return
return $client; return $client;
@@ -196,7 +203,7 @@ class RemoteService {
return $service; return $service;
} }
public static function cookieStoreRetrieve(mixed $id): ?array { public static function cookieStoreRetrieve(mixed $id, Crypto $crypto): ?array {
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
@@ -205,7 +212,6 @@ class RemoteService {
} }
$data = file_get_contents($file); $data = file_get_contents($file);
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
$data = $crypto->decrypt($data); $data = $crypto->decrypt($data);
if (!empty($data)) { if (!empty($data)) {
@@ -216,13 +222,12 @@ class RemoteService {
} }
public static function cookieStoreDeposit(mixed $id, array $value): void { public static function cookieStoreDeposit(mixed $id, array $value, Crypto $crypto): void {
if (empty($value)) { if (empty($value)) {
return; return;
} }
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
$data = $crypto->encrypt(json_encode($value)); $data = $crypto->encrypt(json_encode($value));
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
+1316 -639
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -18,7 +18,7 @@
"test:coverage": "vitest run --coverage --config tests/js/vitest.config.ts" "test:coverage": "vitest run --coverage --config tests/js/vitest.config.ts"
}, },
"dependencies": { "dependencies": {
"pinia": "^3.0.0", "pinia": "^4.0.0",
"vue": "^3.5.18", "vue": "^3.5.18",
"vue-router": "^5.0.0", "vue-router": "^5.0.0",
"vuetify": "^4.0.0" "vuetify": "^4.0.0"
@@ -27,9 +27,12 @@
"@vitejs/plugin-vue": "^6.0.1", "@vitejs/plugin-vue": "^6.0.1",
"@vitest/coverage-v8": "^4.0.18", "@vitest/coverage-v8": "^4.0.18",
"@vitest/ui": "^4.0.18", "@vitest/ui": "^4.0.18",
"@vue/test-utils": "^2.4.10",
"@vue/tsconfig": "^0.9.0", "@vue/tsconfig": "^0.9.0",
"jsdom": "^29.1.1",
"typescript": "~6.0.0", "typescript": "~6.0.0",
"vite": "^8.0.0", "vite": "^8.0.0",
"vitest": "^4.0.18",
"vue-tsc": "^3.0.5" "vue-tsc": "^3.0.5"
} }
} }
+2 -2
View File
@@ -274,7 +274,7 @@ async function initiateOAuth() {
variant="outlined" variant="outlined"
prepend-inner-icon="mdi-account" prepend-inner-icon="mdi-account"
class="mb-4" class="mb-4"
autocomplete="username" autocomplete="off"
autocorrect="off" autocorrect="off"
autocapitalize="none" autocapitalize="none"
:rules="[rules.required]" :rules="[rules.required]"
@@ -289,7 +289,7 @@ async function initiateOAuth() {
variant="outlined" variant="outlined"
prepend-inner-icon="mdi-lock" prepend-inner-icon="mdi-lock"
class="mb-4" class="mb-4"
autocomplete="current-password" autocomplete="new-password"
:rules="[rules.required]" :rules="[rules.required]"
/> />
</template> </template>
+57 -50
View File
@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import { ServiceObject } from '@KTXM/MailManager/models/service' import { ServiceObject } from '@KTXM/MailManager/models/service'
import { ServiceAddressObject } from '@KTXM/MailManager/models/address'
type AuxiliaryTab = 'addresses' | 'messages' | 'sync' type AuxiliaryTab = 'addresses' | 'messages' | 'sync'
type DeleteMode = 'soft' | 'hard' type DeleteMode = 'soft' | 'hard'
@@ -16,15 +17,15 @@ const emit = defineEmits<{
const activeTab = ref<AuxiliaryTab>('addresses') const activeTab = ref<AuxiliaryTab>('addresses')
const deleteMode = ref<DeleteMode>('soft') const deleteMode = ref<DeleteMode>('soft')
const deleteDestination = ref('Trash') const deleteDestination = ref('Trash')
const primaryAddress = ref('') const primaryAddress = ref<ServiceAddressObject>(new ServiceAddressObject())
const secondaryAddresses = ref('') const secondaryAddresses = ref<ServiceAddressObject[]>([])
const settingGroups = [ const settingGroups = [
{ {
title: 'Addresses', title: 'Addresses',
value: 'addresses' as const, value: 'addresses' as const,
icon: 'mdi-at', icon: 'mdi-at',
description: 'Configure the primary mailbox identity and any sender aliases exposed by this service.' description: 'View the primary mailbox identity and sender aliases synced from the JMAP server.'
}, },
{ {
title: 'Messages', title: 'Messages',
@@ -61,10 +62,6 @@ const destinationHint = computed(() => {
return 'Mailbox identifier or well-known role target, for example Trash.' 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( watch(
() => props.service, () => props.service,
service => { service => {
@@ -74,7 +71,7 @@ watch(
) )
watch( watch(
[deleteMode, deleteDestination, primaryAddress, secondaryAddresses], [deleteMode, deleteDestination],
() => { () => {
const nextService = props.service ?? new ServiceObject() const nextService = props.service ?? new ServiceObject()
const nextAuxiliary = { const nextAuxiliary = {
@@ -86,17 +83,13 @@ watch(
} }
if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) { if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) {
if (sameAddresses(nextService, primaryAddress.value, secondaryAddresses.value)) { return
return
}
} }
nextService.primaryAddress = normalizePrimaryAddress(primaryAddress.value)
nextService.secondaryAddresses = normalizeSecondaryAddresses(secondaryAddresses.value)
nextService.auxiliary = nextAuxiliary nextService.auxiliary = nextAuxiliary
emit('update:service', nextService) emit('update:service', nextService)
}, },
{ immediate: true } { deep: true, immediate: true }
) )
function syncFromService(service?: ServiceObject) { function syncFromService(service?: ServiceObject) {
@@ -105,8 +98,8 @@ function syncFromService(service?: ServiceObject) {
deleteDestination.value = typeof auxiliary.deleteDestination === 'string' && auxiliary.deleteDestination.length > 0 deleteDestination.value = typeof auxiliary.deleteDestination === 'string' && auxiliary.deleteDestination.length > 0
? auxiliary.deleteDestination ? auxiliary.deleteDestination
: 'Trash' : 'Trash'
primaryAddress.value = service?.primaryAddress ?? '' primaryAddress.value = service?.primaryAddress ?? new ServiceAddressObject()
secondaryAddresses.value = (service?.secondaryAddresses ?? []).join('\n') secondaryAddresses.value = service?.secondaryAddresses ?? []
} }
function normalizeDeleteDestination(value: string): string { function normalizeDeleteDestination(value: string): string {
@@ -114,27 +107,10 @@ function normalizeDeleteDestination(value: string): string {
return trimmedValue.length > 0 ? trimmedValue : 'Trash' return trimmedValue.length > 0 ? trimmedValue : 'Trash'
} }
function normalizePrimaryAddress(value: string): string | null {
const trimmedValue = value.trim()
return trimmedValue.length > 0 ? trimmedValue : null
}
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 sameAuxiliary(current: Record<string, any>, next: Record<string, any>): boolean { function sameAuxiliary(current: Record<string, any>, next: Record<string, any>): boolean {
return (current.deleteMode === 'hard' ? 'hard' : 'soft') === next.deleteMode return (current.deleteMode === 'hard' ? 'hard' : 'soft') === next.deleteMode
&& (current.deleteDestination ?? undefined) === (next.deleteDestination ?? undefined) && (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))
}
</script> </script>
<template> <template>
@@ -162,26 +138,57 @@ function sameAddresses(service: ServiceObject, nextPrimaryAddress: string, nextS
<div class="jmap-settings-card"> <div class="jmap-settings-card">
<h3 class="text-h6 mb-2">Addresses</h3> <h3 class="text-h6 mb-2">Addresses</h3>
<p class="text-body-2 text-medium-emphasis mb-6"> <p class="text-body-2 text-medium-emphasis mb-6">
Configure the primary mailbox identity and any additional sender aliases exposed by this service. The primary mailbox identity and sender aliases are managed by the JMAP server and synced automatically.
</p> </p>
<v-text-field <div class="text-subtitle-2 mb-2">Primary Address</div>
v-model="primaryAddress" <div class="d-flex ga-2 mb-6">
label="Primary Address" <v-text-field
variant="outlined" :model-value="primaryAddress.label"
prepend-inner-icon="mdi-email-outline" label="Display Name"
class="mb-4" variant="outlined"
/> density="compact"
hide-details="auto"
readonly
/>
<v-text-field
:model-value="primaryAddress.address"
label="Email Address"
variant="outlined"
density="compact"
prepend-inner-icon="mdi-email-outline"
hide-details="auto"
readonly
/>
</div>
<v-textarea <div class="text-subtitle-2 mb-2">Secondary Addresses</div>
v-model="secondaryAddresses" <p v-if="secondaryAddresses.length === 0" class="text-body-2 text-medium-emphasis">
label="Secondary Addresses" No aliases reported by the server.
variant="outlined" </p>
prepend-inner-icon="mdi-email-multiple-outline" <div
rows="4" v-for="(entry, index) in secondaryAddresses"
:hint="secondaryAddressesHint" :key="index"
persistent-hint class="d-flex ga-2 mb-2"
/> >
<v-text-field
:model-value="entry.label"
label="Display Name"
variant="outlined"
density="compact"
hide-details="auto"
readonly
/>
<v-text-field
:model-value="entry.address"
label="Email Address"
variant="outlined"
density="compact"
prepend-inner-icon="mdi-email-multiple-outline"
hide-details="auto"
readonly
/>
</div>
</div> </div>
</v-window-item> </v-window-item>
+3 -3
View File
@@ -1,17 +1,17 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { defineConfig, configDefaults } from 'vitest/config' import { defineConfig, configDefaults } from 'vitest/config'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import vuetify from 'vite-plugin-vuetify'
import path from 'path' import path from 'path'
const __filename = fileURLToPath(import.meta.url) const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename) const __dirname = path.dirname(__filename)
export default defineConfig({ export default defineConfig({
plugins: [vue(), vuetify()], plugins: [vue()],
resolve: { resolve: {
alias: { alias: {
'@KTXC': path.resolve(__dirname, '../../../core/src'), '@': path.resolve(__dirname, '../../src'),
'@KTXC': path.resolve(__dirname, '../../../../core/src'),
}, },
}, },
test: { test: {
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace KTXT\ProviderJmapc\Integration;
use PHPUnit\Framework\TestCase;
class BaseTest extends TestCase
{
public function testBasicAssertion(): void
{
$this->assertTrue(true);
}
public function testArrayOperations(): void
{
$array = ['foo' => 'bar'];
$this->assertArrayHasKey('foo', $array);
$this->assertEquals('bar', $array['foo']);
}
public function testStringOperations(): void
{
$string = 'Hello, World!';
$this->assertStringContainsString('World', $string);
$this->assertEquals(13, strlen($string));
}
}
+10
View File
@@ -2,6 +2,16 @@
require dirname(__DIR__, 2).'/lib/vendor/autoload.php'; require dirname(__DIR__, 2).'/lib/vendor/autoload.php';
// When this module is checked out inside a full server (server/modules/<handle>,
// as it is in CI and in this monorepo checkout), also load the server's own
// core/shared autoloader so tests can reference framework (KTXC/KTXF) types.
// Standalone module checkouts without a server alongside them skip this.
define('SERVER_ROOT', dirname(__DIR__, 4));
$serverAutoload = SERVER_ROOT . '/vendor/autoload.php';
if (is_file($serverAutoload)) {
require $serverAutoload;
}
if (isset($_SERVER['APP_DEBUG']) && $_SERVER['APP_DEBUG']) { if (isset($_SERVER['APP_DEBUG']) && $_SERVER['APP_DEBUG']) {
umask(0000); umask(0000);
} }
@@ -21,6 +21,9 @@
<testsuite name="Unit Tests"> <testsuite name="Unit Tests">
<directory>unit</directory> <directory>unit</directory>
</testsuite> </testsuite>
<testsuite name="Integration Tests">
<directory>Integration</directory>
</testsuite>
</testsuites> </testsuites>
<source ignoreSuppressionOfDeprecations="true" <source ignoreSuppressionOfDeprecations="true"
@@ -29,8 +32,7 @@
restrictWarnings="true" restrictWarnings="true"
> >
<include> <include>
<directory>../../core/lib</directory> <directory>../../lib</directory>
<directory>../../shared/lib</directory>
</include> </include>
<deprecationTrigger> <deprecationTrigger>