Code

Updated css und div framework.
[gosa.git] / plugins / admin / groups / class_groupMail.inc
index 32ae8a21dde9d536b81a00172b9da46d6a323425..03c9987d1affa5473b0e2659ecc479fc6ec661a5 100644 (file)
@@ -9,6 +9,7 @@ class mailgroup extends plugin
 
   var $uid                        = "";       // User id 
   var $cn                         = "";       // cn
+  var $orig_cn                    = "";       // cn
 
   var $method                     = "mailMethod"; // Used Mail method 
   var $mmethod                    = "";           // Contains the gosa.conf MAILMETHOD
@@ -40,20 +41,21 @@ class mailgroup extends plugin
   var $perms                      = array();
   var $gosaMailDeliveryMode       = "[L        ]";   // 
   var $gosaMailMaxSize            = "";       // 
-
+  
+  var $remove_folder_from_imap    = true;
 
   /* Helper */
   var $indexed_acl= array();
   var $indexed_user= array();
 
   /* attribute list for save action */
-  var $attributes= array(   "mail",   "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
+  var $attributes= array( "mail",   "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
       "gosaMailAlternateAddress", "gosaMailForwardingAddress",
       "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
       "acl","gosaSharedFolderTarget", "gosaVacationMessage");
 
   var $objectclasses= array("gosaMailAccount");
-
+  var $CopyPasteVars          = array("quotaUsage","imapacl");
 
   function mailgroup ($config, $dn= NULL, $ui= NULL)
   {
@@ -61,6 +63,8 @@ class mailgroup extends plugin
      */
     plugin::plugin($config, $dn);
 
+    $this->orig_cn = $this->cn;
+
     /* Set mailMethod to the one defined in gosa.conf 
      */
     if (isset($this->config->current['MAILMETHOD'])){
@@ -112,10 +116,7 @@ class mailgroup extends plugin
         $method= new $this->method($this->config);
 
         if ($method->connect($this->attrs["gosaMailServer"][0])){
-
-          /*  get Quota
-           */
-          $quota= $method->getQuota($this->uid);
+        
 
           /* Maybe the entry is not saved in new style, get
              permissions from IMAP and convert them to acl attributes */
@@ -154,21 +155,30 @@ class mailgroup extends plugin
             }
 
           } // ENDE ! isset ($this->attrs['acl'])
+          
+          /* Adapt attributes if needed */
+          $method->fixAttributesOnLoad($this);
+          
+          /*  get Quota */
+          $quota= $method->getQuota($this->uid);
 
           /* Update quota values */
-          if ($quota['gosaMailQuota'] == 2147483647){
-            $this->quotaUsage= "";
-            $this->gosaMailQuota= "";
-          } else {
-            $this->quotaUsage= $quota['quotaUsage'];
-            $this->gosaMailQuota= $quota['gosaMailQuota'];
+          if(is_array($quota)){
+            if ($quota['gosaMailQuota'] == 2147483647){
+              $this->quotaUsage= "";
+              $this->gosaMailQuota= "";
+            } else {
+              $this->quotaUsage= $quota['quotaUsage'];
+              $this->gosaMailQuota= $quota['gosaMailQuota'];
+            }
+          }else{
+            $this->quotaUsage     = "";
+            $this->gosaMailQuota  = "";
+//            print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
           }
           $method->disconnect();
         }   // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
 
-        /* Adapt attributes if needed */
-        $method->fixAttributesOnLoad($this);
-
       }   // ENDE gosaMailServer
 
     }   // ENDE dn != "new"
@@ -269,12 +279,18 @@ class mailgroup extends plugin
       }
     }
 
+    /* Load Mailserver  
+     */
+    if(isset($this->attrs['gosaMailServer'][0])){
+      $this->gosaMailServer =  $this->attrs['gosaMailServer'][0];
+    }
     /* Fill translations */
     $this->perms["lrs"]= _("read");
     $this->perms["lrsp"]= _("post");
     $this->perms["p"]= _("external post");
     $this->perms["lrsip"]= _("append");
     $this->perms["lrswipcd"]= _("write");
+    $this->perms[""]= _("none");
   }
 
   function execute()
@@ -284,6 +300,13 @@ class mailgroup extends plugin
 
     /* Load templating engine */
     $smarty= get_smarty();
+
+    /* Assign acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation) {
+      $smarty->assign($name."ACL",$this->getacl($name));
+    }
+
     if ($_SESSION['js']==FALSE){
       $smarty->assign("javascript", "false");
     } else {
@@ -291,13 +314,20 @@ class mailgroup extends plugin
     }
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
+    $display = "";
+
     /* Do we represent a valid account? */
     if (!$this->is_account && $this->parent == NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
+
+      $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
         _("This 'dn' has no valid mail extensions.")."</b>";
       return ($display);
     }
@@ -306,41 +336,58 @@ class mailgroup extends plugin
     $display= "";
     if ($this->parent != NULL){
       if ($this->is_account){
-        $display= $this->show_header(_("Remove mail account"),
+        $display.= $this->show_disable_header(_("Remove mail account"),
             _("This account has mail features enabled. You can disable them by clicking below."));
       } else {
-        $display= $this->show_header(_("Create mail account"),
+        $display.= $this->show_enable_header(_("Create mail account"),
             _("This account has mail features disabled. You can enable them by clicking below."));
+  
+        /* Show checkbox that allows us to remove imap entry too*/
+        if($this->initially_was_account){
+          $c = "";
+          if($this->remove_folder_from_imap){
+            $c= " checked ";
+          }
+          $display .= "<h2>Shared folder delete options</h2>
+                       <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
+                        title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
+          $display .= _("Remove the shared folder and all its contents after saving this account");
+        }
         return ($display);
       }
     }
 
     /* Add ACL? */
-    foreach ($this->indexed_user as $nr => $user){
-      if (isset($_POST["add_$nr"])){
-        $this->imapacl[""]= "l";
-      }
-      if (isset($_POST["del_$nr"])){
-        unset ($this->imapacl[$user]);
+    if($this->acl_is_writeable("acl")){
+      foreach ($this->indexed_user as $nr => $user){
+        if (isset($_POST["add_$nr"])){
+          $this->imapacl[""]= "l";
+        }
+        if (isset($_POST["del_$nr"])){
+          unset ($this->imapacl[$user]);
+        }
       }
     }
 
     /* Trigger forward add dialog? */
-    if (isset($_POST['add_local_forwarder'])){
-      $this->forward_dialog= TRUE;
-      $this->dialog= TRUE;
+    if($this->acl_is_writeable("gosaMailForwardingAddress")){
+      if (isset($_POST['add_local_forwarder'])){
+        $this->forward_dialog= TRUE;
+        $this->dialog= TRUE;
+      }
     }
 
     /* Cancel forward add dialog? */
-    if (isset($_POST['add_locals_cancel'])){
-      $this->forward_dialog= FALSE;
-      $this->dialog= FALSE;
+    if($this->acl_is_writeable("gosaMailForwardingAddress")){
+      if (isset($_POST['add_locals_cancel'])){
+        $this->forward_dialog= FALSE;
+        $this->dialog= FALSE;
+      }
     }
 
     /* Finished adding of locals? */
-    if (isset($_POST['add_locals_finish'])){
-      if (count ($_POST['local_list']) &&
-          chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+    if ((isset($_POST['add_locals_finish'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))) {
+      if (count ($_POST['local_list']) && $this->acl_is_writeable("gosaMailForwardingAddress")){
 
         /* Walk through list of forwarders, ignore own addresses */
         foreach ($_POST['local_list'] as $val){
@@ -356,7 +403,7 @@ class mailgroup extends plugin
     }
 
     /* Add forward email addresses */
-    if (isset($_POST['add_forwarder'])){
+    if ((isset($_POST['add_forwarder'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
       if ($_POST['forward_address'] != ""){
 
         /* Valid email address specified? */
@@ -374,7 +421,7 @@ class mailgroup extends plugin
         } else {
 
           /* Add it */
-          if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+          if ($this->acl_is_writeable("gosaMailForwardingAddress")){
             $this->addForwarder ($address);
           }
 
@@ -383,9 +430,8 @@ class mailgroup extends plugin
     }
 
     /* Delete forward email addresses */
-    if (isset($_POST['delete_forwarder'])){
-      if (count($_POST['forwarder_list'])
-          && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+    if (isset($_POST['delete_forwarder']) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
+      if (count($_POST['forwarder_list'])&& $this->acl_is_writeable("gosaMailForwardingAddress")){
 
         $this->delForwarder ($_POST['forwarder_list']);
       }
@@ -393,8 +439,7 @@ class mailgroup extends plugin
 
     /* Add alternate email addresses */
     if (isset($_POST['add_alternate'])){
-      if ($_POST['alternate_address'] != "" &&
-          chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
+      if ($_POST['alternate_address'] != "" && $this->acl_is_writeable("gosaMailAlternateAddress")){
 
         if (!is_email($_POST['alternate_address'])){
           print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
@@ -409,11 +454,11 @@ class mailgroup extends plugin
     }
 
     /* Delete alternate email addresses */
-    if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
-      if (count($_POST['alternates_list']) &&
-          chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
-
-        $this->delAlternate ($_POST['alternates_list']);
+    if($this->acl_is_writeable("gosaMailAlternateAddress")){
+      if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
+        if (count($_POST['alternates_list']) && $this->acl_is_writeable("gosaMailAlternateAddress")){
+          $this->delAlternate ($_POST['alternates_list']);
+        }
       }
     }
 
@@ -459,8 +504,8 @@ class mailgroup extends plugin
         $filter.= "(!(|$exclude))";
       }
 
-      $acl= array($this->config->current['BASE'] => ":all");
-      $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
+      $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $gmailfilter['depselect'],
+                     array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
       $ldap->cd($gmailfilter['depselect']);
       $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
       error_reporting (0);
@@ -496,7 +541,6 @@ class mailgroup extends plugin
     }
 
     /* Assemble normal permissions */
-    $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
     if (isset($this->imapacl['anyone'])){
       $smarty->assign("default_permissions", $this->imapacl['anyone']);
     }
@@ -506,31 +550,61 @@ class mailgroup extends plugin
     }
 
     /* Assemble extra attributes */
-    $perm= chkacl($this->acl, "permissions");
+    $perm= $this->getacl( "permissions");
     $tmp= "";
     $nr= 0;
     $count= count($this->imapacl);
     $this->indexed_user= array();
     $this->indexed_acl= array();
     foreach($this->imapacl as $user => $acl){
+
+      /* Add additional acl settings */
       if ($user != "anyone" && $user != "%members%"){
-        $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
-          "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
-        foreach ($this->perms as $key => $value){
-          if ($acl == $key){
-            $tmp.= "<option value=$key selected>$value</option>";
-          } else {
-            $tmp.= "<option value=$key>$value</option>";
+
+        $Dis  = "";
+        if(!preg_match("/w/",$perm)){
+          $Dis = " disabled ";
+        }
+  
+        /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */
+        if(!preg_match("/r/",$perm)){
+          $user = "";
+          $nr   = "none";
+          $key  = "none";  
+        }
+
+        $tmp.= "<tr>  
+                 <td>
+                  <input name=\"user_$nr\" size=20 maxlength=60 value=\"$user\" ".$Dis.">
+                 </td>
+                 <td>
+                 <select size=\"1\" name=\"perm_$nr\" ".$Dis.">";
+
+        /* Add acl options for this additional acl setting */
+        if(preg_match("/r/",$perm)){
+          foreach ($this->perms as $key => $value){
+            if ($acl == $key){
+              $tmp.= "<option value=$key selected>$value</option>";
+            } else {
+              $tmp.= "<option value=$key>$value</option>";
+            }
           }
         }
         $tmp.= "</select>&nbsp;";
+
+
+        
         if ($nr == $count - 1){
-          $tmp.= "<input type=submit value=\""._("Add")."\" ".
-            "name=\"add_$nr\" $perm>";
+          if($this->acl_is_writeable("acl")){
+            $tmp.= "<input type=submit value=\""._("Add")."\" ".
+              "name=\"add_$nr\" >";
+          }
         }
         if ($count > 3){
-          $tmp.= "<input type=submit value=\""._("Remove")."\" ".
-            "name=\"del_$nr\" $perm></td></tr>";
+          if($this->acl_is_writeable("acl")){
+            $tmp.= "<input type=submit value=\""._("Remove")."\" ".
+              "name=\"del_$nr\" ></td></tr>";        
+          }
         }
       }
       $this->indexed_user[$nr]= $user;
@@ -547,11 +621,15 @@ class mailgroup extends plugin
     foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
           "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
       $smarty->assign("$val", $this->$val);
-      $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
     }
     if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
-      $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
-      $smarty->assign("quotadefined", "true");
+      if($this->acl_is_readable("gosaMailQuota")){
+        $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
+        $smarty->assign("quotadefined", "true");
+      }else{
+        $smarty->assign("quotadefined", "true");
+        $smarty->assign("quotausage", "-");
+      }
     } else {
       $smarty->assign("quotadefined", "false");
     }
@@ -569,7 +647,6 @@ class mailgroup extends plugin
      */
     if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
       $this->attributes[]="acl";
-      $this->attributes[]="kolabHomeServer";
       $this->objectclasses[] = "kolabSharedFolder";
     }
     /* include global link_info */
@@ -583,24 +660,24 @@ class mailgroup extends plugin
     $this->attrs['gosaMailForwardingAddress']= array();
     $this->attrs['gosaSharedFolderTarget']= array();
 
-    /* Keep uid */
-    unset ($this->attrs['uid']);
-    $ldap->cd($this->dn);
-    $this->cleanup();
-    $ldap->modify ($this->attrs); 
-
-    show_ldap_error($ldap->get_error());
-
     /* Connect to IMAP server for account deletion */
-    if ($this->is_account){
+    if ($this->initially_was_account){
       $method= new $this->method($this->config);
-      if ($method->connect($this->attrs["gosaMailServer"][0])){
+      $method->fixAttributesOnRemove($this);
+      if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
+
         /* Remove account from IMAP server */
         $method->deleteMailbox($this->uid);
         $method->disconnect();
       }
-      $method->fixAttributesOnRemove($this);
     }
+    /* Keep uid */
+    unset ($this->attrs['uid']);
+
+    $ldap->cd($this->dn);
+    $ldap->modify ($this->attrs); 
+    show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events("remove");
@@ -610,6 +687,16 @@ class mailgroup extends plugin
   /* Save data to object */
   function save_object()
   {
+
+    /* Check if user wants to remove the shared folder from imap too */
+    if($this->initially_was_account && !$this->is_account){
+      if(isset($_POST['remove_folder_from_imap'])){
+        $this->remove_folder_from_imap = true;
+      }else{
+        $this->remove_folder_from_imap = false;
+      }
+    }
+
     /* Assemble mail delivery mode
        The mode field in ldap consists of values between braces, this must
        be called when 'mail' is set, because checkboxes may not be set when
@@ -624,36 +711,44 @@ C: Use custom sieve script
 I: Only insider delivery */
     if (isset($_POST['mailedit'])){
 
-      /* Save ldap attributes */
       plugin::save_object();
 
-      $tmp= "";
-      if (!isset($_POST["drop_own_mails"])){
-        $tmp.= "L";
-      }
-      if (isset($_POST["use_mailsize_limit"])){
-        $tmp.= "R";
-      }
-      if (isset($_POST["use_spam_filter"])){
-        $tmp.= "S";
-      }
-      if (isset($_POST["use_vacation"])){
-        $tmp.= "V";
-      }
-      if (isset($_POST["own_script"])){
-        $tmp.= "C";
+      $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
+
+      /* Handle delivery flags */
+      if($this->acl_is_writeable("gosaMailDeliveryModeL")){
+        if(!preg_match("/L/",$tmp) && !isset($_POST['drop_own_mails'])){
+          $tmp.="L";
+        }elseif(preg_match("/L/",$tmp) && isset($_POST['drop_own_mails'])){
+          $tmp = preg_replace("/L/","",$tmp);
+        }
       }
-      if (isset($_POST["only_local"])){
-        $tmp.= "I";
+
+      $opts = array(
+          "R"   => "use_mailsize_limit",
+          "S"   => "use_spam_filter",
+          "V"   => "use_vacation",
+          "C"   => "own_script",
+          "I"   => "only_local");
+
+      foreach($opts as $flag => $post){
+        if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
+          if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
+            $tmp.= $flag;
+          }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
+            $tmp = preg_replace("/".$flag."/","",$tmp);
+          }
+        }
       }
-      $tmp= "[$tmp]";
 
-      if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
-        $this->gosaMailDeliveryMode= $tmp;
+      $tmp= "[$tmp]";
+      if ($this->gosaMailDeliveryMode != $tmp){
+        $this->is_modified= TRUE;
       }
+      $this->gosaMailDeliveryMode= $tmp;
 
       /* Collect data and re-assign it to the imapacl array */
-      if (chkacl($this->acl, "permissions") == ""){
+      if ($this->acl_is_writeable("acl")){
         $this->imapacl= array();
         $this->imapacl['%members%']= $_POST['member_permissions'];
         $this->imapacl['anyone']= $_POST['default_permissions'];
@@ -686,9 +781,7 @@ I: Only insider delivery */
     /* Save arrays */
     $this->attrs['gosaMailAlternateAddress']  = $this->gosaMailAlternateAddress;
     $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
-
-    /* Save shared folder target */
-    $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
+    $this->attrs['gosaSharedFolderTarget']    = "share+".$this->uid;
 
     if(preg_match("/kolab/i",$this->mmethod)){
       /* Save acl's */
@@ -728,25 +821,9 @@ I: Only insider delivery */
     }  
 
 
-    if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
-      $method= new $this->method($this->config);
-      $method->fixAttributesOnStore($this);
-      if (($method->connect($this->gosaMailServer))){
-        $method->updateMailbox($this->uid);
-        $method->setQuota($this->uid, $this->gosaMailQuota);
-        $method->setSharedFolderPermissions($this->uid, $this->imapacl);
-        $method->disconnect();
-      }
-    }
-
     /* Exchange '%member%' pseudo entry */
     $memberacl= $this->imapacl['%members%'];
 
-    if(empty($memberacl)){
-      print_a($this);
-      exit();
-    }
-
     foreach ($this->members as $user){
       if(preg_match("/kolab/i",$this->mmethod)){
         $ldap->cd($this->config->current['BASE']);
@@ -761,23 +838,47 @@ I: Only insider delivery */
       }
     }
     $this->attrs['acl'] = array();
+    
+    
     foreach($this->imapacl as $user => $acl){
-      if(preg_match("/%members%/",$user) || empty($user)) continue;
-      
+
+      /* Remove empty user entry, to avoid entry like this im imap 
+       *   "" lrs
+       */
+      if(empty($user)){
+        unset($this->imapacl[$user]);
+      }
+   
+      /* Skip invalid values */
+      if(preg_match("/%members%/",$user) || empty($user)){
+        continue;
+      }
+
+      /* Append ldap acl entries */
       $this->attrs['acl'][] = $user." ".$acl;
     }
 
+    if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
+      $method= new $this->method($this->config);
+      $method->fixAttributesOnStore($this);
+      if (($method->connect($this->gosaMailServer))){
+        $method->updateMailbox($this->uid);
+        $method->setQuota($this->uid, $this->gosaMailQuota);
+        $method->setSharedFolderPermissions($this->uid, $this->imapacl);
+        $method->disconnect();
+      }
+    }
+
     /* Save data to LDAP */
     $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs); 
-
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/mail with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
       if ($this->is_modified){
-        $this->handle_post_events("mofify");
+        $this->handle_post_events("modify");
       }
     } else {
       $this->handle_post_events("add");
@@ -789,7 +890,12 @@ I: Only insider delivery */
   {
     $ldap= $this->config->get_ldap_link();
 
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
+    if(!$this->is_account) return array();
+    
+    //$message[] = $str;      
 
     /* must: mail */
     if ($this->mail == ""){
@@ -800,13 +906,13 @@ I: Only insider delivery */
     }
     $ldap->cd($this->config->current['BASE']);
     $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
-        $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
+        $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
     if ($ldap->count() != 0){
       $message[]= _("The primary address you've entered is already in use.");
     }
-
+  
     /* Check quota */
-    if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
+    if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
       if (!is_numeric($this->gosaMailQuota)) {
         $message[]= _("Value in 'Quota size' is not valid.");
       } else {
@@ -815,7 +921,7 @@ I: Only insider delivery */
     }
 
     /* Check rejectsize for integer */
-    if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
+    if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){
       if (!is_numeric($this->gosaMailMaxSize)){
         $message[]= _("Please specify a vaild mail size for mails to be rejected.");
       } else {
@@ -938,6 +1044,63 @@ I: Only insider delivery */
     return ($name);
   }
 
+  function getCopyDialog()
+  {
+    if(!$this->is_account) return("");
+
+    $smarty = get_smarty();
+    $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
+    $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
+    $smarty->assign("mail",$this->mail);
+    $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
+    $ret = array();
+    $ret['string'] = $display;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+  function saveCopyDialog()
+  {
+    if(!$this->is_account) return;
+
+    /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses 
+    */
+    $this->execute();
+    if(isset($_POST['mail'])){
+      $this->mail = $_POST['mail'];
+    }
+  }
+
+
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+    /* Reset alternate mail addresses */
+    $this->gosaMailAlternateAddress = array();
+  }
+
+
+  /* Return plugin informations for acl handling  */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Mail"),
+          "plDescription" => _("Group mail"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("groups"), 
+          "plProvidedAcls"=> array(
+            "mail"                      => _("Mail address"),
+            "gosaMailAlternateAddress"  => _("Alternate addresses"),
+            "gosaMailForwardingAddress" => _("Forwarding addresses"),
+            "gosaMailQuota"             => _("Quota size"),
+            "gosaMailServer"            => _("Mail server"),
+            "acl"                       => _("Permissions"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: