Code

Added first test for get_module_permissions
[gosa.git] / include / class_mail-methods-golab.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 mailMethodGolab 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 mailMethodGolab($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   /* Get quota and divide it by 1024, because in gosa we display in MB
48       but we get Kb */
49   function getQuota($folder)
50   {
51     $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
53     /* Only use lower case folder names, if folder name is like "@domain.com" */
54     if(preg_match("/@/",$folder)){
55       $folder = strtolower($folder);
56     }
58     error_reporting(0);  
59   
60     /* Load quota settings */
61     $quota_value = @imap_get_quota($this->mbox, $folder);
62     if(is_array($quota_value)) {
63       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
64         /* use for PHP >= 4.3 */
65         $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
66         $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
67       } else {
68         /* backward icompatible */
69         $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
70         $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
71       }
72     }elseif(!$quota_value){
73       return(false);
74     }
76     error_reporting(E_ALL); 
77  
78     return ($result);
79   }
82   function fixAttributesOnLoad(&$mailObject)
83   {
84     /* Kolab shared folder names are like ' shared.uid@server.de ' 
85         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
86         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
87     if(get_class($mailObject) == "mailgroup"){
88      $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
89     }
91     /* Convert attributes and objectClasses */
92     foreach ($this->attribute_map as $dest => $source){
93       /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
94       if (isset($mailObject->attrs[$source])){
95         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
96         unset ($mailObject->attrs[$source]);
97       */
99       if (isset($mailObject->attrs[$source])){
100         unset($mailObject->attrs[$source]['count']);
101         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
102         $mailObject->$dest=        $mailObject->attrs[$source];
104         unset ($mailObject->$dest['count']);
105         unset ($mailObject->attrs[$source]);
106       }
107     }
109     /* Adjust server name if needed */
110     foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
111       if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
112         $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
113         break;
114       }
115     }
116   }
119   function fixAttributesOnStore(&$mailObject)
120   {
121     global $config;
122   
123     /* If quota is empty, remove quota restrictions by setting quota to 0 */
124     if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
125       $mailObject->attrs['gosaMailQuota'] = 0;
126     }
128     /* Convert attributes and objectClasses */
129     foreach ($this->attribute_map as $source => $dest){
130       if (isset($mailObject->attrs[$source])){
131         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
132         unset ($mailObject->attrs[$source]);
133       }
134     }
135     $objectclasses= array();
136     foreach ($mailObject->attrs['objectClass'] as $oc){
137       if ($oc !=  'kolabInetOrgPerson' && $oc !=  'kolabSharedFolder'){
138         $objectclasses[]= $oc;
139       }
140     }
141     $mailObject->attrs['objectClass']= $objectclasses;
142     if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
143   
144       /* Add kolabSharedFoleder Class */
145       $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
147       /* Work on acl attribute */
148       $new_acl= array();
149       foreach ($mailObject->attrs['acl'] as $uacl){
151         /* Get user=(mail) & acls  */
152         list($user, $acl) = split(" ", $uacl);
153       
154         /* Add al users which have seperated acls 
155            %members% are all users in this group, 
156            which have the standard group acl
157         */
158         if ($user != "%members%"){
159           $new_acl[$user]= $uacl;
160         } else {
161         
162           /* All groupmembers will be added */
163           $ldap = $config->get_ldap_link();
164           $ldap->cd($config->current['BASE']);
165           foreach ($mailObject->members as $member){
167             /* Get user mail address .... */
168             $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
169             $res = $ldap->fetch();
171             /* Default mail address is set to uid - 
172                So if there is no mail address defined the uid is added 
173              */
174             $mail = $member;
176             /* Use mail address if it is available */
177             if(isset($res['mail'][0])){
178               $mail = $res['mail'][0];
179             }
181             /* only append this mail/permission string to acl,
182                if there arn't already some (special) configs for this user */
183             $found =false;
184             foreach($mailObject->imapacl as $mailA => $acl){
185               if(strtolower(trim($mailA))==strtolower(trim($mail))){
186                 $found = true;
187               }
188             }
190             /* Skipp user, with no email adress too */     
191             if($member == $mail){
192               $found = true;
193             }
194    
195             /* Append new user acl */
196             if(!$found){
197               $new_acl[$member]= "$mail $acl";
198             }
200             /* Old line */
201             //  $new_acl[$member]= "$member $acl";
202           }
203         }
204       }
205  
206       /* Save shared folder target */
207       $mailObject->attrs['gosaSharedFolderTarget']= "kolab+".$mailObject->mail;
209       /* Kolab shared folder names are like ' shared.uid@server.de ' 
210         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
211         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
212       $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
213   
214       /* Assign new acls */
215       $mailObject->attrs['acl']= array();
216       foreach ($new_acl as $key => $value){
217         $mailObject->attrs['acl'][]= $value;
218       }
219     } else {
220       $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
221     }
223     /* Remove imap:// tagging */
224     $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
225     $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
226     $mailObject->attrs['kolabDeleteFlag']= array();
227   }
229   function fixAttributesOnRemove(&$mailObject)
230   {
231     /* Add attribute for object deletion and remove GOsa specific
232        values from entry. */
233     foreach($this->attribute_map as $kolabAttr){
234       $mailObject->attrs[$kolabAttr] = array();
235     }  
237     /* Only add kolab delete Flag in case of an user.mailAccount */
238     if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
239       $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
240     }else{
241       /* Kolab shared folder names are like ' shared.uid@server.de ' 
242         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
243         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
244       $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
245       
246     }
247   }
250   function deleteMailbox($folder)
251   {
252     /* Remove shared folders and skip removing users. 
253        KolabD is not able to remove shared folders yet, so we do it instead */
254     if(!(preg_match("/^user\//",$folder))){
255       return mailMethodCyrus::deleteMailbox($folder);
256     }
257     return (TRUE);
258   }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>