Code

Updated phoneAccount.
[gosa.git] / include / class_mail-methods-kolab.inc
index 1f785a06390ff907968de9c6779e474b06f7a5a3..61d15c47fdf5b50c6936521383fb3dd670802dd0 100644 (file)
@@ -32,6 +32,18 @@ class mailMethodKolab extends mailMethodCyrus
 
   function mailMethodKolab($config)
   {
+    /* Check if the mail account identification attribute
+       is overridden in the configuration file
+     */
+    if(isset($config->current['MAIL_ATTRIB']) && !empty($config->current['MAIL_ATTRIB'])){
+      $new_uattrib= strtolower($config->current['MAIL_ATTRIB']);
+      if(in_array($new_uattrib,array("mail","uid"))){
+        $this->uattrib = $new_uattrib;
+      }else{
+        trigger_error(sprintf("Unsupported MAIL_ATTRIB in gosa configuration specified, use 'mail' or 'uid', instead of '%s'.",            $new_uattrib));
+      }
+    }
+
     $this->config= $config->data['SERVERS']['IMAP'];
   }
 
@@ -44,49 +56,50 @@ class mailMethodKolab extends mailMethodCyrus
     return (TRUE);
   }
 
+  /* Get quota and divide it by 1024, because in gosa we display in MB
+      but we get Kb */
   function getQuota($folder)
   {
     $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
 
-    /* Load quota settings */
-    $folder = $folder;
-
-    /* try to read quota with style of users
-       user/name@server.de
-     */
-    $quota_value = @imap_get_quota($this->mbox, str_replace("user.","user/",$folder));
-
-    /* If obove method failed, try to read quota with style of users
-       user.name@server.de
-     */
-    if(!is_array($quota_value)){
-      $quota_value = @imap_get_quota($this->mbox, $folder);
+    /* Only use lower case folder names, if folder name is like "@domain.com" */
+    if(preg_match("/@/",$folder)){
+      $folder = strtolower($folder);
     }
 
+    error_reporting(0);  
+  
+    /* Load quota settings */
+    $quota_value = @imap_get_quota($this->mbox, $folder);
     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'] / 1024);
-        $result['gosaMailQuota']= ($quota_value["STORAGE"]['limit'] / 1024);
+        $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
+        $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
       } else {
         /* backward icompatible */
-        $result['quotaUsage']=    ($quota_value['usage'] / 1024);
-        $result['gosaMailQuota']= ($quota_value['limit'] / 1024);
+        $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
+        $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
       }
+    }elseif(!$quota_value){
+      return(false);
     }
-    return ($result);
-  }
-
 
-
-  function deleteMailbox($folder)
-  {
-    return (TRUE);
+    error_reporting(E_ALL); 
+    return ($result);
   }
 
 
   function fixAttributesOnLoad(&$mailObject)
   {
+    /* Kolab shared folder names are like ' shared.uid@server.de ' 
+        So overwrite uid to match these folder names. Else we can't read quota settings etc. 
+        #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
+    if(get_class($mailObject) == "mailgroup"){
+     $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
+    }
+
     /* Convert attributes and objectClasses */
     foreach ($this->attribute_map as $dest => $source){
       /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
@@ -100,6 +113,12 @@ class mailMethodKolab extends mailMethodCyrus
         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
         $mailObject->$dest=        $mailObject->attrs[$source];
 
+        /* Ensure that cleanup will recognize the ampped attributes too */
+        if(isset($mailObject->saved_attributes)){
+          $mailObject->saved_attributes[$dest] = $mailObject->attrs[$source];
+          $mailObject->saved_attributes[$source] = $mailObject->attrs[$source];
+        }
+
         unset ($mailObject->$dest['count']);
         unset ($mailObject->attrs[$source]);
       }
@@ -118,6 +137,12 @@ class mailMethodKolab extends mailMethodCyrus
   function fixAttributesOnStore(&$mailObject)
   {
     global $config;
+  
+    /* If quota is empty, remove quota restrictions by setting quota to 0 */
+    if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
+      $mailObject->attrs['gosaMailQuota'] = 0;
+    }
+
     /* Convert attributes and objectClasses */
     foreach ($this->attribute_map as $source => $dest){
       if (isset($mailObject->attrs[$source])){
@@ -195,6 +220,14 @@ class mailMethodKolab extends mailMethodCyrus
           }
         }
       }
+      /* Save shared folder target */
+      $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->mail;
+
+      /* Kolab shared folder names are like ' shared.uid@server.de ' 
+        So overwrite uid to match these folder names. Else we can't read quota settings etc. 
+        #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
+      $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
   
       /* Assign new acls */
       $mailObject->attrs['acl']= array();
@@ -218,9 +251,29 @@ class mailMethodKolab extends mailMethodCyrus
     foreach($this->attribute_map as $kolabAttr){
       $mailObject->attrs[$kolabAttr] = array();
     }  
-    //$mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
+
+    /* Only add kolab delete Flag in case of an user.mailAccount */
+    if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
+      $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
+    }else{
+      /* Kolab shared folder names are like ' shared.uid@server.de ' 
+        So overwrite uid to match these folder names. Else we can't read quota settings etc. 
+        #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
+      $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
+      
+    }
   }
 
+
+  function deleteMailbox($folder)
+  {
+    /* Remove shared folders and skip removing users. 
+       KolabD is not able to remove shared folders yet, so we do it instead */
+    if(preg_match("/^shared/",$folder)){
+      return mailMethodCyrus::deleteMailbox($folder);
+    }
+    return (TRUE);
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: