Code

Updated mail methods.
[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     /* 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 = "shared.".$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         /* Ensure that cleanup will recognize the ampped attributes too */
112         if(isset($mailObject->saved_attributes)){
113           $mailObject->saved_attributes[$dest] = $mailObject->attrs[$source];
114           $mailObject->saved_attributes[$source] = $mailObject->attrs[$source];
115         }
117         unset ($mailObject->$dest['count']);
118         unset ($mailObject->attrs[$source]);
119       }
120     }
122     /* Adjust server name if needed */
123     foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
124       if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
125         $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
126         break;
127       }
128     }
129   }
132   function fixAttributesOnStore(&$mailObject)
133   {
134     global $config;
135   
136     /* If quota is empty, remove quota restrictions by setting quota to 0 */
137     if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
138       $mailObject->attrs['gosaMailQuota'] = 0;
139     }
141     /* Convert attributes and objectClasses */
142     foreach ($this->attribute_map as $source => $dest){
143       if (isset($mailObject->attrs[$source])){
144         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
145         unset ($mailObject->attrs[$source]);
146       }
147     }
148     $objectclasses= array();
149     foreach ($mailObject->attrs['objectClass'] as $oc){
150       if ($oc !=  'kolabInetOrgPerson' && $oc !=  'kolabSharedFolder'){
151         $objectclasses[]= $oc;
152       }
153     }
154     $mailObject->attrs['objectClass']= $objectclasses;
155     if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
156   
157       /* Add kolabSharedFoleder Class */
158       $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
160       /* Work on acl attribute */
161       $new_acl= array();
162       foreach ($mailObject->attrs['acl'] as $uacl){
164         /* Get user=(mail) & acls  */
165         list($user, $acl) = split(" ", $uacl);
166       
167         /* Add al users which have seperated acls 
168            %members% are all users in this group, 
169            which have the standard group acl
170         */
171         if ($user != "%members%"){
172           $new_acl[$user]= $uacl;
173         } else {
174         
175           /* All groupmembers will be added */
176           $ldap = $config->get_ldap_link();
177           $ldap->cd($config->current['BASE']);
178           foreach ($mailObject->members as $member){
180             /* Get user mail address .... */
181             $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
182             $res = $ldap->fetch();
184             /* Default mail address is set to uid - 
185                So if there is no mail address defined the uid is added 
186              */
187             $mail = $member;
189             /* Use mail address if it is available */
190             if(isset($res['mail'][0])){
191               $mail = $res['mail'][0];
192             }
194             /* only append this mail/permission string to acl,
195                if there arn't already some (special) configs for this user */
196             $found =false;
197             foreach($mailObject->imapacl as $mailA => $acl){
198               if(strtolower(trim($mailA))==strtolower(trim($mail))){
199                 $found = true;
200               }
201             }
203             /* Skipp user, with no email adress too */     
204             if($member == $mail){
205               $found = true;
206             }
207    
208             /* Append new user acl */
209             if(!$found){
210               $new_acl[$member]= "$mail $acl";
211             }
213             /* Old line */
214             //  $new_acl[$member]= "$member $acl";
215           }
216         }
217       }
218  
219       /* Save shared folder target */
220       $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->mail;
222       /* Kolab shared folder names are like ' shared.uid@server.de ' 
223         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
224         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
225       $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
226   
227       /* Assign new acls */
228       $mailObject->attrs['acl']= array();
229       foreach ($new_acl as $key => $value){
230         $mailObject->attrs['acl'][]= $value;
231       }
232     } else {
233       $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
234     }
236     /* Remove imap:// tagging */
237     $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
238     $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
239     $mailObject->attrs['kolabDeleteFlag']= array();
240   }
242   function fixAttributesOnRemove(&$mailObject)
243   {
244     /* Add attribute for object deletion and remove GOsa specific
245        values from entry. */
246     foreach($this->attribute_map as $kolabAttr){
247       $mailObject->attrs[$kolabAttr] = array();
248     }  
250     /* Only add kolab delete Flag in case of an user.mailAccount */
251     if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
252       $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
253     }else{
254       /* Kolab shared folder names are like ' shared.uid@server.de ' 
255         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
256         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
257       $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
258       
259     }
260   }
263   function deleteMailbox($folder)
264   {
265     /* Remove shared folders and skip removing users. 
266        KolabD is not able to remove shared folders yet, so we do it instead */
267     if(preg_match("/^shared/",$folder)){
268       return mailMethodCyrus::deleteMailbox($folder);
269     }
270     return (TRUE);
271   }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>