Code

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