Code

Added comment to sieve TLS
[gosa.git] / gosa-plugins / mail / personal / mail / class_mailAccount.inc
index 2f5ad1052bb9af3b2c5bae4847bf8bc41173e275..d5b87ef2e9c3b370544a1e09cc4c8c86e754d48d 100644 (file)
@@ -148,11 +148,13 @@ class mailAccount extends plugin
 
       /* If the doamin part is selectable, we have to split the mail address
        */
-      if($this->mailMethod->domainSelectionEnabled()){
-        $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
-        $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
-        if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
-          $this->mailDomainParts[] = $this->mailDomainPart;
+      if(!(!$this->mailMethod->isModifyableMail() && $this->is_account)){
+        if($this->mailMethod->domainSelectionEnabled()){
+          $this->mailDomainPart = preg_replace("/^[^@]*+@/","",$this->mail);
+          $this->mail = preg_replace("/@.*$/","\\1",$this->mail);
+          if(!in_array($this->mailDomainPart,$this->mailDomainParts)){
+            $this->mailDomainParts[] = $this->mailDomainPart;
+          }
         }
       }
 
@@ -192,6 +194,7 @@ class mailAccount extends plugin
 
   function execute()
   {
+
     /* Call parent execute */
     $display = plugin::execute();
 
@@ -493,13 +496,19 @@ class mailAccount extends plugin
     if (isset($_POST['mailTab'])){
 
       /* Save ldap attributes */
+      $mail = $this->mail;
       plugin::save_object();
 
-      /* Get posted mail domain part, if necessary  
-       */
-      if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
-        if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
-          $this->mailDomainPart = get_post('MailDomain');
+      if(!$this->mailMethod->isModifyableMail() && $this->initially_was_account){
+        $this->mail = $mail;
+      }else{
+
+        /* Get posted mail domain part, if necessary  
+         */
+        if($this->mailMethod->domainSelectionEnabled() && isset($_POST['MailDomain'])){
+          if(in_array(get_post('MailDomain'), $this->mailDomainParts)){
+            $this->mailDomainPart = get_post('MailDomain');
+          }
         }
       }
 
@@ -833,6 +842,25 @@ class mailAccount extends plugin
       $this->mail = $this->mail."@".$this->mailDomainPart;
     }
 
+    /* Update sharedFolder dependencies. 
+       Open each shared folder and remove this account. 
+       Then Save the group to ensure that all necessary 
+        actions will be taken (imap acls updated aso.).
+     */
+    $ldap = $this->config->get_ldap_link();    
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
+    while($attrs = $ldap->fetch()){
+      $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
+      if(isset($grp->by_object['mailgroup']) && isset($grp->by_object['group'])){
+        $grp->by_object['group']->removeUser($this->uid);
+
+        /* Do not save the complete group! This will quit the complete membership 
+         */
+        $grp->by_object['mailgroup']->save();
+      } 
+    }
+
     /* Remove GOsa attributes */
     plugin::remove_from_parent();
 
@@ -868,10 +896,6 @@ class mailAccount extends plugin
           msg_dialog::display(_("Mail error"), sprintf(_("Cannot remove mailbox! Error was: %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."), 
-                $this->mailMethod->get_error()), ERROR_DIALOG);
-        }
       }
     }
     $this->mailMethod->disconnect();
@@ -888,13 +912,17 @@ class mailAccount extends plugin
     $ldap= $this->config->get_ldap_link();
 
     /* If domain part was selectable, contruct mail address */
-    if($this->mailMethod->domainSelectionEnabled()){
-      $this->mail = $this->mail."@".$this->mailDomainPart;
+    if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
+
+      if($this->mailMethod->domainSelectionEnabled()){
+        $this->mail = $this->mail."@".$this->mailDomainPart;
+      }
+
+      /* Enforce lowercase mail address and trim whitespaces
+       */
+      $this->mail = trim(strtolower($this->mail));
     }
-    
-    /* Enforce lowercase mail address and trim whitespaces
-     */
-    $this->mail = trim(strtolower($this->mail));
+
 
     /* Call parents save to prepare $this->attrs */
     plugin::save();
@@ -947,7 +975,6 @@ class mailAccount extends plugin
 
         if (!is_integer(strpos($this->gosaMailDeliveryMode, "C"))){
 
-
           /* Do not write sieve settings if this account is new and 
              doesn't seem to exist.
            */
@@ -960,20 +987,32 @@ class mailAccount extends plugin
             }
           }
         }else{
-      
          echo "Check sieve management here";
-
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, 
               "User uses an own sieve script, skipping sieve update.".$str."</b>","");
         }
+      }
+    }
+    $this->mailMethod->disconnect();
 
-        if(!$this->mailMethod->updateSharedFolder()){
-          msg_dialog::display(_("Mail error"), sprintf(_("Cannot update shared folder permissions! Error was: %s."), 
-                $this->mailMethod->get_error()), ERROR_DIALOG);
+    /* Update sharedFolder dependencies.
+       Open each shared folder and remove this account.
+       Then Save the group to ensure that all necessary
+       actions will be taken (imap acls updated aso.).
+     */
+    if(!$this->initially_was_account){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $ldap->search("(&(objectClass=posixGroup)(objectClass=gosaMailAccount)(memberUid=".$this->uid."))",array("dn"));
+      while($attrs = $ldap->fetch()){
+        $grp = new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $attrs['dn']);
+        if(isset($grp->by_object['mailgroup'])){
+          /* Do not save the complete group! This will quit the complete membership
+           */
+          $grp->by_object['mailgroup']->save();
         }
       }
     }
-    $this->mailMethod->disconnect();
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -1005,31 +1044,34 @@ class mailAccount extends plugin
 
     /* Mail address checks */
     $mail = $this->mail;
-    if($this->mailMethod->domainSelectionEnabled()){
-      $mail.= "@".$this->mailDomainPart;
-    }
+    if(!(!$this->mailMethod->isModifyableMail() && $this->initially_was_account)){
 
-    if (empty($mail)){
-      $message[]= msgPool::required(_("Primary address"));
-    }
-    if ($this->is_template){
-      if (!tests::is_email($mail, TRUE)){
-        $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
+      if($this->mailMethod->domainSelectionEnabled()){
+        $mail.= "@".$this->mailDomainPart;
       }
-    } else {
-      if (!tests::is_email($mail)){
-        $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
+
+      if (empty($mail)){
+        $message[]= msgPool::required(_("Primary address"));
+      }
+      if ($this->is_template){
+        if (!tests::is_email($mail, TRUE)){
+          $message[]= msgPool::invalid(_("Mail address"),"","","%givenName.%sn@your-domain.com");
+        }
+      } else {
+        if (!tests::is_email($mail)){
+          $message[]= msgPool::invalid(_("Mail address"),"","","your-address@your-domain.com");
+        }
       }
-    }
 
-    /* Check if this mail address is already in use */
-    $ldap->cd($this->config->current['BASE']);
-    $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
-      "(objectClass=gosaMailAccount)".
-      "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
-    $ldap->search($filter,array("uid"));
-    if ($ldap->count() != 0){
-      $message[]= msgPool::duplicated(_("Mail address"));
+      /* Check if this mail address is already in use */
+      $ldap->cd($this->config->current['BASE']);
+      $filter = "(&(!(objectClass=gosaUserTemplate))(!(uid=".$this->uid."))".
+        "(objectClass=gosaMailAccount)".
+        "(|(mail=".$mail.")(alias=".$mail.")(gosaMailAlternateAddress=".$mail.")))";
+      $ldap->search($filter,array("uid"));
+      if ($ldap->count() != 0){
+        $message[]= msgPool::duplicated(_("Mail address"));
+      }
     }
 
 
@@ -1319,6 +1361,17 @@ class mailAccount extends plugin
   }
 
 
+  function allow_remove()
+  {
+    $resason = "";
+    if(!$this->mailMethod->allow_remove($reason)){
+      return($reason);
+    }
+    return("");
+  }
+
+
+
   /*! \brief  ACL settings 
    */
   static function plInfo()