mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 08:27:03 +03:00
Added ACL response class for #157
This commit is contained in:
parent
ecdf1603b3
commit
b1038667ee
3 changed files with 63 additions and 7 deletions
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
namespace MailSo\Imap\Commands;
|
namespace MailSo\Imap\Commands;
|
||||||
|
|
||||||
|
use \MailSo\Imap\Responses\ACL as ACLResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @category MailSo
|
* @category MailSo
|
||||||
* @package Imap
|
* @package Imap
|
||||||
|
|
@ -48,13 +50,13 @@ trait ACL
|
||||||
&& $sFolderName === $oResponse->ResponseList[2]
|
&& $sFolderName === $oResponse->ResponseList[2]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$aResult[$oResponse->ResponseList[3]] = static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
|
$aResult[$oResponse->ResponseList[3]] = static::aclRightsToClass(\array_slice($oResponse->ResponseList, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $aResult;
|
return $aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FolderListRights(string $sFolderName, string $sIdentifier) : ?array
|
public function FolderListRights(string $sFolderName, string $sIdentifier) : ?ACLResponse
|
||||||
{
|
{
|
||||||
// if ($this->IsSupported('ACL')) {
|
// if ($this->IsSupported('ACL')) {
|
||||||
$oResponses = $this->SendRequestGetResponse('LISTRIGHTS', array(
|
$oResponses = $this->SendRequestGetResponse('LISTRIGHTS', array(
|
||||||
|
|
@ -69,13 +71,13 @@ trait ACL
|
||||||
&& $sIdentifier === $oResponse->ResponseList[3]
|
&& $sIdentifier === $oResponse->ResponseList[3]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
|
return static::aclRightsToClass(\array_slice($oResponse->ResponseList, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FolderMyRights(string $sFolderName) : ?array
|
public function FolderMyRights(string $sFolderName) : ?ACLResponse
|
||||||
{
|
{
|
||||||
// if ($this->IsSupported('ACL')) {
|
// if ($this->IsSupported('ACL')) {
|
||||||
$oResponses = $this->SendRequestGetResponse('MYRIGHTS', array($this->EscapeString($sFolderName)));
|
$oResponses = $this->SendRequestGetResponse('MYRIGHTS', array($this->EscapeString($sFolderName)));
|
||||||
|
|
@ -86,19 +88,19 @@ trait ACL
|
||||||
&& $sFolderName === $oResponse->ResponseList[2]
|
&& $sFolderName === $oResponse->ResponseList[2]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 3));
|
return static::aclRightsToClass(\array_slice($oResponse->ResponseList, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function aclRightsToArray(array $rules) : array
|
private static function aclRightsToClass(array $rules) : ACLResponse
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
$result = \array_merge($result, \str_split($rule));
|
$result = \array_merge($result, \str_split($rule));
|
||||||
}
|
}
|
||||||
return \array_unique($result);
|
return new ACLResponse(\array_unique($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,12 @@ namespace MailSo\Imap\Enumerations;
|
||||||
* @package Imap
|
* @package Imap
|
||||||
* @subpackage Enumerations
|
* @subpackage Enumerations
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* PHP 8.1
|
||||||
|
enum FolderACL: string {
|
||||||
|
case ADMINISTER = 'a';
|
||||||
|
}
|
||||||
|
*/
|
||||||
abstract class FolderACL
|
abstract class FolderACL
|
||||||
{
|
{
|
||||||
const
|
const
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?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\Responses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category MailSo
|
||||||
|
* @package Imap
|
||||||
|
*/
|
||||||
|
class ACL implements \JsonSerializable
|
||||||
|
{
|
||||||
|
private $rights;
|
||||||
|
|
||||||
|
function __construct(array $rights)
|
||||||
|
{
|
||||||
|
$this->rights = $rights;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PHP 8.1
|
||||||
|
public function hasRight(string|\MailSo\Imap\Enumerations\FolderACL $right)
|
||||||
|
{
|
||||||
|
if ($right instanceof \BackedEnum) {
|
||||||
|
return \in_array($right->value, $this->rights);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public function hasRight(string $right)
|
||||||
|
{
|
||||||
|
$const = '\\MailSo\\Imap\\Enumerations\\FolderACL::' . \strtoupper($right);
|
||||||
|
if (\defined($const)) {
|
||||||
|
$right = \constant($const);
|
||||||
|
}
|
||||||
|
return \in_array($right, $this->rights);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize()
|
||||||
|
{
|
||||||
|
return $this->rights;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue