2013-11-15 18:22:46 +01:00
< ? php
/**
* EGroupware - Mail Folder ACL - interface class
*
* @ link http :// www . egroupware . org
* @ package mail
2016-10-08 14:32:58 +02:00
* @ author Hadi Nategh [ hn @ egroupware . org ]
* @ copyright ( c ) 2013 - 16 by EGroupware GmbH < info - AT - egroupware . org >
2013-11-15 18:22:46 +01:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
2014-04-03 14:31:52 +02:00
* @ version $Id $
2013-11-15 18:22:46 +01:00
*/
2017-05-11 16:47:31 +02:00
/*
* Reference : RFC 4314 DOCUMENTATION - RIGHTS ( https :// tools . ietf . org / html / rfc4314 )
*
* Standard Rights :
*
* The currently defined standard rights are ( note that the list below
* doesn ' t list all commands that use a particular right ) :
*
* l - lookup ( mailbox is visible to LIST / LSUB commands , SUBSCRIBE mailbox )
* r - read ( SELECT the mailbox , perform STATUS )
* s - keep seen / unseen information across sessions ( set or clear \SEEN flag
* via STORE , also set \SEEN during APPEND / COPY / FETCH BODY [ ... ])
* w - write ( set or clear flags other than \SEEN and \DELETED via
* STORE , also set them during APPEND / COPY )
* i - insert ( perform APPEND , COPY into mailbox )
* p - post ( send mail to submission address for mailbox ,
* not enforced by IMAP4 itself )
* k - create mailboxes ( CREATE new sub - mailboxes in any
* implementation - defined hierarchy , parent mailbox for the new
* mailbox name in RENAME )
* x - delete mailbox ( DELETE mailbox , old mailbox name in RENAME )
* t - delete messages ( set or clear \DELETED flag via STORE , set
* \DELETED flag during APPEND / COPY )
* e - perform EXPUNGE and expunge as a part of CLOSE
* a - administer ( perform SETACL / DELETEACL / GETACL / LISTRIGHTS )
*
*
*
* Obsolete Rights :
*
* Due to ambiguity in RFC 2086 , some existing RFC 2086 server
* implementations use the " c " right to control the DELETE command .
* Others chose to use the " d " right to control the DELETE command . For
* the former group , let ' s define the " create " right as union of the " k "
* and " x " rights , and the " delete " right as union of the " e " and " t "
* rights . For the latter group , let ' s define the " create " rights as a
* synonym to the " k " right , and the " delete " right as union of the " e " ,
* " t " , and " x " rights .
* For compatibility with RFC 2086 , this section defines two virtual
* rights " d " and " c " .
* If a client includes the " d " right in a rights list , then it MUST be
* treated as if the client had included every member of the " delete "
* right . ( It is not an error for a client to specify both the " d "
* right and one or more members of the " delete " right , but the effect
* is no different than if just the " d " right or all members of the
* " delete " right had been specified . )
*
*/
2016-03-28 20:51:38 +02:00
use EGroupware\Api ;
2016-05-03 21:17:44 +02:00
use EGroupware\Api\Framework ;
use EGroupware\Api\Etemplate ;
2016-03-28 20:51:38 +02:00
use EGroupware\Api\Mail ;
2013-11-15 18:22:46 +01:00
class mail_acl
{
/**
* Methods callable via menuaction
*
* @ var array
*/
var $public_functions = array (
'edit' => True ,
);
2013-11-28 16:08:41 +01:00
/**
2017-03-14 10:53:50 +01:00
* static used define abbreviations for common access rights
2013-11-28 16:08:41 +01:00
*
* @ array
*
*/
var $aclRightsAbbrvs = array (
'lrs' => array ( 'label' => 'readable' , 'title' => 'Allows a user to read the contents of the mailbox.' ),
'lprs' => array ( 'label' => 'post' , 'title' => 'Allows a user to read the mailbox and post to it through the delivery system by sending mail to the submission address of the mailbox.' ),
'ilprs' => array ( 'label' => 'append' , 'title' => 'Allows a user to read the mailbox and append messages to it, either via IMAP or through the delivery system.' ),
2017-05-12 15:48:36 +02:00
'ilprsw' => array ( 'label' => 'write' , 'title' => 'Allows a user to read and write the maibox, post to it, append messages to it.' ),
'eilprswtk' => array ( 'label' => 'write & delete' , 'title' => 'Allows a user to read, write and create folders and mails, post to it, append messages to it and delete messages.' ),
2014-02-28 16:39:46 +01:00
'aeiklprstwx' => array ( 'label' => 'all' , 'title' => 'The user has all possible rights on the mailbox. This is usually granted to users only on the mailboxes they own.' ),
2013-11-28 16:08:41 +01:00
'custom' => array ( 'label' => 'custom' , 'title' => 'User defined combination of rights for the ACL' ),
);
2013-11-15 18:22:46 +01:00
/**
2017-03-14 10:53:50 +01:00
* imap object instantiated in constructor for account to edit
2013-11-15 18:22:46 +01:00
*
2016-03-28 20:51:38 +02:00
* @ var Mail\Imap
2013-11-15 18:22:46 +01:00
*/
2014-09-24 19:25:18 +02:00
var $imap ;
2013-11-28 16:08:41 +01:00
2013-11-15 18:22:46 +01:00
/**
*
2014-09-24 19:25:18 +02:00
* @ var mail_account
2013-11-15 18:22:46 +01:00
*/
2014-09-24 19:25:18 +02:00
var $current_account ;
2013-11-15 18:22:46 +01:00
/**
2014-07-22 10:05:42 +02:00
* Edit folder ACLs of account ( s )
2013-11-15 18:22:46 +01:00
*
2020-01-31 15:03:56 +01:00
* @ param array $content = null
2017-06-14 11:04:21 +02:00
* @ param string $msg = ''
2013-11-28 16:08:41 +01:00
*
2013-11-15 18:22:46 +01:00
*/
function edit ( array $content = null , $msg = '' )
{
2016-05-03 21:17:44 +02:00
$tmpl = new Etemplate ( 'mail.acl' );
2014-09-24 19:25:18 +02:00
if ( ! is_array ( $content ))
{
2022-05-04 16:52:37 +02:00
$acc_id = $_GET [ 'acc_id' ] ? ? $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'mail' ][ 'ActiveProfileID' ];
2014-09-24 19:25:18 +02:00
if ( isset ( $_GET [ 'account_id' ]) && ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]))
{
2016-05-03 21:17:44 +02:00
Framework :: window_close ( lang ( 'Permission denied' ));
2014-09-24 19:25:18 +02:00
}
$account_id = $_GET [ 'account_id' ];
}
else
{
$acc_id = $content [ 'acc_id' ];
$account_id = $content [ 'account_id' ];
}
2016-03-28 20:51:38 +02:00
$account = Mail\Account :: read ( $acc_id , $account_id );
2014-09-24 19:25:18 +02:00
$this -> imap = $account -> imapServer ( isset ( $account_id ) ? ( int ) $account_id : false );
2020-01-31 15:03:56 +01:00
$mailbox = $_GET [ 'mailbox' ] ? base64_decode ( $_GET [ 'mailbox' ]) : self :: _extract_mailbox ( $content [ 'mailbox' ], $acc_id );
2014-09-24 19:25:18 +02:00
if ( empty ( $mailbox ))
{
2017-01-31 18:01:08 +01:00
$mailbox = $this -> imap -> isAdminConnection ? $this -> imap -> getUserMailboxString ( $account_id ) : 'INBOX' ;
2014-09-24 19:25:18 +02:00
}
2014-09-26 13:24:43 +02:00
if ( ! $this -> imap -> isAdminConnection )
{
$tmpl -> setElementAttribute ( 'mailbox' , 'autocomplete_url' , 'mail.mail_compose.ajax_searchFolder' );
2017-03-14 10:53:50 +01:00
$tmpl -> setElementAttribute ( 'mailbox' , 'autocomplete_params' , array ( 'mailaccount' => $acc_id ));
2014-09-26 13:24:43 +02:00
}
else
{
//Todo: Implement autocomplete_url function with admin stuffs consideration
}
2014-09-24 14:02:35 +02:00
// Unset the content if folder is changed, in order to read acl rights for new selected folder
2020-01-31 15:03:56 +01:00
if ( ! is_array ( $content [ 'button' ]) && self :: _extract_mailbox ( $content [ 'mailbox' ], $acc_id ) && ! is_array ( $content [ 'grid' ][ 'delete' ])) unset ( $content );
2014-09-24 19:25:18 +02:00
2013-11-15 18:22:46 +01:00
if ( ! is_array ( $content ))
{
if ( ! empty ( $mailbox ))
{
2013-12-05 14:49:02 +01:00
$content [ 'mailbox' ] = $mailbox ;
2022-05-04 16:52:37 +02:00
if (( $acls = $this -> retrieve_acl ( $mailbox , $msg )) === false )
2017-05-12 15:48:36 +02:00
{
Api\Framework :: window_close ( $msg );
}
2013-11-28 16:08:41 +01:00
$n = 1 ;
2022-05-04 16:52:37 +02:00
foreach ( $acls as $key => $acl )
2013-11-28 16:08:41 +01:00
{
2022-05-04 16:52:37 +02:00
$rights = [];
foreach ( $acl -> getIterator () as $right )
2013-11-28 16:08:41 +01:00
{
$content [ 'grid' ][ $n ][ 'acl_' . $right ] = true ;
2022-05-04 16:52:37 +02:00
$rights [] = $right ;
}
$virtual = $acl -> getString ( Horde_Imap_Client_Data_Acl :: RFC_2086 );
foreach ([ 'c' , 'd' ] as $right )
{
if ( strpos ( $virtual , $right ) !== false )
{
$content [ 'grid' ][ $n ][ 'acl_' . $right ] = true ;
}
2013-11-28 16:08:41 +01:00
}
2013-12-09 11:10:51 +01:00
2014-02-28 16:39:46 +01:00
sort ( $rights );
2013-12-09 11:10:51 +01:00
$acl_abbrvs = implode ( '' , $rights );
2013-12-05 08:58:45 +01:00
2013-11-28 16:08:41 +01:00
if ( array_key_exists ( $acl_abbrvs , $this -> aclRightsAbbrvs ))
{
$content [ 'grid' ][ $n ][ 'acl' ] = $acl_abbrvs ;
}
else
{
$content [ 'grid' ][ $n ][ 'acl' ] = 'custom' ;
}
2014-09-24 19:25:18 +02:00
if (( $user = $this -> imap -> getMailBoxAccountId ( $key )))
2014-02-28 13:44:27 +01:00
{
2014-09-24 19:25:18 +02:00
$content [ 'grid' ][ $n ++ ][ 'acc_id' ] = $user ;
2014-02-28 13:44:27 +01:00
}
else
{
2014-04-15 18:09:19 +02:00
$content [ 'grid' ][ $n ++ ][ 'acc_id' ] = $key ;
2014-02-28 13:44:27 +01:00
}
2013-11-28 16:08:41 +01:00
}
2014-02-28 13:44:27 +01:00
//error_log(__METHOD__."() acl=".array2string($acl).' --> grid='.array2string($content['grid']));
2013-11-15 18:22:46 +01:00
}
2014-04-15 18:09:19 +02:00
//Set the acl entry in the last row with lrs as default ACL
2014-02-28 14:08:50 +01:00
array_push ( $content [ 'grid' ], array (
2014-04-15 18:09:19 +02:00
'acc_id' => '' ,
'acl_l' => true ,
'acl_r' => true ,
'acl_s' => true ));
2013-11-15 18:22:46 +01:00
}
2013-11-28 16:08:41 +01:00
else
{
2021-11-16 11:23:03 +01:00
$button = ! empty ( $content [ 'grid' ][ 'delete' ]) ? 'delete' : @ key (( array ) $content [ 'button' ]);
2020-01-31 15:03:56 +01:00
$data = $content ;
$data [ 'mailbox' ] = self :: _extract_mailbox ( $content [ 'mailbox' ], $acc_id );
2013-11-28 16:08:41 +01:00
switch ( $button )
{
case 'save' :
case 'apply' :
if ( $content )
{
2020-01-31 15:03:56 +01:00
$validation_err = $this -> update_acl ( $data , $msg );
2013-11-28 16:08:41 +01:00
if ( $validation_err )
{
foreach ( $validation_err as & $row )
{
$tmpl -> set_validation_error ( 'grid[' . $row . ']' . '[acc_id]' , " You must fill this field! " );
}
}
2014-09-24 19:25:18 +02:00
2013-12-02 18:09:35 +01:00
//Add new row at the end
if ( $content [ 'grid' ][ count ( $content [ 'grid' ])][ 'acc_id' ])
array_push ( $content [ 'grid' ], array ( 'acc_id' => '' ));
2013-11-28 16:08:41 +01:00
}
else
{
$msg .= " \n " . lang ( " Error: Could not save ACL " ) . ' ' . lang ( " reason! " );
}
//Send message
2016-05-03 21:17:44 +02:00
Framework :: message ( $msg );
2013-11-28 16:08:41 +01:00
if ( $button == " apply " ) break ;
2016-05-03 21:17:44 +02:00
Framework :: window_close ();
2016-03-28 20:51:38 +02:00
exit ;
2013-11-28 16:08:41 +01:00
case 'delete' :
2020-01-31 15:03:56 +01:00
$aclRvmCnt = $this -> remove_acl ( $data , $msg );
2013-12-05 08:58:45 +01:00
if ( is_array ( $aclRvmCnt ))
{
$content [ 'grid' ] = $aclRvmCnt ;
}
else
{
2013-12-20 17:17:12 +01:00
error_log ( __METHOD__ . __LINE__ . " () " . " The remove_acl suppose to return an array back, something is wrong there " );
2013-12-05 08:58:45 +01:00
}
2016-05-03 21:17:44 +02:00
Framework :: message ( $msg );
2013-11-28 16:08:41 +01:00
}
}
2014-02-28 18:00:53 +01:00
$readonlys = $sel_options = array ();
2013-11-28 16:08:41 +01:00
$sel_options [ 'acl' ] = $this -> aclRightsAbbrvs ;
2014-04-15 18:09:19 +02:00
2014-07-23 13:59:46 +02:00
//Make the account owner's fields all readonly as owner has all rights and should not be able to change them
foreach ( $content [ 'grid' ] as $key => $fields )
2014-04-15 18:09:19 +02:00
{
2017-03-14 17:50:33 +01:00
if ( self :: _extract_acc_id ( $fields [ 'acc_id' ]) == $this -> imap -> acc_imap_username ||
$this -> imap -> getMailBoxUserName ( self :: _extract_acc_id ( $fields [ 'acc_id' ])) == $this -> imap -> acc_imap_username )
2014-04-15 18:09:19 +02:00
{
2014-09-26 16:18:30 +02:00
foreach ( array_keys ( $fields ) as $index )
2014-07-23 13:59:46 +02:00
{
$readonlys [ 'grid' ][ $key ][ $index ] = true ;
}
2014-04-15 18:09:19 +02:00
$readonlys [ 'grid' ][ 'delete[' . $key . ']' ] = true ;
2014-07-23 13:59:46 +02:00
$readonlys [ 'grid' ][ $key ][ 'acl_recursive' ] = true ;
$preserv [ 'grid' ][ $key ] = $fields ;
$preserv [ 'grid' ][ $key ][ 'acl_recursive' ] = false ;
2014-04-15 18:09:19 +02:00
}
2017-03-14 14:49:29 +01:00
if ( count ( $content [ 'grid' ]) != $key )
{
$preserv [ 'grid' ][ $key ][ 'acc_id' ] = self :: _extract_acc_id ( $fields [ 'acc_id' ]);
$preserv [ 'grid' ][ $key ][ 'acl_recursive' ] = false ;
$readonlys [ 'grid' ][ $key ][ 'acc_id' ] = true ;
}
2014-04-15 18:09:19 +02:00
}
2014-07-23 13:59:46 +02:00
//Make entry row's delete button readonly
2014-04-15 18:09:19 +02:00
$readonlys [ 'grid' ][ 'delete[' . count ( $content [ 'grid' ]) . ']' ] = true ;
2014-09-24 19:25:18 +02:00
$preserv [ 'mailbox' ] = $content [ 'mailbox' ];
$preserv [ 'acc_id' ] = $acc_id ;
$preserv [ 'account_id' ] = $account_id ;
$content [ 'grid' ][ 'account_type' ] = $this -> imap -> supportsGroupAcl () ? 'both' : 'accounts' ;
2014-09-26 16:18:30 +02:00
// set a custom autocomplete method for mailbox taglist
if ( $account_id )
{
$tmpl -> setElementAttribute ( 'mailbox' , 'autocomplete_url' , __CLASS__ . '::ajax_folders' );
$tmpl -> setElementAttribute ( 'mailbox' , 'autocomplete_params' , array (
'acc_id' => $acc_id ,
'account_id' => $account_id ,
));
}
2013-11-28 16:08:41 +01:00
$tmpl -> exec ( 'mail.mail_acl.edit' , $content , $sel_options , $readonlys , $preserv , 2 );
2013-11-15 18:22:46 +01:00
}
2014-09-26 16:18:30 +02:00
/**
* Autocomplete for folder taglist
*
2016-05-03 21:17:44 +02:00
* @ throws Api\Exception\NoPermission\Admin
2014-09-26 16:18:30 +02:00
*/
public static function ajax_folders ()
{
if ( ! empty ( $_GET [ 'account_id' ]) && ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ])
{
2016-05-03 21:17:44 +02:00
throw new Api\Exception\NoPermission\Admin ;
2014-09-26 16:18:30 +02:00
}
2016-03-28 20:51:38 +02:00
$account = Mail\Account :: read ( $_GET [ 'acc_id' ], $_GET [ 'account_id' ]);
2014-09-26 16:18:30 +02:00
$imap = $account -> imapServer ( ! empty ( $_GET [ 'account_id' ]) ? ( int ) $_GET [ 'account_id' ] : false );
$mailbox = $imap -> isAdminConnection ? $imap -> getUserMailboxString ( $imap -> isAdminConnection ) : 'INBOX' ;
$folders = array ();
foreach ( self :: getSubfolders ( $mailbox , $imap ) as $folder )
{
if ( stripos ( $folder , $_GET [ 'query' ]) !== false )
{
$folders [] = array (
'id' => $folder ,
'label' => $folder ,
);
}
}
// switch regular JSON response handling off
2016-05-03 21:17:44 +02:00
Api\Json\Request :: isJSONRequest ( false );
2014-09-26 16:18:30 +02:00
header ( 'Content-Type: application/json; charset=utf-8' );
echo json_encode ( $folders );
2016-03-28 20:51:38 +02:00
exit ;
2014-09-26 16:18:30 +02:00
}
2020-01-31 15:03:56 +01:00
/**
* Update ACL rights of a folder or including subfolders for an account ( s )
*
* @ param array $content content including the acl rights
* @ param string $msg Message
*
* @ return Array | void return array of validation messages or nothing
*/
2013-11-28 16:08:41 +01:00
function update_acl ( $content , & $msg )
2013-11-15 18:22:46 +01:00
{
2013-11-28 16:08:41 +01:00
$validator = array ();
2014-09-24 19:25:18 +02:00
2013-11-28 16:08:41 +01:00
foreach ( $content [ 'grid' ] as $keys => $value )
{
2013-12-05 08:58:45 +01:00
$recursive = $value [ 'acl_recursive' ];
2013-11-28 16:08:41 +01:00
unset ( $value [ 'acc_id' ]);
unset ( $value [ 'acl_recursive' ]);
unset ( $value [ 'acl' ]);
2013-12-05 08:58:45 +01:00
2013-11-28 16:08:41 +01:00
$options = array ();
2022-05-04 16:52:37 +02:00
foreach ( $value as $key => $set )
2013-11-28 16:08:41 +01:00
{
2022-05-04 16:52:37 +02:00
if ( $set )
2013-11-28 16:08:41 +01:00
{
2022-05-04 16:52:37 +02:00
$right = explode ( " acl_ " , $key );
2013-12-09 11:10:51 +01:00
if ( $right [ 1 ] === 'c' ) $right [ 1 ] = 'kx' ; // c = kx , rfc 4314
if ( $right [ 1 ] === 'd' ) $right [ 1 ] = 'et' ; // d = et , rfc 4314
2013-11-28 16:08:41 +01:00
$options [ 'rights' ] .= $right [ 1 ];
}
}
2017-03-14 14:49:29 +01:00
$username = self :: _extract_acc_id ( $content [ 'grid' ][ $keys ][ 'acc_id' ]);
2014-05-15 16:33:27 +02:00
//error_log(__METHOD__."(".__LINE__.") setACL($content[mailbox], $username, ".array2string($options).", $recursive)");
2014-09-24 19:25:18 +02:00
if ( is_numeric ( $username ) && ( $u = $this -> imap -> getMailBoxUserName ( $username )))
2014-02-28 13:44:27 +01:00
{
$username = $u ;
}
if ( ! empty ( $username ))
2013-11-28 16:08:41 +01:00
{
2014-02-28 13:44:27 +01:00
//error_log(__METHOD__."() setACL($content[mailbox], $username, ".array2string($options).", $recursive)");
2014-07-23 13:59:46 +02:00
if (( $ret = $this -> setACL ( $content [ 'mailbox' ], $username , $options , $recursive , $msg )))
{
2014-09-24 19:25:18 +02:00
$msg = lang ( " The Folder %1 's ACLs saved " , $content [ 'mailbox' ]);
2014-07-23 13:59:46 +02:00
}
else
{
2014-09-24 19:25:18 +02:00
$msg = lang ( 'Error while setting ACL for folder %1!' , $content [ 'mailbox' ]) . ' ' . $msg ;
2014-07-23 13:59:46 +02:00
}
2013-11-28 16:08:41 +01:00
}
else
{
if ( $keys !== count ( $content [ 'grid' ]))
{
2013-12-05 08:58:45 +01:00
array_push ( $validator , $keys );
2017-05-24 17:41:02 +02:00
$msg = lang ( " Could not save the ACL because some names are empty " );
2013-11-28 16:08:41 +01:00
}
}
}
2014-04-15 18:09:19 +02:00
if ( is_array ( $validator ))
{
return $validator ;
2014-09-24 19:25:18 +02:00
}
2013-11-15 18:22:46 +01:00
}
/**
2017-05-08 10:07:32 +02:00
* Retrieve Folder ACL rights
2020-01-31 15:03:56 +01:00
* @ param string $mailbox
* @ param string & $msg
*
2022-05-04 16:52:37 +02:00
* @ return Horde_Imap_Client_Data_Acl [] | false returns array of acl or false on failure
2020-01-31 15:03:56 +01:00
* @ todo rights 'c' and 'd' should be fixed
2013-11-15 18:22:46 +01:00
*/
2017-05-08 10:07:32 +02:00
function retrieve_acl ( $mailbox , & $msg )
2013-11-15 18:22:46 +01:00
{
2022-05-04 16:52:37 +02:00
if (( $acl = $this -> getACL ( $mailbox )) !== false )
2013-11-15 18:22:46 +01:00
{
2017-05-08 10:07:32 +02:00
$msg = lang ( 'ACL rights retrieved successfully' );
2013-11-28 16:08:41 +01:00
return $acl ;
2013-11-15 18:22:46 +01:00
}
else
{
2013-11-28 16:08:41 +01:00
$msg = lang ( 'Get ACL rights failed from IMAP server!' );
2017-05-12 15:48:36 +02:00
return false ;
2013-11-15 18:22:46 +01:00
}
}
2013-11-28 16:08:41 +01:00
/**
* remove_acl
2013-12-05 08:58:45 +01:00
* This method take content of acl rights , and will delete the one from ACL IMAP ,
* for selected folder and / or its subfolders
2013-11-28 16:08:41 +01:00
*
* @ param Array $content content array of popup window
* @ param string $msg message
*
2020-01-31 15:03:56 +01:00
* @ return Array | Boolean An array as new content for grid or false in case of error
2013-11-28 16:08:41 +01:00
*/
2013-12-05 08:58:45 +01:00
function remove_acl ( $content , & $msg )
2013-11-28 16:08:41 +01:00
{
$row_num = array_keys ( $content [ 'grid' ][ 'delete' ], " pressed " );
2014-02-28 14:08:50 +01:00
if ( $row_num ) $row_num = $row_num [ 0 ];
2013-12-05 08:58:45 +01:00
$recursive = $content [ 'grid' ][ $row_num ][ 'acl_recursive' ];
2017-03-14 14:49:29 +01:00
$identifier = self :: _extract_acc_id ( $content [ 'grid' ][ $row_num ][ 'acc_id' ]);
$content [ 'mailbox' ] = is_array ( $content [ 'mailbox' ]) ? $content [ 'mailbox' ][ 0 ] : $content [ 'mailbox' ];
2014-09-24 19:25:18 +02:00
if ( is_numeric ( $identifier ) && ( $u = $this -> imap -> getMailBoxUserName ( $identifier )))
2014-05-15 16:33:27 +02:00
{
$identifier = $u ;
}
//error_log(__METHOD__.__LINE__."(".$content['mailbox'].", ".$identifier.", ".$recursive.")");
2013-12-05 08:58:45 +01:00
if (( $res = $this -> deleteACL ( $content [ 'mailbox' ], $identifier , $recursive )))
{
unset ( $content [ 'grid' ][ $row_num ]);
unset ( $content [ 'grid' ][ 'delete' ]);
if ( $recursive )
{
2014-09-24 19:25:18 +02:00
$msg = lang ( " The %1 's acl, including its subfolders, removed from the %2 " , $content [ 'mailbox' ], $identifier );
2013-12-05 08:58:45 +01:00
}
else
{
2014-09-24 19:25:18 +02:00
$msg = lang ( " The %1 's acl removed from the %2 " , $content [ 'mailbox' ], $identifier );
2013-12-05 08:58:45 +01:00
}
return array_combine ( range ( 1 , count ( $content [ 'grid' ])), array_values ( $content [ 'grid' ]));
}
else
{
2014-09-24 19:25:18 +02:00
$msg = lang ( " An error happend while trying to remove ACL rights from the account %1! " , $identifier );
2013-12-05 08:58:45 +01:00
return false ;
}
2013-11-28 16:08:41 +01:00
}
/**
* Delete ACL rights of a folder or including subfolders from an account
*
* @ param String $mailbox folder name that needs to be edited
* @ param String $identifier The identifier to delete .
* @ param Boolean $recursive boolean flag FALSE | TRUE . If it is FALSE , only the folder take in to account , but in case of TRUE
* the mailbox including all its subfolders will be considered .
*
2013-12-05 08:58:45 +01:00
* @ return Boolean FALSE in case of any exceptions and TRUE in case of success
2013-11-28 16:08:41 +01:00
*/
function deleteACL ( $mailbox , $identifier , $recursive )
{
2013-12-05 08:58:45 +01:00
if ( $recursive )
2013-11-28 16:08:41 +01:00
{
2014-09-26 16:18:30 +02:00
$folders = self :: getSubfolders ( $mailbox , $this -> imap );
2013-11-28 16:08:41 +01:00
}
2013-12-05 08:58:45 +01:00
else
2013-11-28 16:08:41 +01:00
{
2014-04-15 11:05:03 +02:00
$folders = ( array ) $mailbox ;
2013-12-05 08:58:45 +01:00
}
foreach ( $folders as $sbFolders )
{
try
{
2014-09-24 19:25:18 +02:00
$this -> imap -> deleteACL ( $sbFolders , $identifier );
2013-12-05 08:58:45 +01:00
}
catch ( Exception $e )
{
2017-03-14 10:53:50 +01:00
error_log ( __METHOD__ . " Could not delete ACL rights of folder " . $mailbox . " for account " . $identifier . " . " . $e -> getMessage ());
2013-12-05 08:58:45 +01:00
return false ;
}
2013-11-28 16:08:41 +01:00
}
2013-12-05 08:58:45 +01:00
return true ;
}
2013-11-28 16:08:41 +01:00
2013-12-05 08:58:45 +01:00
/**
* Get subfolders of a mailbox
*
* @ param string $mailbox structural folder name
2016-03-28 20:51:38 +02:00
* @ param Mail\Imap $imap
2013-12-05 08:58:45 +01:00
* @ return Array an array including all subfolders of given mailbox | returns an empty array in case of no subfolders
*/
2016-03-28 20:51:38 +02:00
protected static function getSubfolders ( $mailbox , Mail\Imap $imap )
2013-12-05 08:58:45 +01:00
{
2014-09-26 16:18:30 +02:00
$delimiter = $imap -> getDelimiter ();
$nameSpace = $imap -> getNameSpace ();
$prefix = $imap -> getFolderPrefixFromNamespace ( $nameSpace , $mailbox );
if (( $subFolders = $imap -> getMailBoxesRecursive ( $mailbox , $delimiter , $prefix )))
2013-12-05 08:58:45 +01:00
{
return $subFolders ;
}
2014-09-26 13:24:43 +02:00
else
2013-12-05 08:58:45 +01:00
{
return array ();
}
2013-11-28 16:08:41 +01:00
}
/**
* Set ACL rights of a folder or including subfolders to an account
* @ param String $mailbox folder name that needs to be edited
2014-07-23 13:59:46 +02:00
* @ param String $identifier The identifier to set .
2013-11-28 16:08:41 +01:00
* @ param Array $options Additional options :
2014-04-15 18:09:19 +02:00
* - rights : ( string ) The rights to alter or set .
* - action : ( string , optional ) If 'add' or 'remove' , adds or removes the
* specified rights . Sets the rights otherwise .
2013-11-28 16:08:41 +01:00
* @ param Boolean $recursive boolean flag FALSE | TRUE . If it is FALSE , only the folder take in to account , but in case of TRUE
* the mailbox including all its subfolders will be considered .
* @ param String $msg message
2013-12-05 08:58:45 +01:00
* @ return Boolean FALSE in case of any exceptions and TRUE in case of success ,
2013-11-28 16:08:41 +01:00
*
*/
2014-07-23 13:59:46 +02:00
function setACL ( $mailbox , $identifier , $options , $recursive , & $msg )
2013-11-28 16:08:41 +01:00
{
2013-12-05 08:58:45 +01:00
if ( $recursive )
2013-11-28 16:08:41 +01:00
{
2014-09-26 16:18:30 +02:00
$folders = self :: getSubfolders ( $mailbox , $this -> imap );
2013-11-28 16:08:41 +01:00
}
2013-12-05 08:58:45 +01:00
else
2013-11-28 16:08:41 +01:00
{
2014-04-15 11:05:03 +02:00
$folders = ( array ) $mailbox ;
2013-12-05 08:58:45 +01:00
}
foreach ( $folders as $sbFolders )
{
try
{
2014-09-24 19:25:18 +02:00
$this -> imap -> setACL ( $sbFolders , $identifier , $options );
2013-12-05 08:58:45 +01:00
}
catch ( Exception $e )
{
2014-07-23 13:59:46 +02:00
$msg = $e -> getMessage ();
2017-03-14 10:53:50 +01:00
error_log ( __METHOD__ . " Could not set ACL rights on folder " . $mailbox . " for account " . $identifier . " . " . $e -> getMessage ());
2013-12-05 08:58:45 +01:00
return false ;
}
2013-11-28 16:08:41 +01:00
}
2013-12-05 08:58:45 +01:00
return true ;
2013-11-28 16:08:41 +01:00
}
/**
* Get ACL rights of a folder from an account
*
* @ param String $mailbox folder name that needs to be read
2022-05-04 16:52:37 +02:00
* @ return Horde_Imap_Client_Data_Acl [] | false FALSE in case of any exceptions and returns Array in case of success ,
2013-11-28 16:08:41 +01:00
*/
function getACL ( $mailbox )
{
2014-04-22 16:15:58 +02:00
try
2013-11-28 16:08:41 +01:00
{
2020-01-31 15:03:56 +01:00
return $this -> imap -> getACL ( $mailbox );
2014-04-22 16:15:58 +02:00
} catch ( Exception $e ) {
2017-03-14 10:53:50 +01:00
error_log ( __METHOD__ . " Could not get ACL rights from folder " . $mailbox . " . " . $e -> getMessage ());
2014-04-22 16:15:58 +02:00
return false ;
2013-11-28 16:08:41 +01:00
}
}
2017-03-14 14:49:29 +01:00
/**
* Method to get acc_id id value whether if is a flat value or an array
*
* @ param type $acc_id acc_id value comming from client - side
*
* @ return string returns acc_id in flat format
*/
private static function _extract_acc_id ( $acc_id )
{
return is_array ( $acc_id ) ? $acc_id [ 0 ] : $acc_id ;
}
2020-01-31 15:03:56 +01:00
/**
* @ param string | array $mailbox
* @ param string $acc_id
*
* @ return string | NULL return sanitate mailbox of acc id and delimiter and return it as string
*/
private static function _extract_mailbox ( $mailbox , $acc_id )
{
$mailbox = is_array ( $mailbox ) ? $mailbox [ 0 ] : $mailbox ;
return preg_replace ( " /^ " . $acc_id . " ::/ " , '' , $mailbox );
}
2022-04-26 11:29:39 +02:00
}