Skip to content

Commit

Permalink
release(1.3.2) - Added new searchApplyMessages endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosep Jõeleht authored and Joosep Jõeleht committed May 24, 2022
1 parent 4bb13d6 commit 8e3a9bb
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
138 changes: 120 additions & 18 deletions src/Service/MessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,179 @@

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)
{
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
);
}
}

0 comments on commit 8e3a9bb

Please sign in to comment.