Index: trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 1523)
+++ trunk/expressoAdmin1_2/inc/class.imap_functions.inc.php	(revision 1913)
@@ -126,5 +126,5 @@
 	}
 	
-	function delete_user($uid)
+	function delete_mailbox($uid)
 	{
 		$result['status'] = true;
@@ -137,5 +137,5 @@
 		{
 			$result['status'] = false;
-			$result['msg'] = $this->functions->lang('it was not possible to delete users mailbox') . ".\n";
+			$result['msg'] = $this->functions->lang('it was not possible to delete mailbox') . ".\n";
 			$result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error();
 		}
@@ -193,16 +193,34 @@
 		return $result;
 	}
-	
+	function empty_user_inbox($params){
+	       if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox'))
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('You do not have access to clean an user inbox');
+			return $result;
+		} else return $this->empty_inbox($params);
+		
+        }
+        function empty_shared_account_inbox($params){
+            if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox'))
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('You do not have right to empty an shared account inbox');
+			return $result;
+		} else return $this->empty_inbox($params);
+        }
 	function empty_inbox($params)
 	{
 		// Verifica o acesso do gerente
-		if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox'))
-		{
-			$result['status'] = false;
-			$result['msg'] = $this->functions->lang('You do not have access to clean an user inbox');
-			return $result;
-		}
-		
-		if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
+		if (!($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox') ||
+                      $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox')
+                  ))
+		{
+			$result['status'] = false;
+			$result['msg'] = $this->functions->lang('You do not have access to clean an inbox');
+			return $result;
+		}
+
+                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
 		{
 			$imap_options = '/tls/novalidate-cert';
@@ -241,5 +259,5 @@
 			{
 				$result['status'] = false;
-				$result['msg'] = $this->functions->lang('It was not possible clean the users inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
+				$result['msg'] = $this->functions->lang('It was not possible clean the inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error();
 			}
 		}
@@ -251,3 +269,124 @@
 		return $result;
 	}
+	function getaclfrombox($params)
+	{
+		$boxacl = $params['uid'];
+		
+		$return = array();	
+		
+		$mbox_acl = imap_getacl($this->imap, "user" . $this->imapDelimiter . $boxacl);
+		
+		foreach ($mbox_acl as $user => $acl)
+		{
+			if ($user != $boxacl )
+			{
+				$return[$user] = $acl;
+			}
+		}
+		return $return;
+	}
+	function setaclfrombox($user, $acl, $mailbox)
+	{
+		$serverString = '{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}';
+		$mailboxes_list = imap_getmailboxes($this->imap, $serverString, "user".$this->imapDelimiter.$mailbox.$this->imapDelimiter."*");                
+		$result = Array();
+                $result['status'] = true;
+                if (is_array($mailboxes_list))
+		{
+                        $folder = str_replace($serverString, "", imap_utf7_encode("user".$this->imapDelimiter.$mailbox));
+                        $folder = str_replace("&-", "&", $folder);
+
+                        if (imap_setacl ($this->imap, $folder, $user, $acl) ) {
+                            foreach ($mailboxes_list as $key => $val)
+                            {
+                                    $folder = str_replace($serverString, "", imap_utf7_encode($val->name));
+                                    $folder = str_replace("&-", "&", $folder);
+                                    if (!imap_setacl ($this->imap, $folder, $user, $acl))
+                                    {
+                                            $result['status'] = false;
+                                            $result['msg']  = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl';
+                                            $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error();
+                                            break;
+                                    }
+                            }
+                        } else {
+                            $result['status'] = false;
+                            $result['msg']  = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl';
+                            $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error();
+                            break;
+                        }
+		}
+		return $result;
+	}
+        function save_shared_account($params){           
+            //Rename mailbox
+            $result = Array();
+            $result['status'] = true;
+            if($params['uid'] != $params['old_uid'] ){
+                    $result = $this->rename_mailbox($params['old_uid'], $params['uid']);
+                    if(!$result['status']) return $result;
+            }
+
+            //Begin edit Quota
+            $quota = $this->get_user_info($params['uid'] );
+
+            if ( $quota['mailquota'] != $params['mailquota'] ){
+                    if(!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_quote') )
+                    {
+                                $result['status'] = false;
+                                $result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox quota');
+                                return $result;
+                    } else $this->change_user_quota($params['old_uid'], $params['mailquota']);
+            }
+            //End Edit Quota
+ 
+            /* Begin Set ACL */
+            //Old users set in the box
+            $owners_acl_old = $this->getaclfrombox($params);
+            //new settings
+            $owners_acl_new = unserialize($params['owners_acl']);
+
+            $owners_to_remove = array_diff_assoc($owners_acl_old,$owners_acl_new);
+            $owners_to_add = array_diff_assoc($owners_acl_new,$owners_acl_old);
+
+            //Find modified users
+            $tmp_update = array_diff_assoc($owners_acl_old,$owners_to_remove);
+            $owners_to_update = Array();
+            foreach($tmp_update  as $user => $acl){
+                if($owners_acl_old[$user] != $acl){
+                    $owners_to_update[$user] = $acl;
+                }
+            }
+            
+            //Check Modify manage acl
+            
+            if( (count($owners_to_remove) > 0 || count($owners_to_add) > 0 || count($owners_to_update) > 0) && !$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_acl') ){
+                $result['status'] = false;
+		$result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox acl');
+		return $result;
+            }
+            
+            if( is_array($owners_acl_new)){
+                foreach($owners_to_remove as $user => $acl){
+                    $params['user'] = $user;
+                    $params['acl'] = "none";
+                    $user = $params['user'];
+                    $result = $this->setaclfrombox($user,"none",$params['uid']);
+                }
+                //add new users
+                foreach($owners_to_add as $user => $acl){
+                    $params['user'] = $user;
+                    $params['acl'] = $acl;
+                    $result = $this->setaclfrombox($user,$acl,$params['uid']);
+                }
+                //update users
+                 foreach($owners_to_update as $user => $acl){
+                    $params['user'] = $user;
+                    $params['acl'] = $acl;
+                    $result = $this->setaclfrombox($user,$acl,$params['uid']);
+                }               
+            }
+            /* End Set Acl */
+            return $result;
+        }
 }
