From 8e3a9bb82e76a2b5e8f563ed18c5026be2efe5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joosep=20J=C3=B5eleht?= Date: Tue, 24 May 2022 15:42:15 +0300 Subject: [PATCH] release(1.3.2) - Added new searchApplyMessages endpoint support --- composer.json | 2 +- src/Service/MessageService.php | 138 ++++++++++++++++++++++++++++----- 2 files changed, 121 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index b379078..6a4eaa1 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "", "type": "library", "license": "EUPL-1.1", - "version": "1.3.1", + "version": "1.3.2", "require": { "php": "^7.4|^8.0|^8.1", "ext-curl": "*", diff --git a/src/Service/MessageService.php b/src/Service/MessageService.php index 2e0859e..dc78247 100644 --- a/src/Service/MessageService.php +++ b/src/Service/MessageService.php @@ -2,12 +2,27 @@ namespace Zone\Wildduck\Service; +use Zone\Wildduck\Collection; +use Zone\Wildduck\Collection2; +use Zone\Wildduck\Exception\ApiConnectionException; +use Zone\Wildduck\Exception\AuthenticationFailedException; +use Zone\Wildduck\Exception\InvalidAccessTokenException; +use Zone\Wildduck\Exception\RequestFailedException; +use Zone\Wildduck\Exception\ValidationException; +use Zone\Wildduck\Message; +use Zone\Wildduck\WildduckObject; + class MessageService extends AbstractService { public function delete(string $user, string $mailbox, string $message, $params = null, $opts = null) { - return $this->request('delete', $this->buildPath('/users/%s/mailboxes/%s/messages/%s', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'delete', + $this->buildPath('/users/%s/mailboxes/%s/messages/%s', $user, $mailbox, $message), + $params, + $opts + ); } public function deleteOutbound(string $user, string $queueId, $params = null, $opts = null) @@ -15,64 +30,151 @@ public function deleteOutbound(string $user, string $queueId, $params = null, $o return $this->request('delete', $this->buildPath('/users/%s/outbound/%s', $user, $queueId), $params, $opts); } - public function downloadAttachment(string $user, string $mailbox, string $message, string $attachment, $params = null, $opts = null) - { + public function downloadAttachment( + string $user, + string $mailbox, + string $message, + string $attachment, + $params = null, + $opts = null + ) { // $opts['raw'] = true; - return $this->request('get', $this->buildPath('/users/%s/mailboxes/%s/messages/%s/attachments/%s', $user, $mailbox, $message, $attachment), $params, $opts); + return $this->request( + 'get', + $this->buildPath( + '/users/%s/mailboxes/%s/messages/%s/attachments/%s', + $user, + $mailbox, + $message, + $attachment + ), + $params, + $opts + ); } public function forward(string $user, string $mailbox, string $message, $params = null, $opts = null) { - return $this->request('post', $this->buildPath('/users/%s/mailboxes/%s/messages/%s/forward', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'post', + $this->buildPath('/users/%s/mailboxes/%s/messages/%s/forward', $user, $mailbox, $message), + $params, + $opts + ); } public function events(string $user, string $mailbox, string $message, $params = null, $opts = null) { - return $this->request('get', $this->buildPath('/users/%s/mailboxes/%s/messages/%s/events', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'get', + $this->buildPath('/users/%s/mailboxes/%s/messages/%s/events', $user, $mailbox, $message), + $params, + $opts + ); } public function source(string $user, string $mailbox, string $message, $params = null, $opts = null) { $opts['raw'] = true; - return $this->request('get', $this->buildPath('/users/%s/mailboxes/%s/messages/%s/message.eml', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'get', + $this->buildPath( + '/users/%s/mailboxes/%s/messages/%s/message.eml', + $user, + $mailbox, + $message + ), + $params, + $opts + ); } /** - * @return \Zone\Wildduck\Collection|\Zone\Wildduck\Message[] + * @return Collection|Message[] */ public function all(string $user, string $mailbox, $params = null, $opts = null) { - return $this->requestCollection('get', $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), $params, $opts); + return $this->requestCollection( + 'get', + $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), + $params, + $opts + ); } /** - * @return \Zone\Wildduck\Message + * @return Message */ public function get(string $user, string $mailbox, string $message, $params = null, $opts = null) { - return $this->request('get', $this->buildPath('/users/%s/mailboxes/%s/messages/%s', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'get', + $this->buildPath('/users/%s/mailboxes/%s/messages/%s', $user, $mailbox, $message), + $params, + $opts + ); + } + + public function search(string $user, $params = null, $opts = null): Collection2 + { + return $this->requestCollection('get', $this->buildPath('/users/%s/search', $user), $params, $opts); } /** - * @return \Zone\Wildduck\Collection|\Zone\Wildduck\Message[] + * @throws RequestFailedException + * @throws InvalidAccessTokenException + * @throws AuthenticationFailedException + * @throws ApiConnectionException + * @throws ValidationException + * + * @link https://docs.wildduck.email/api/#operation/searchApplyMessages */ - public function search(string $user, $params = null, $opts = null) + public function searchApplyMessages(string $user, $params = null, $opts = null): WildduckObject { - return $this->requestCollection('get', $this->buildPath('/users/%s/search', $user), $params, $opts); + return $this->request('post', $this->buildPath('/users/%s/search', $user), $params, $opts); } - public function submitDraft(string $user, string $mailbox, string $message, $params = null, $opts = null) + /** + * @throws RequestFailedException + * @throws InvalidAccessTokenException + * @throws AuthenticationFailedException + * @throws ApiConnectionException + * @throws ValidationException + */ + public function submitDraft(string $user, string $mailbox, string $message, $params = null, $opts = null): WildduckObject { - return $this->request('post', $this->buildPath('/users/%s/mailboxes/%s/messages/%s/submit', $user, $mailbox, $message), $params, $opts); + return $this->request( + 'post', + $this->buildPath('/users/%s/mailboxes/%s/messages/%s/submit', $user, $mailbox, $message), + $params, + $opts + ); } + /** + * @throws RequestFailedException + * @throws InvalidAccessTokenException + * @throws AuthenticationFailedException + * @throws ApiConnectionException + * @throws ValidationException + */ public function update(string $user, string $mailbox, $params = null, $opts = null) { - return $this->request('put', $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), $params, $opts); + return $this->request( + 'put', + $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), + $params, + $opts + ); } public function upload(string $user, string $mailbox, $params = null, $opts = null) { - return $this->request('post', $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), $params, $opts); + return $this->request( + 'post', + $this->buildPath('/users/%s/mailboxes/%s/messages', $user, $mailbox), + $params, + $opts + ); } }