Code

Replaced in_array calls for gosa-plugins
[gosa.git] / gosa-plugins / mail / admin / groups / mail / class_groupMail.inc
index 557537538018df33b001ed23116e26142efdc181..95acdd231d7b109120ea8721aae0585c3c2a826f 100644 (file)
@@ -11,7 +11,6 @@ class mailgroup extends plugin
   var $gosaMailForwardingAddress  = array();  // Forwarding also empty
   var $gosaMailServer             = "";       // Selected mailserver 
   var $gosaMailQuota              = "";       // Defined Quota 
-  var $quotaUsage                 = 0;        // Currently used quota
   var $gosaVacationMessage        = "";       // Vocation message 
   var $gosaSpamSortLevel          = "";     
   var $gosaSpamMailbox            = "";
@@ -20,13 +19,15 @@ class mailgroup extends plugin
   var $gosaMailMaxSize            = "";       // 
   var $FolderType                 = array("CAT" => '', "SUB_CAT" => '');
 
+  var $quotaUsage                 = -1;        // -1 Means undefined
+
   /* Internal */
   var $AclTypes                   = array();
   var $members                    = array();  // Group members
   var $mailusers                  = array();  // Group member with mail account
   var $folder_acls                = array();
   var $MailMethod = NULL; 
-  var $forward_dialog             = FALSE;    
+  var $mailAddressSelect             = FALSE;    
   var $remove_folder_from_imap    = true;
   var $view_logged                = FALSE;
   var $mailDomainPart             = "";
@@ -38,12 +39,27 @@ class mailgroup extends plugin
       "acl","gosaSharedFolderTarget", "gosaVacationMessage");
 
   var $objectclasses= array("gosaMailAccount");
-  var $multiple_support = TRUE;
+  var $multiple_support = FALSE; // Not tested yet
+
+  var $uid = "";
+  var $cn ="";
+  var $orig_cn = "";
+  var $show_effective_memeber = FALSE;
 
-  function __construct (&$config, $dn= NULL, $ui= NULL)
+  function __construct (&$config, $dn= NULL, $base_object= NULL)
   {
     plugin::plugin($config, $dn);
 
+    /* Get attributes from parent object
+     */
+    foreach(array("uid","cn") as $attr){
+      if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
+        $this->$attr = $this->parent->by_object['group']->$attr;
+      }elseif(isset($this->attrs[$attr])){
+        $this->$attr = $this->attrs[$attr][0];
+      }
+    }
+    $this->orig_cn = $this->uid = $this->cn;
 
     /* Intialize the used mailMethod
      */
@@ -52,19 +68,25 @@ class mailgroup extends plugin
     $this->mailMethod->fixAttributesOnLoad();
     $this->mailDomainParts      = $this->mailMethod->getMailDomains();
     $this->AvailableFolderTypes = $this->mailMethod->getAvailableFolderTypes();
-    $this->AclTypes             = $this->mailMethod->getAclTypes();
     $this->MailBoxes = array();
 
     /* Remember account status
      */
     $this->initially_was_account = $this->is_account;
 
+    /* While we are not not allowed to modify the mail address
+     *  and this is a new mail account, preset the user part of the 
+     *  mail address with the accounts cn.
+     */ 
+    if(!$this->mailMethod->isModifyableMail() && !$this->initially_was_account){
+      $this->mail = $base_object->cn;
+    }
+
     /* Load folder_acls with defaults.
       anyone -- The default acl, will be written to ldap.
       member -- The ACL used for the members.
-     */
-    $this->folder_acls['__anyone__'] = "p";
-    $this->folder_acls['__member__'] = "lrswp";
+     */ 
+    $this->folder_acls = $this->mailMethod->getDefaultACLs();
 
     /* Load acls
        The most used acl will be used as member acl, this
@@ -74,9 +96,11 @@ class mailgroup extends plugin
     $ldap = $this->config->get_ldap_link();
     if(isset($this->attrs['acl'])){
       for($i = 0; $i < $this->attrs['acl']['count'] ; $i++){
-        $str = trim($this->attrs['acl'][$i]);
-        $name = trim(preg_replace("/^([^\s]*).*$/","\\1",$str));
-        $acl  = trim(preg_replace("/^[^\s]*+\s/","",$str));
+
+        /* Be carefull here, since kolab22 uses spaces in the acls (herbert read anon/post)
+         */
+        $str = $this->attrs['acl'][$i];
+        list($name, $acl) = preg_split("/[ ]{1}/", $str, 2);
         if($name == "anyone") $name = "__anyone__";
         $this->folder_acls[$name] = $acl;
       }
@@ -89,37 +113,38 @@ class mailgroup extends plugin
 
         /* Read quota */
         $this->gosaMailQuota = $this->mailMethod->getQuota($this->gosaMailQuota);
+        $this->quotaUsage = $this->mailMethod->getQuotaUsage($this->quotaUsage);
         if($this->mailMethod->is_error()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot read quota settings: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
 
         /* Read mailboxes */
         $this->MailBoxes = $this->mailMethod->getMailboxList($this->MailBoxes);
         if($this->mailMethod->is_error()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot get list of mailboxes: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
 
         /* Receive folder types */
         $this->FolderType = $this->mailMethod->getFolderType($this->FolderType);
         if($this->mailMethod->is_error()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Could not receive folder types! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot receive folder types: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
 
         /* Receive permissions */  
         $this->folder_acls = $this->mailMethod->getFolderACLs($this->folder_acls);
         if($this->mailMethod->is_error()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Could not receive folder permissions! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot receive folder permissions: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
 
       }elseif(!$this->mailMethod->is_connected()){
-        msg_dialog::display(_("Mail error"), sprintf(_("Cannot connect mail method! Error was: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
               $this->mailMethod->get_error()), ERROR_DIALOG);
       }elseif(!$this->mailMethod->account_exists()){
-        msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Mailbox '%s' doesn't exists on mail server: %s"),
               $this->mailMethod->get_account_id(),$this->gosaMailServer), ERROR_DIALOG);
       }
 
@@ -129,7 +154,7 @@ class mailgroup extends plugin
         if($this->mailMethod->domainSelectionEnabled() || $this->mailMethod->mailEqualsCN()){
           $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
           $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
-          if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+          if(!in_array_strict($this->mailDomainPart,$this->mailDomainParts)){
             $this->mailDomainParts[] = $this->mailDomainPart;
           }
         }
@@ -149,15 +174,18 @@ class mailgroup extends plugin
     /* Disconnect mailMethod. Connect on demand later.
      */
     $this->mailMethod->disconnect();
+    $this->AclTypes = $this->mailMethod->getAclTypes();
 
     /* Summarize most used ACLs as member acl 
      */
     if(count($this->folder_acls) > 2){
       $acl_usage = array();
-      $most_acl = "";
+      $most_acl = $this->folder_acls['__member__'];
       $most_cnt = 0;
       $member = $this->get_member();
       foreach($this->folder_acls as $user => $acl){
+        if(preg_match("/^__/",$user)) continue;
+        if(!in_array_strict($user,$member['mail'])) continue; 
         if(!isset($acl_usage[$acl])) $acl_usage[$acl]=0;
         $acl_usage[$acl] ++;
         if($acl_usage[$acl] > $most_cnt){
@@ -168,7 +196,7 @@ class mailgroup extends plugin
       $this->folder_acls['__member__'] = $most_acl;  
       foreach($this->folder_acls as $name => $acl){
         if(preg_match("/^__/",$name)) continue;
-        if($acl == $most_acl && in_array($name,$member['mail'])){
+        if($acl == $most_acl && in_array_strict($name,$member['mail'])){
           unset($this->folder_acls[$name]);
         }
       }
@@ -197,6 +225,7 @@ class mailgroup extends plugin
     $ldap->cd($this->config->current['BASE']);
     if(isset($this->parent->by_object['group'])){
       foreach($this->parent->by_object['group']->memberUid as $uid){
+        if(!isset($this->parent->by_object['group']->dnMapping[$uid])) continue;
         $dn = $this->parent->by_object['group']->dnMapping[$uid];
         $member['all'][$uid] = $uid;
         if($ldap->object_match_filter($dn,"(&(objectClass=gosaMailAccount)(".$this->mailMethod->getUAttrib()."=*))")){
@@ -214,8 +243,8 @@ class mailgroup extends plugin
       foreach($users as $user){
         $member['all'][$user['uid'][0]] = $user['dn'];
         if(isset($user[$uattrib]) 
-            && in_array("gosaMailAccount",$user['objectClass']) 
-            && (in_array($user['uid'][0], $this->attrs['memberUid']))){
+            && in_array_strict("gosaMailAccount",$user['objectClass']) 
+            && (in_array_strict($user['uid'][0], $this->attrs['memberUid']))){
           $member['mail'][$user['uid'][0]] = $user[$uattrib][0];
         }
       }
@@ -234,8 +263,6 @@ class mailgroup extends plugin
       $this->view_logged = TRUE;
       new log("view","groups/".get_class($this),$this->dn);
     }
-
-    $this->get_member();
  
     /****************
       Account status
@@ -283,36 +310,59 @@ class mailgroup extends plugin
       }
     }
 
+    
+    /****************
+      Preset mail attribute
+     ****************/
+    if(empty($this->mail) && $this->mailMethod->mailEqualsCN() && !$this->initially_was_account){
+      if($this->mailMethod->domainSelectionEnabled()){
+        $this->mail = &$this->parent->by_object['group']->cn;
+      }
+    }
+
 
     /****************
       Forward addresses
      ****************/
+
     if (isset($_POST['add_local_forwarder'])){
-      $this->forward_dialog= TRUE;
+      $this->mailAddressSelect= new mailAddressSelect($this->config, get_userinfo());
       $this->dialog= TRUE;
     }
-    if (isset($_POST['add_locals_cancel'])){
-      $this->forward_dialog= FALSE;
+
+    if (isset($_POST['mailAddressSelect_cancel'])){
+      $this->mailAddressSelect= FALSE;
       $this->dialog= FALSE;
     }
-    if (isset($_POST['add_locals_finish'])){
-      if (isset($_POST['local_list'])){
-        if($this->acl_is_writeable("gosaMailForwardingAddress")){
-          foreach ($_POST['local_list'] as $val){
-            if (!in_array ($val, $this->gosaMailAlternateAddress) &&
-                $val != $this->mail){
-              $this->addForwarder($val);
-              $this->is_modified= TRUE;
-            }
+
+    if (isset($_POST['mailAddressSelect_save'])){
+      if($this->acl_is_writeable("gosaMailForwardingAddress")){
+        $list = $this->mailAddressSelect->save();
+        foreach ($list as $entry){
+          $val = $entry['mail'][0];
+          if (!in_array_strict($val, $this->gosaMailAlternateAddress) && $val != $this->mail){
+            $this->addForwarder($val);
+            $this->is_modified= TRUE;
           }
         }
-        $this->forward_dialog= FALSE;
+        $this->mailAddressSelect= FALSE;
         $this->dialog= FALSE;
       } else {
         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
       }
     }
 
+    if($this->mailAddressSelect instanceOf mailAddressSelect){
+      $used  = array();
+      $used['mail'] = array_values($this->gosaMailAlternateAddress);
+      $used['mail'] = array_merge($used['mail'], array_values($this->gosaMailForwardingAddress));
+      $used['mail'][] = $this->mail;
+
+      // Build up blocklist
+      session::set('filterBlacklist', $used);
+      return($this->mailAddressSelect->execute());
+    }
+
     if (isset($_POST['add_forwarder'])){
       if ($_POST['forward_address'] != ""){
         $address= $_POST['forward_address'];
@@ -327,7 +377,7 @@ class mailgroup extends plugin
             }
           }
         } elseif ($address == $this->mail
-            || in_array($address, $this->gosaMailAlternateAddress)) {
+            || in_array_strict($address, $this->gosaMailAlternateAddress)) {
           msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
         } else {
           $valid= TRUE;
@@ -343,9 +393,6 @@ class mailgroup extends plugin
     if (isset($_POST['delete_forwarder'])){
       $this->delForwarder ($_POST['forwarder_list']);
     }
-    if ($this->forward_dialog){
-      return($this->display_forward_dialog());
-    } 
 
  
     /****************
@@ -371,10 +418,14 @@ class mailgroup extends plugin
       }
       if ($valid && ($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
         $ui= get_userinfo();
-        if ($user != $ui->username){
-          msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."&nbsp;".
-              sprintf(_("Address is already in use by user '%s'."), $user), ERROR_DIALOG);
+        $addon= "";
+        if ($user[0] == "!") {
+          $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
+        } else {
+          $addon= sprintf(_("Address is already in use by user '%s'."), $user);
         }
+        msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
+            "$addon</i>", ERROR_DIALOG);
       }
     }
     if (isset($_POST['delete_alternate']) && isset($_POST['alternates_list'])){
@@ -390,16 +441,17 @@ class mailgroup extends plugin
     $smarty= get_smarty();
     $smarty->assign("initially_was_account", $this->initially_was_account);
     $smarty->assign("isModifyableMail", $this->mailMethod->isModifyableMail());
+    $smarty->assign("isModifyableServer", $this->mailMethod->isModifyableServer());
     $smarty->assign("mailEqualsCN", $this->mailMethod->mailEqualsCN());
     $smarty->assign("folder_acls" , $this->postable_acls());
     $smarty->assign("AclTypes" ,    $this->AclTypes);
+    $smarty->assign("Effective",    $this->get_effective_member_acls());
+    $smarty->assign("show_effective_memeber",    $this->show_effective_memeber);
   
     $smarty->assign("quotaEnabled", $this->mailMethod->quotaEnabled());
-    $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
-    if($this->mailMethod->is_connected()){ 
-      $smarty->assign("quotaUsage", $this->mailMethod->getQuotaUsage());
-    }else{
-      $smarty->assign("quotaUsage", _("Unknown")); 
+    if($this->mailMethod->quotaEnabled()){
+      $smarty->assign("gosaMailQuota",$this->gosaMailQuota);
+      $smarty->assign("quotaUsage",   mailMethod::quota_to_image($this->quotaUsage,$this->gosaMailQuota)); 
     }
 
     $smarty->assign("MailDomains", $this->mailDomainParts);
@@ -447,7 +499,7 @@ class mailgroup extends plugin
       Multi edit support 
      ******/
     foreach($this->attributes as $attr){
-      if(in_array($attr,$this->multi_boxes)){
+      if(in_array_strict($attr,$this->multi_boxes)){
         $smarty->assign("use_".$attr,TRUE);
       }else{
         $smarty->assign("use_".$attr,FALSE);
@@ -456,7 +508,7 @@ class mailgroup extends plugin
 
     /* Multiple support handling */
     foreach(array("kolabFolderType") as $attr){
-      if(in_array($attr,$this->multi_boxes)){
+      if(in_array_strict($attr,$this->multi_boxes)){
         $smarty->assign("use_".$attr,TRUE);
       }else{
         $smarty->assign("use_".$attr,FALSE);
@@ -490,7 +542,6 @@ class mailgroup extends plugin
     /* Zero arrays */
     $this->attrs['gosaMailAlternateAddress'] = array();
     $this->attrs['gosaMailForwardingAddress']= array();
-    $this->attrs['gosaSharedFolderTarget']= array();
 
     $this->mailMethod->fixAttributesOnRemove();
     $this->cleanup();
@@ -510,15 +561,15 @@ class mailgroup extends plugin
     if (!$this->is_template && $this->remove_folder_from_imap){
 
       if(!$this->mailMethod->connect()){
-        msg_dialog::display(_("Mail error"), sprintf(_("Cannot connect mail method! Error was: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
               $this->mailMethod->get_error()), ERROR_DIALOG);
       }else{
         if(!$this->mailMethod->deleteMailbox()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
         if(!$this->mailMethod->updateSharedFolder()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions! Error was: %s."),
+          msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions: %s"),
                 $this->mailMethod->get_error()), ERROR_DIALOG);
         }
       }
@@ -545,9 +596,17 @@ class mailgroup extends plugin
     }
     if (isset($_POST['mailedit'])){
 
+      if(isset($_POST['show_effective_memeber'])){
+        $this->show_effective_memeber = !$this->show_effective_memeber;
+      }
+
       $mail = $this->mail;
+      $server = $this->gosaMailServer;
       plugin::save_object();
 
+      if(!$this->mailMethod->isModifyableServer() && $this->initially_was_account){
+        $this->gosaMailServer = $server;
+      }
       if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
         $this->mail = $mail;
       }else{
@@ -562,7 +621,7 @@ class mailgroup extends plugin
       /* Get posted mail domain part, if necessary
        */
       if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
-        if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
+        if(in_array_strict(get_post('MailDomain'), $this->mailDomainParts)){
           $this->mailDomainPart = get_post('MailDomain');
         }
       }
@@ -608,7 +667,7 @@ class mailgroup extends plugin
           }
         }
         if(isset($_POST['add_acl_user'])){
-          $new_acls[_('new')] = $this->folder_acls['__anyone__'];
+          $new_acls[_('New')] = $this->folder_acls['__anyone__'];
         }
         $this->folder_acls = $new_acls;
       }
@@ -687,6 +746,12 @@ class mailgroup extends plugin
     $member = $this->get_member();
     $new_folder_acls = array("anyone" => $this->folder_acls['__anyone__']);
     foreach($member['mail'] as $uid => $mail){
+
+      /* Do not save overridden acls */
+      if(isset($this->folder_acls[$mail])){
+        continue;
+      }
+
       $this->acl[] = $mail." ".$this->folder_acls['__member__'];
       $new_folder_acls[$mail]=$this->folder_acls['__member__'];
     }
@@ -697,7 +762,7 @@ class mailgroup extends plugin
     }
     $this->folder_acls = $new_folder_acls;
     $this->acl = array_unique($this->acl);
-      
+     
     /* Call parents save to prepare $this->attrs */
     plugin::save();
 
@@ -726,15 +791,15 @@ class mailgroup extends plugin
      */
     $this->mailMethod->connect();
     if(!$this->mailMethod->is_connected()){
-      msg_dialog::display(_("Mail error"), sprintf(_("Cannot connect mail method! Error was: %s."),
+      msg_dialog::display(_("Mail error"), sprintf(_("Mail method cannot connect: %s"),
             $this->mailMethod->get_error()), ERROR_DIALOG);
     }else{
       if(!$this->mailMethod->updateMailbox()){
-        msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox! Error was: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Cannot update mailbox: %s"),
               $this->mailMethod->get_error()), ERROR_DIALOG);
       }
       if(!$this->mailMethod->setQuota($this->gosaMailQuota)){
-        msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings! Error was: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Cannot write quota settings: %s"),
               $this->mailMethod->get_error()), ERROR_DIALOG);
       }
       /* Save Folder Types, if available 
@@ -743,7 +808,7 @@ class mailgroup extends plugin
         $this->mailMethod->setFolderType($this->FolderType);
       }
       if(!$this->mailMethod->setFolderACLs($this->folder_acls)){
-        msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions! Error was: %s."),
+        msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions: %s"),
               $this->mailMethod->get_error()), ERROR_DIALOG);
       }
     }
@@ -767,16 +832,26 @@ class mailgroup extends plugin
     if(!$this->is_account) return array();
     $ldap= $this->config->get_ldap_link();
 
+
     /* Call common method to give check the hook */
     $message= plugin::check();
 
+    /* Ensure that this group isn't renamed if the mailMethod enforces cn mailAttributes 
+     */
+    if($this->mailMethod->mailEqualsCN() && $this->initially_was_account){
+      if($this->cn != $this->orig_cn){
+        $message[] = sprintf(_("The group 'cn' has changed. It can't be changed due to the fact that mail method '%s' relies on it!")
+            ,get_class($this->mailMethod));
+      }
+    }
+
     if(empty($this->gosaMailServer)){
       $message[]= msgPool::noserver(_("Mail"));
     }
 
     /* Mail address checks */
+    $mail = $this->mail;
     if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
-      $mail = $this->mail;
       if($this->mailMethod->domainSelectionEnabled() || $this->mailMethod->mailEqualsCN()){
         $mail.= "@".$this->mailDomainPart;
       }
@@ -796,6 +871,16 @@ class mailgroup extends plugin
       }
     }
 
+    /* Check if this mail address is already in use */
+    $ldap->cd($this->config->current['BASE']);
+    $filter = "(&(!(objectClass=gosaUserTemplate))(!(cn=".$this->cn."))".
+           "(objectClass=gosaMailAccount)".
+           "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
+    $ldap->search($filter,array("cn"));
+    if ($ldap->count() != 0){
+           $message[]= msgPool::duplicated(_("Mail address"));
+    }
+
     /* Check rejectsize for integer */
     if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){
       if (!is_numeric($this->gosaMailMaxSize)){
@@ -824,7 +909,7 @@ class mailgroup extends plugin
 
     foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
  
-      if (in_array($val, $skip)){
+      if (in_array_strict($val, $skip)){
         continue;
       }
 
@@ -955,7 +1040,7 @@ class mailgroup extends plugin
     $this->gosaMailForwardingAddress_Some = array();
     if(isset($all['gosaMailForwardingAddress'])){
       for($i = 0 ; $i < $all['gosaMailForwardingAddress']['count'] ; $i++){
-        if(!in_array($all['gosaMailForwardingAddress'][$i],$this->gosaMailForwardingAddress)){
+        if(!in_array_strict($all['gosaMailForwardingAddress'][$i],$this->gosaMailForwardingAddress)){
           $this->gosaMailForwardingAddress_Some[] = $all['gosaMailForwardingAddress'][$i];
         }
       }
@@ -1007,11 +1092,11 @@ class mailgroup extends plugin
     $ret = plugin::get_multi_edit_values();
     $ret['Forward_some'] = $this->gosaMailForwardingAddress_Some;    
     $ret['Forward_all'] = $this->gosaMailForwardingAddress;    
-    if(in_array('kolabFolderType',$this->multi_boxes)){
+    if(in_array_strict('kolabFolderType',$this->multi_boxes)){
       $ret['kolabFolderTypeType'] = $this->kolabFolderTypeType;
       $ret['kolabFolderTypeSubType'] = $this->kolabFolderTypeSubType;
     }
-    if(in_array("acl",$this->multi_boxes)){
+    if(in_array_strict("acl",$this->multi_boxes)){
       $ret['imapacl'] = $this->imapacl;
     }
     return($ret);
@@ -1021,7 +1106,7 @@ class mailgroup extends plugin
   {
     $forward = array();
     foreach($attrs['Forward_some'] as $addr){
-      if(in_array($addr,$this->gosaMailForwardingAddress)){
+      if(in_array_strict($addr,$this->gosaMailForwardingAddress)){
         $forward[] = $addr;
       }
     }
@@ -1033,95 +1118,11 @@ class mailgroup extends plugin
   }
 
 
-  /*! \brief  Displays a dialog that allows mail address selection.
-   */
-  function display_forward_dialog()
-  {
-    restore_error_handler();
-
-    $smarty = get_smarty();
-    $ldap= $this->config->get_ldap_link();
-
-    /* Save data */
-    $mailfilter= session::get("mailfilter");
-    foreach( array("depselect", "muser", "regex") as $type){
-      if (isset($_POST[$type])){
-        $mailfilter[$type]= $_POST[$type];
-      }
-    }
-    if (isset($_GET['search'])){
-      $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
-      if ($s == "**"){
-        $s= "*";
-      }
-      $mailfilter['regex']= $s;
-    }
-    session::set("mailfilter", $mailfilter);
-
-    /* Get actual list */
-    $mailusers= array ();
-    if ($mailfilter['regex'] != '*' && $mailfilter['regex'] != ""){
-      $regex= $mailfilter['regex'];
-      $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
-    } else {
-      $filter= "";
-    }
-    if ($mailfilter['muser'] != ""){
-      $user= $mailfilter['muser'];
-      $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
-    }
-
-    /* Add already present people to the filter */
-    $exclude= "";
-    foreach ($this->gosaMailForwardingAddress as $mail){
-      $exclude.= "(mail=$mail)";
-    }
-    if ($exclude != ""){
-      $filter.= "(!(|$exclude))";
-    }
-    $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $mailfilter['depselect'],
-        array("sn", "mail", "givenName"), GL_SIZELIMIT | GL_SUBSEARCH);
-    $ldap->cd($mailfilter['depselect']);
-    $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
-    while ($attrs= $ldap->fetch()){
-      if(preg_match('/%/', $attrs['mail'][0])){
-        continue;
-      }
-      $name= $this->make_name($attrs);
-      $mailusers[$attrs['mail'][0]]= $name."&lt;".
-        $attrs['mail'][0]."&gt;";
-    }
-    natcasesort ($mailusers);
-    reset ($mailusers);
-
-    /* Show dialog */
-    $smarty->assign("search_image", get_template_path('images/lists/search.png'));
-    $smarty->assign("usearch_image", get_template_path('images/lists/search-user.png'));
-    $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
-    $smarty->assign("infoimage", get_template_path('images/info.png'));
-    $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
-    $smarty->assign("mailusers", $mailusers);
-    if (isset($_POST['depselect'])){
-      $smarty->assign("depselect", $_POST['depselect']);
-    }
-    $smarty->assign("deplist", $this->config->idepartments);
-    $smarty->assign("apply", apply_filter());
-    $smarty->assign("alphabet", generate_alphabet());
-    $smarty->assign("hint", print_sizelimit_warning());
-    foreach( array("depselect", "muser", "regex") as $type){
-      $smarty->assign("$type", $mailfilter[$type]);
-    }
-    $smarty->assign("hint", print_sizelimit_warning());
-    $display= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE, dirname(__FILE__)));
-    return ($display);
-  }
-
-
   /*! \brief  Add given mail address to the list of forwarders.
    */
   function addForwarder($address)
   {
-    if(empty($address)) continue;
+    if(empty($address)) return;
     $this->gosaMailForwardingAddress[]= $address;
     $this->gosaMailForwardingAddress= array_unique($this->gosaMailForwardingAddress);
 
@@ -1141,7 +1142,7 @@ class mailgroup extends plugin
    */
   function delForwarder($addresses)
   {
-    if(empty($address)) continue;
+    if(empty($addresses)) return;
     $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
         $this->gosaMailForwardingAddress);
 
@@ -1167,15 +1168,18 @@ class mailgroup extends plugin
     /* Is this address already assigned in LDAP? */
     $ldap->cd ($this->config->current['BASE']);
     $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
-        "(gosaMailAlternateAddress=$address)))");
+        "(gosaMailAlternateAddress=$address)))", array("cn", "uid"));
 
     if ($ldap->count() > 0){
       $attrs= $ldap->fetch ();
+      if (!isset($attrs["uid"])) {
+        return ("!".$attrs["cn"][0]);
+      }
       return ($attrs["uid"][0]);
     }
 
     /* Add to list of alternates */
-    if (!in_array($address, $this->gosaMailAlternateAddress)){
+    if (!in_array_strict($address, $this->gosaMailAlternateAddress)){
       $this->gosaMailAlternateAddress[]= $address;
     }
 
@@ -1191,7 +1195,7 @@ class mailgroup extends plugin
    */
   function delAlternate($addresses)
   {
-    if(empty($address)) continue;
+    if(!count($addresses)) return;
     $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
         $this->gosaMailAlternateAddress);
     $this->is_modified= TRUE;
@@ -1207,7 +1211,25 @@ class mailgroup extends plugin
     return($ret);
   }
 
-  
+
+  function get_effective_member_acls()
+  {
+    $tmp = array();
+    $member = $this->get_member();
+    foreach($member['mail'] as $uid => $mail){
+
+      /* Do not save overridden acls */
+      if(isset($this->folder_acls[$mail])){
+        continue;
+      }
+
+      
+      $tmp[$mail]  = $this->folder_acls['__member__'];
+    }
+    return($tmp);
+  }
+
+
   function allow_remove()
   {
     $resason = "";