Code

Updated plugin
[gosa.git] / include / class_mail-methods-cyrus.inc
index d8b7a184e8be5bf581677494f25188721ed63073..18e55fa6d2810d93dba2bdddaa582aa711c49b60 100644 (file)
@@ -23,6 +23,7 @@ class mailMethodCyrus extends mailMethod
   var $mbox= "-";
   var $config;
   var $gosaMailServer= "";
+var $uattrib= "uid";
 
   function mailMethodCyrus($config)
   {
@@ -31,15 +32,20 @@ class mailMethodCyrus extends mailMethod
 
   function connect($gosaMailServer)
   {
+    $cfg=array();
+
     /* Connect to IMAP server. I don't want to see these warning here... */
     $this->gosaMailServer= $gosaMailServer;
     if (!isset($this->config[$gosaMailServer])){
-      print_red(_("Warning: Account has an invalid mailserver string! Please check the mail server settings in the mail tab."));
+      print_red(_("Warning: Account has an invalid mailserver string!"));
     } else {
       $cfg= $this->config[$gosaMailServer];
     }
-
     /* For some reason, hiding errors with @ does not wor here... */
+    if(!isset($cfg['connect']))   $cfg['connect']="";
+    if(!isset($cfg['admin']))     $cfg['admin']="";
+    if(!isset($cfg['password']))  $cfg['password']="";
+
     $this->mbox = @imap_open($cfg['connect'], $cfg['admin'], $cfg['password'], OP_HALFOPEN);
 
     /* Mailbox reachable? */
@@ -65,41 +71,76 @@ class mailMethodCyrus extends mailMethod
     if(is_array($quota_value)) {
       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
         /* use for PHP >= 4.3 */
-        $result['quotaUsage']=    $quota_value["STORAGE"]['usage'];
-        $result['gosaMailQuota']= $quota_value["STORAGE"]['limit'];
+        if($quota_value["STORAGE"]['limit'] == 2147483647){
+          $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
+          $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] );
+        }else{
+          $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
+          $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
+        }
       } else {
-        /* backward compatible */
-        $result['quotaUsage']=    $quota_value['usage'];
-        $result['gosaMailQuota']= $quota_value['limit'];
+        /* backward icompatible */
+        if($quota_value['usage'] == 2147483647){
+          $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
+          $result['gosaMailQuota']= (int) ($quota_value['limit'] );
+        }else{
+          $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
+          $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
+        }
       }
+    }elseif(!$quota_value){
+      /* If there is no quota defined for this account, the function imap_get_quota returns false. */
+      return(array("quotaUsage"=>"","gosaMailQuota"=>""));
     }
     error_reporting (E_ALL);
-
     return ($result);
   }
 
+
+  /* return all folders of the users mailbox*/
   function getMailboxList($folder, $uid= "")
   {
-    /* Initialize depending on group or user mode */
-    if ($uid != ""){
-      $result= array("INBOX");
-    } else {
-      $result= array();
+    global $config;
+    $result = array();
+
+    /* Get domain an mail address if uid is an mail address */
+    $domain = "";
+    if(preg_match("/@/",$folder)){
+      $domain = "@".preg_replace("/^.*@/","",$folder);
+      $folder = preg_replace("/@.*$/","",$folder);
     }
 
     /* Get list of mailboxes for combo box */
     $cfg= $this->config[$this->gosaMailServer];
-    $list = imap_listmailbox($this->mbox, $cfg["connect"], $folder.".*");
+
+    /* Create search pattern
+         (user/kekse*@domain.de
+          user.kekse*@domain.de
+          user.kekse*  )
+       depending on given folder name) */
+    $q = $folder."*".$domain;
+    $list = imap_listmailbox($this->mbox, $cfg["connect"], $q);
+
+    /* Create list of returned folder names */
     if (is_array($list)){
       foreach ($list as $val){
-        $result[]=preg_replace ("/.*user\.".$uid."\./",
-            "INBOX.", imap_utf7_decode ($val));
+
+        /* Cut domain name */
+        $val = preg_replace("/@.*$/","",$val);
+        $result[]=preg_replace ("/^.*".normalizePreg($folder)."/","INBOX", imap_utf7_decode ($val));
       }
     }
 
+    /* Append "INBOX" to the folder array if result is empty and request comes from user dialog */
+    if(empty($result) && !empty($uid)){
+      $result[] = "INBOX";
+    }
+
     return ($result);
   }
 
+
   function updateMailbox($folder)
   {
     /* Check if mailbox exists */
@@ -117,10 +158,13 @@ class mailMethodCyrus extends mailMethod
   function setQuota($folder, $gosaMailQuota)
   {
     /* Workaround for the php imap extension */
-    if ($gosaMailQuota == ""){
-      $gosaMailQuota= "0";
+    if (($gosaMailQuota == "") || ($gosaMailQuota== "2147483647")){
+      $gosaMailQuota= "2147483647";
+    }elseif($gosaMailQuota > 0){
+      $gosaMailQuota = $gosaMailQuota *1024;
     }
-
+    
+    
     /* Write mail quota */
     if (!imap_set_quota($this->mbox, $folder, $gosaMailQuota)){
       print_red(sprintf(_("Can't write IMAP quota. Server says '%s'."), imap_last_error()));
@@ -132,12 +176,6 @@ class mailMethodCyrus extends mailMethod
 
   function setSharedFolderPermissions($folder, $permissions)
   {
-    /* Show warning message in case of missing imap_getacl */
-    if (!function_exists('imap_getacl')){
-      print_red (_("Warning: imap_getacl is not implemented, wouldn't modify acl informations."));
-      return;
-    }
-
     /* Get list of subfolders */
     $folders= $this->getMailboxList($folder, "");
     $folders[]= $folder;
@@ -148,10 +186,14 @@ class mailMethodCyrus extends mailMethod
       if (function_exists('imap_getacl')){
 
         /* Remove all acl's for this folder */
-        $users= imap_getacl ($this->mbox, $subfolder);
-        foreach ($users as $userid => $perms){
-          imap_setacl ($this->mbox, $subfolder, $userid, "");
+        $users= @imap_getacl ($this->mbox, $subfolder);
+        if(is_array($users)){
+          foreach ($users as $userid => $perms){
+            imap_setacl ($this->mbox, $subfolder, $userid, "");
+          }
         }
+      } else {
+        print_red (_("Warning: imap_getacl is not implemented, can't remove acl informations."));
       }
 
       /* Set permissions for this folder */