Code

Updated Quota progress bar.
[gosa.git] / gosa-plugins / mail / personal / mail / class_mail-methods-cyrus.inc
index 147a5d1f49cf1aba372d6de11ee6106f470d8b8b..152daee4d5ec2d1d74fb3b119f82c1b704143116 100644 (file)
@@ -8,7 +8,10 @@ class mailMethodCyrus extends mailMethod{
   protected $quota_loaded = FALSE;
    
   /* Allow modification of account_ids for existing mail accounts */
-  protected $modifyableMail = FALSE;
+  protected $modifyableMail   = FALSE;
+
+  /* Allow modification of the mail server attribute existing mail accounts */
+  protected $modifyableServer = FALSE;
 
   /* Enforces same value for 'mail' as used for 'cn' */
   protected $mailEqualsCN   = FALSE; 
@@ -33,7 +36,7 @@ class mailMethodCyrus extends mailMethod{
     if (!isset($this->ServerList[$this->MailServer])){
       $this->error = _("Mail server for this account is invalid!");
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
-          "<b>The selected mail server '".$this->MailServer."' is invalid.</b>",""); 
+          "<b>IMAP: The selected mail server '".$this->MailServer."' is invalid.</b>",""); 
       return(FALSE);
     } else {
       $cfg= $this->ServerList[$this->MailServer];
@@ -53,9 +56,15 @@ class mailMethodCyrus extends mailMethod{
     /* Mailbox reachable? */
     if ($this->imap_handle === FALSE){
       $this->error = imap_last_error();
+
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>Failed</b> :".imap_last_error(),
+        "<b>IMAP:</b> ".$cfg['admin']."@".$cfg['connect']);
+
       return (FALSE);
       $this->connected = FALSE;
     }
+    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>successful</b>",
+        "<b>IMAP:</b> ".$cfg['admin']."@".$cfg['connect']);
     $this->connected = TRUE;
 
     return (TRUE);
@@ -74,9 +83,9 @@ class mailMethodCyrus extends mailMethod{
     $list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
     $res = is_array($list) && count($list);
     if($res){
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>Account exists in imap server.</b>"); 
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>IMAP: Account exists in imap server.</b>"); 
     }else{
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>Account seems NOT to exists in imap server.</b>"); 
+      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","<b>IMAP: Account seems NOT to exists in imap server.</b>"); 
     }
     return($res);
   }
@@ -104,10 +113,16 @@ class mailMethodCyrus extends mailMethod{
       return(FALSE);
     }
 
+    $this->reset_error();
+
     /* Load quota settings */
     $result = array("quotaUsage"=>"","gosaMailQuota"=>"");
     $quota_value = @imap_get_quota($this->imap_handle, $this->account_id);
 
+    /* Reset error queue, imap_qet_quota() will fail if the quota wasn't set yet.
+     */
+    imap_errors();
+
     if(is_array($quota_value) && count($quota_value)) {
       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
 
@@ -142,10 +157,10 @@ class mailMethodCyrus extends mailMethod{
         $quota = "(".$this->quotaUsage." / ".$this->quotaValue.")";
       }
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, $quota , 
-          "<b>Successfully received account quota</b>");
+          "<b>IMAP: Successfully received account quota</b>");
     }else{
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, imap_last_error() , 
-          "<b>Failed to receive account quota</b>");
+          "<b>IMAP: Failed to receive account quota</b>");
     }
   }
 
@@ -196,11 +211,11 @@ class mailMethodCyrus extends mailMethod{
       msg_dialog::display(_("IMAP error"), sprintf(_("Cannot modify IMAP mailbox quota: %s"),
             '<br><br><i>'.imap_last_error().'</i>'), ERROR_DIALOG);
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id.": (".$debug_number.")</b>" , 
-          "<b>Set account quota</b> on server '".$this->MailServer."' <b>".imap_last_error()."</b>");
+          "<b>IMAP: Set account quota</b> on server '".$this->MailServer."' <b>".imap_last_error()."</b>");
       return (FALSE);
     }
     @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id.": (".$debug_number.")</b>" , 
-        "<b>Set account quota</b> on server :".$this->MailServer);
+        "<b>IMAP: Set account quota</b> on server :".$this->MailServer);
     return (TRUE);
   }
 
@@ -220,7 +235,7 @@ class mailMethodCyrus extends mailMethod{
       $list = imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
       if ($list === FALSE){
         @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id."</b>" , 
-          "<b>Add/Update account</b> on server :".$this->MailServer);
+          "<b>IMAP: Add/Update account</b> on server :".$this->MailServer);
         if (!imap_createmailbox($this->imap_handle, $cfg["connect"]. $this->account_id)){
           $this->error = imap_last_error();
           return(FALSE);
@@ -296,11 +311,11 @@ class mailMethodCyrus extends mailMethod{
         $result[] = $str;      
       }
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,trim(implode($result,", "),", "),
-          "<b>Received mailbox folders.</b>");
+          "<b>IMAP: Received mailbox folders.</b>");
       $this->error = imap_last_error();
     }else{
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,imap_last_error(),
-          "<b>Cannot receive mailbox folders.</b>");
+          "<b>IMAP: Cannot receive mailbox folders.</b>");
       $this->error = imap_last_error();
       return(array());
     }
@@ -324,7 +339,7 @@ class mailMethodCyrus extends mailMethod{
     if (!function_exists('imap_getacl')){
       $this->error = _("The module imap_getacl is not implemented!");
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"The imap_getacl module is missing!",
-          "<b>Cannot set folder acls.</b>");
+          "<b>IMAP: Cannot set folder acls.</b>");
       return($folder_acls);
     }
 
@@ -337,6 +352,15 @@ class mailMethodCyrus extends mailMethod{
       $folder_acls[$user] = $acl;
     }
 
+    /* Merge given ACL with acl mapping
+       This ensures that no ACL will accidentally overwritten by gosa.
+     */
+    foreach($folder_acls as $user => $acl){
+      if(!isset($this->acl_mapping[$acl])){
+        $this->acl_mapping[$acl] = $acl;
+      }
+    }
+
     return($folder_acls);
   }
 
@@ -352,7 +376,7 @@ class mailMethodCyrus extends mailMethod{
     if (!function_exists('imap_getacl')){
       $this->error = _("The module imap_getacl is not implemented!");
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"The imap_getacl module is missing!",
-          "<b>Cannot set folder acls.</b>");
+          "<b>IMAP: Cannot set folder acls.</b>");
       return(FALSE);
     }
 
@@ -370,7 +394,7 @@ class mailMethodCyrus extends mailMethod{
           $userid = strtolower($userid);
           imap_setacl ($this->imap_handle, $folder_id, $userid, "");
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$folder_id." -> ".$userid,
-              "<b>Removing folder permissions.</b>");
+              "<b>IMAP: Removing folder permissions.</b>");
         }
       }
     }
@@ -382,7 +406,7 @@ class mailMethodCyrus extends mailMethod{
       foreach ($permissions as $user => $acl){
         imap_setacl ($this->imap_handle, $folder_id, $user, $acl);
         @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$folder_id." -> ".$user.": ".$acl,
-            "<b>Setting new folder permissions.</b>");
+            "<b>IMAP: Setting new folder permissions.</b>");
       }
     }
     return(TRUE);
@@ -412,9 +436,6 @@ class mailMethodCyrus extends mailMethod{
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,"<b>SIEVE: login failed.</b>");
       $this->error = $sieve->error_raw;
       return(FALSE);
-    }else{
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Options: ".$cfg["sieve_option"] ,
-          "SIEVE: <b>login successfull.</b>");
     }
 
     /* Build spamlevel. Spamassassin tags mails with "*" for each integer
@@ -433,12 +454,9 @@ class mailMethodCyrus extends mailMethod{
         if(!$sieve->sieve_getscript("gosa")){
           $this->error = sprintf(_("Cannot retrieve SIEVE script: %s"),to_string($sieve->error_raw));
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,
-              "SIEVE: <b>Connot read 'gosa' sieve script.</b>");
+              "<b>SIEVE: Connot read 'gosa' sieve script.</b>");
           $this->error = $sieve->error_raw;
           return(FALSE);
-        }else{
-          @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$sieve->error_raw ,
-              "SIEVE: <b>Sieve script named 'gosa' found.</b>");
         }
 
         $is_valid_script = FALSE;
@@ -453,12 +471,12 @@ class mailMethodCyrus extends mailMethod{
 
         if($is_valid_script || strlen($script) == 0 || empty($script)){
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"" ,
-              "SIEVE: Sieve script 'gosa' was a valid GOsa script and will be replaced.");
+              "<b>SIEVE</b>: Sieve script 'gosa' was a valid GOsa script and will be replaced.");
         }else{
           $new_name = "non_gosa_".date("Ymd_H-i-s");
           $sieve->sieve_sendscript($new_name, $script);
           @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$this->sieve->error_raw ,
-              "SIEVE: Non GOsa sieve script. <b>Creating backup of the current sieve script '".$new_name."'.</b>");
+              "<b>SIEVE</b>: Non GOsa sieve script. <b>Creating backup of the current sieve script '".$new_name."'.</b>");
         }
       }
     }
@@ -524,11 +542,8 @@ class mailMethodCyrus extends mailMethod{
     if (!$sieve->sieve_sendscript("gosa", $script)){
       $this->error = sprintf(_("Cannot store SIEVE script: %s"), to_string($sieve->error_raw));
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "Error was: ".to_string($sieve->error_raw) ,
-        "SIEVE: <b>Writing new Sieve script failed!</b>");
+        "<b>SIEVE: Writing new Sieve script failed!</b>");
       return(FALSE);
-    }else{
-      @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"<b>Successfully written!</b>" ,
-        "SIEVE: <b>NEW sieve script 'gosa' contains '".strlen($script)."' characters.</b>");
     }
 
     if(!$sieve->sieve_setactivescript("gosa")){
@@ -536,7 +551,6 @@ class mailMethodCyrus extends mailMethod{
       return(FALSE);
     }
 
-    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,"","SIEVE: <b>Logout</b>");
     $sieve->sieve_logout();
   }
 }