Code

Updated resizing for divlists
[gosa.git] / include / class_mail-methods-kolab.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require_once("class_mail-methods-cyrus.inc");
22 class mailMethodKolab extends mailMethodCyrus
23 {
24   var $mbox= "-";
25   var $config;
26   var $gosaMailServer= "";
27   var $uattrib= "mail";
29   var $attribute_map= array("gosaMailAlternateAddress"  =>  "alias",
30                             "gosaMailQuota"             =>  "cyrus-userquota",
31                             "gosaMailServer"            =>  "kolabHomeServer");
33   function mailMethodKolab($config)
34   {
35     $this->config= $config->data['SERVERS']['IMAP'];
36   }
38   function updateMailbox($folder)
39   {
40   }
42   function setQuota($folder, $gosaMailQuota)
43   {
44     return (TRUE);
45   }
47   function deleteMailbox($folder)
48   {
49     return (TRUE);
50   }
53   /* Get quota and divide it by 1024, because in gosa we display in MB
54       but we get Kb */
55   function getQuota($folder)
56   {
57     $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
59     error_reporting(0);  
60   
61     /* Load quota settings */
62     $quota_value = @imap_get_quota($this->mbox, $folder);
63     if(is_array($quota_value)) {
64       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
65         /* use for PHP >= 4.3 */
66         $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
67         $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
68       } else {
69         /* backward icompatible */
70         $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
71         $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
72       }
73     }elseif(!$quota_value){
74       return(false);
75     }
77     error_reporting(E_ALL); 
78  
79     return ($result);
80   }
83   function fixAttributesOnLoad(&$mailObject)
84   {
85     /* Kolab shared folder names are like ' shared.uid@server.de ' 
86         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
87         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
88     $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
90     /* Convert attributes and objectClasses */
91     foreach ($this->attribute_map as $dest => $source){
92       /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
93       if (isset($mailObject->attrs[$source])){
94         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
95         unset ($mailObject->attrs[$source]);
96       */
98       if (isset($mailObject->attrs[$source])){
99         unset($mailObject->attrs[$source]['count']);
100         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
101         $mailObject->$dest=        $mailObject->attrs[$source];
103         unset ($mailObject->$dest['count']);
104         unset ($mailObject->attrs[$source]);
105       }
106     }
108     /* Adjust server name if needed */
109     foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
110       if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
111         $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
112         break;
113       }
114     }
115   }
118   function fixAttributesOnStore(&$mailObject)
119   {
120     global $config;
121   
122     /* If quota is empty, remove quota restrictions by setting quota to 0 */
123     if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
124       $mailObject->attrs['gosaMailQuota'] = 0;
125     }
127     /* Convert attributes and objectClasses */
128     foreach ($this->attribute_map as $source => $dest){
129       if (isset($mailObject->attrs[$source])){
130         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
131         unset ($mailObject->attrs[$source]);
132       }
133     }
134     $objectclasses= array();
135     foreach ($mailObject->attrs['objectClass'] as $oc){
136       if ($oc !=  'kolabInetOrgPerson' && $oc !=  'kolabSharedFolder'){
137         $objectclasses[]= $oc;
138       }
139     }
140     $mailObject->attrs['objectClass']= $objectclasses;
141     if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
142   
143       /* Add kolabSharedFoleder Class */
144       $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
146       /* Work on acl attribute */
147       $new_acl= array();
148       foreach ($mailObject->attrs['acl'] as $uacl){
150         /* Get user=(mail) & acls  */
151         list($user, $acl) = split(" ", $uacl);
152       
153         /* Add al users which have seperated acls 
154            %members% are all users in this group, 
155            which have the standard group acl
156         */
157         if ($user != "%members%"){
158           $new_acl[$user]= $uacl;
159         } else {
160         
161           /* All groupmembers will be added */
162           $ldap = $config->get_ldap_link();
163           $ldap->cd($config->current['BASE']);
164           foreach ($mailObject->members as $member){
166             /* Get user mail address .... */
167             $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
168             $res = $ldap->fetch();
170             /* Default mail address is set to uid - 
171                So if there is no mail address defined the uid is added 
172              */
173             $mail = $member;
175             /* Use mail address if it is available */
176             if(isset($res['mail'][0])){
177               $mail = $res['mail'][0];
178             }
180             /* only append this mail/permission string to acl,
181                if there arn't already some (special) configs for this user */
182             $found =false;
183             foreach($mailObject->imapacl as $mailA => $acl){
184               if(strtolower(trim($mailA))==strtolower(trim($mail))){
185                 $found = true;
186               }
187             }
189             /* Skipp user, with no email adress too */     
190             if($member == $mail){
191               $found = true;
192             }
193    
194             /* Append new user acl */
195             if(!$found){
196               $new_acl[$member]= "$mail $acl";
197             }
199             /* Old line */
200             //  $new_acl[$member]= "$member $acl";
201           }
202         }
203       }
204  
205       /* Save shared folder target */
206       $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->uid;
208       /* Kolab shared folder names are like ' shared.uid@server.de ' 
209         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
210         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
211       $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
212   
213       /* Assign new acls */
214       $mailObject->attrs['acl']= array();
215       foreach ($new_acl as $key => $value){
216         $mailObject->attrs['acl'][]= $value;
217       }
218     } else {
219       $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
220     }
222     /* Remove imap:// tagging */
223     $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
224     $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
225     $mailObject->attrs['kolabDeleteFlag']= array();
226   }
228   function fixAttributesOnRemove(&$mailObject)
229   {
230     /* Add attribute for object deletion and remove GOsa specific
231        values from entry. */
232     foreach($this->attribute_map as $kolabAttr){
233       $mailObject->attrs[$kolabAttr] = array();
234     }  
235     $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
236   }
240 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
241 ?>