Part of issue #157 (rfc2086 & rfc4314)

This commit is contained in:
djmaze 2021-11-01 00:29:20 +01:00
parent 06cb57bc93
commit 3676183b10
3 changed files with 153 additions and 0 deletions

View file

@ -0,0 +1,99 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Imap\Commands;
/**
* @category MailSo
* @package Imap
*/
trait ACL
{
public function FolderSetACL(string $sFolderName, string $sIdentifier, string $sAccessRights) : void
{
$this->SendRequestGetResponse('SETACL', array(
$this->EscapeString($sFolderName),
$this->EscapeString($sIdentifier),
$this->EscapeString($sAccessRights)
));
}
public function FolderDeleteACL(string $sFolderName, string $sIdentifier) : void
{
$this->SendRequestGetResponse('DELETEACL', array(
$this->EscapeString($sFolderName),
$this->EscapeString($sIdentifier)
));
}
public function FolderGetACL(string $sFolderName) : array
{
$oResponses = $this->SendRequestGetResponse('GETACL', array($this->EscapeString($sFolderName)));
$aResult = array();
foreach ($oResponses as $oResponse) {
if (MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& isset($oResponse->ResponseList[4])
&& 'ACL' === $oResponse->ResponseList[1]
&& $sFolderName === $oResponse->ResponseList[2]
)
{
$aResult[$oResponse->ResponseList[3]] = static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
}
}
return $aResult;
}
public function FolderListRights(string $sFolderName, string $sIdentifier) : ?array
{
$oResponses = $this->SendRequestGetResponse('LISTRIGHTS', array(
$this->EscapeString($sFolderName),
$this->EscapeString($sIdentifier)
));
foreach ($oResponses as $oResponse) {
if (MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& isset($oResponse->ResponseList[4])
&& 'LISTRIGHTS' === $oResponse->ResponseList[1]
&& $sFolderName === $oResponse->ResponseList[2]
&& $sIdentifier === $oResponse->ResponseList[3]
)
{
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
}
}
return null;
}
public function FolderMyRights(string $sFolderName) : ?array
{
$oResponses = $this->SendRequestGetResponse('MYRIGHTS', array($this->EscapeString($sFolderName)));
foreach ($oResponses as $oResponse) {
if (MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType
&& isset($oResponse->ResponseList[3])
&& 'MYRIGHTS' === $oResponse->ResponseList[1]
&& $sFolderName === $oResponse->ResponseList[2]
)
{
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 3));
}
}
return null;
}
private static function aclRightsToArray(array $rules) : array
{
$result = array();
foreach ($rules as $rule) {
$result = \array_merge($result, \str_split($rule));
}
return \array_unique($result);
}
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2021 DJMaze
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://datatracker.ietf.org/doc/html/rfc2086
* https://datatracker.ietf.org/doc/html/rfc4314#section-4
*/
namespace MailSo\Imap\Enumerations;
/**
* @category MailSo
* @package Imap
* @subpackage Enumerations
*/
abstract class FolderACL
{
const
/** rfc2086 */
// perform SETACL/DELETEACL/GETACL/LISTRIGHTS
ADMINISTER = 'a',
// mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox
LOOKUP = 'l',
// SELECT the mailbox, perform STATUS
READ = 'r',
// set or clear \SEEN flag via STORE, also set \SEEN during APPEND/COPY/FETCH BODY[...]
SEEN = 's',
// set or clear flags other than \SEEN and \DELETED via STORE, also set them during APPEND/COPY
WRITE = 'w',
// perform APPEND, COPY into mailbox
INSERT = 'i',
// send mail to submission address for mailbox, not enforced by IMAP4 itself
POST = 'p',
// CREATE new sub-mailboxes in any implementation-defined hierarchy
// CREATE_OLD = 'c',
// STORE DELETED flag, perform EXPUNGE
// DELETED_OLD = 'd',
/** rfc4314 */
// CREATE new sub-mailboxes in any implementation-defined hierarchy, parent mailbox for the new mailbox name in RENAME
CREATE = 'k',
// DELETE mailbox, old mailbox name in RENAME
DELETE = 'x',
// set or clear \DELETED flag via STORE, set \DELETED flag during APPEND/COPY
DELETED = 't',
// perform EXPUNGE and expunge as a part of CLOSE
EXPUNGE = 'e';
}

View file

@ -18,6 +18,7 @@ namespace MailSo\Imap;
class ImapClient extends \MailSo\Net\NetClient
{
use Traits\ResponseParser;
// use Commands\ACL;
const
TAG_PREFIX = 'TAG';