Code

Updated table summary
[gosa.git] / gosa-plugins / mail / personal / mail / class_mail-methods-cyrus.inc
index 94c7ccc18c43f35441aed0760275dc04102a306a..367917671e66b495d6afa983988031b47bab66b4 100644 (file)
@@ -36,7 +36,7 @@ class mailMethodCyrus extends mailMethod{
     mailMethod::connect();
 
     if(!count($this->ServerList)){
-      $this->error = _("There are no imap compatible mail servers defined!");
+      $this->error = _("There are no IMAP compatible mail servers defined!");
       @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,
           "<b>IMAP: No mail servers configured, check systems->server->service->imap.</b>","");
       return(FALSE);
@@ -57,7 +57,11 @@ class mailMethodCyrus extends mailMethod{
     /* Setting connect timeout to 10 seconds,
         else the GOsa UI may freeze for 60 seconds.
        (PHP default is 'default_socket_timeout = 60') */
-    imap_timeout(1, 10 );
+    $timeout = $this->config->get_cfg_value("imapTimeout",10);
+    @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__,$timeout,
+          "<b>IMAP: Setting imap connect timeout to</b> (seconds)");
+    imap_timeout(1, $timeout);
+
     $this->imap_handle = @imap_open($cfg['connect'], $cfg['admin'], $cfg['password'], OP_HALFOPEN);
 
     /* Mailbox reachable? */
@@ -243,10 +247,28 @@ class mailMethodCyrus extends mailMethod{
       if ($list === FALSE){
         @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id."</b>" , 
           "<b>IMAP: Add/Update account</b> on server :".$this->MailServer);
-        if (!imap_createmailbox($this->imap_handle, $cfg["connect"]. $this->account_id)){
+        if (!imap_createmailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
           $this->error = imap_last_error();
           return(FALSE);
         }
+
+        /* Autocreate configured default folders */ 
+        $folders= $this->config->get_cfg_value("cyrusAutocreateFolders", null);
+        if ($folders) {
+          $foldersToCreate= explode(",", $folders);
+          $cyrus_delim= $this->cyrusUseSlashes?"/":".";
+
+          // Walk thru list of specified folders
+          foreach ($foldersToCreate as $folder) {
+            @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id."</b>" , 
+              "<b>IMAP: Add/Update account folder ".$folder."</b> on server :".$this->MailServer);
+            if(!imap_createmailbox($this->imap_handle, $cfg["connect"].$this->account_id.$cyrus_delim.$folder)) {
+              $this->error= imap_last_error();
+              return(FALSE);
+            }
+          }
+
+        }
       }
     }
     return(TRUE);
@@ -266,9 +288,16 @@ class mailMethodCyrus extends mailMethod{
 
     $cfg= $this->ServerList[$this->MailServer];
     @imap_setacl ($this->imap_handle, $this->account_id, $cfg["admin"], "lrswipcda");
-    if (!imap_deletemailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
-      $this->error = imap_last_error();
-      return (FALSE);
+
+    if ($this->config->get_cfg_value("cyrusDeleteMailbox", "true") == "true"){
+      if (!imap_deletemailbox($this->imap_handle, $cfg["connect"].$this->account_id)){
+        $this->error = imap_last_error();
+        return (FALSE);
+      }
+    } else{ 
+      msg_dialog::display(_("Mail info"),
+        sprintf(_("LDAP entry has been removed but cyrus mailbox (%s) is kept.\nPlease delete it manually!"),
+        $this->account_id), INFO_DIALOG);
     }
     return (TRUE);
   }
@@ -292,10 +321,10 @@ class mailMethodCyrus extends mailMethod{
        And prepare replacements 
      */ 
     if(preg_match("/\@/",$this->account_id)){
-      $search = preg_replace("/\@/","*@",$this->account_id);
+      $search = preg_replace("/\@/","/*@",$this->account_id);
       $with_domain = TRUE;
     }else{
-      $search = $this->account_id."*";
+      $search = $this->account_id."/*";
       $with_domain = FALSE;
     }
     $folder = $this->account_id;
@@ -304,10 +333,17 @@ class mailMethodCyrus extends mailMethod{
     }
 
     /* Contact imap server */
-    $list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $search);
+    $list = @imap_listmailbox($this->imap_handle, $cfg["connect"], $this->account_id);
+    $list2 = @imap_listmailbox($this->imap_handle, $cfg["connect"], $search);
 
     /* Create list of returned folder names */
     if (is_array($list)){
+
+      /* Merge in subfolders */
+      if(is_array($list2)){
+        $list = array_merge($list,$list2);
+      }
+
       foreach ($list as $val){
         $str = trim(preg_replace("/^\{[^\}]*+\}/","",$val));
         if($with_domain){
@@ -423,6 +459,21 @@ class mailMethodCyrus extends mailMethod{
   {
     mailMethod::saveSieveSettings();
 
+    // Check file integrity 
+    $files = array();
+    foreach(array("sieve-header.txt","sieve-spam.txt","sieve-mailsize.txt","sieve-vacation.txt","sieve-discard.txt") as $file){
+      if(!file_exists(CONFIG_DIR."/".$file) || ! is_readable(CONFIG_DIR."/".$file)){
+        $files[] = CONFIG_DIR."/".$file;
+        @DEBUG (DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__ , CONFIG_DIR."/".$file,
+            "<b>Sieve template missing, please locate and move the template file: </b>");
+      }
+    }
+    if(count($files)){
+      $msg = sprintf(_("File '%s' does not exist!"),implode($files,", "));
+      $msg .= "&nbsp;"._("The sieve script may not be written correctly.");
+      msg_dialog::display(_("Warning"),$msg,WARNING_DIALOG);
+    }
+
     /* Map attribute from parent class 
      */
     $mail = $this->parent->mail;
@@ -492,11 +543,12 @@ class mailMethodCyrus extends mailMethod{
       Build up new sieve script here.
      *****/
 
+
     /* Only create a new one, if it is not empty */
     $script= "";
     if (is_integer(strpos($gosaMailDeliveryMode, "R")) ||
         is_integer(strpos($gosaMailDeliveryMode, "C")) ||
-        !is_integer(strpos($gosaMailDeliveryMode, "L")) ||
+        !is_integer(strpos($gosaMailDeliveryMode, "I")) ||
         is_integer(strpos($gosaMailDeliveryMode, "V")) ||
         is_integer(strpos($gosaMailDeliveryMode, "S"))){
 
@@ -535,7 +587,7 @@ class mailMethodCyrus extends mailMethod{
     }
 
     /* If no local delivery is wanted, tell the script to discard the mail */
-    if (!is_integer(strpos($gosaMailDeliveryMode, "L"))){
+    if (!is_integer(strpos($gosaMailDeliveryMode, "I"))){
       $text= preg_replace('/"/', '\\"', implode ("", file(CONFIG_DIR."/sieve-discard.txt")));
       eval ("\$script.=\"$text\";");
     }