Code

Added seperate
[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   }
52   function getMailboxList($folder, $uid= "")
53   {
54     global $config;
55     $result = array();
57     /* Get domain an mail address if uid is an mail address */
58     $domain = "";
59     if(preg_match("/@/",$folder)){
60       $domain = preg_replace("/^.*@/","",$folder);
61       $folder = preg_replace("/@.*$/","",$folder);
62     }
64     /* Get list of mailboxes for combo box */
65     $cfg= $this->config[$this->gosaMailServer];
66     
67     /* Create search pattern
68          (user/kekse*@domain.de
69           user.kekse*@domain.de 
70           user.kekse*  )
71        depending on given folder name) */
72     $q = $folder."*@".$domain;
73     $list = imap_listmailbox($this->mbox, $cfg["connect"], $q);
75     /* Create list of returned folder names */
76     if (is_array($list)){
77       foreach ($list as $val){
79         /* Cut domain name */
80         $val = preg_replace("/@.*$/","",$val);
81         $result[]=preg_replace ("/^.*".normalizePreg($folder)."/","INBOX", imap_utf7_decode ($val));
82       }
83     }
85     /* Append "INBOX" to the folder array if result is empty and request comes from user dialog */
86     if(empty($result) && !empty($uid)){
87       $result[] = "INBOX";
88     }
90     return ($result);
91   }
95   /* Get quota and divide it by 1024, because in gosa we display in MB
96       but we get Kb */
97   function getQuota($folder)
98   {
99     $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
101     error_reporting(0);  
102   
103     /* Load quota settings */
104     $quota_value = @imap_get_quota($this->mbox, $folder);
105     if(is_array($quota_value)) {
106       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
107         /* use for PHP >= 4.3 */
108         $result['quotaUsage']=    (int) ($quota_value["STORAGE"]['usage'] / 1024);
109         $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
110       } else {
111         /* backward icompatible */
112         $result['quotaUsage']=    (int) ($quota_value['usage'] / 1024);
113         $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
114       }
115     }elseif(!$quota_value){
116       return(false);
117     }
119     error_reporting(E_ALL); 
120  
121     return ($result);
122   }
125   function fixAttributesOnLoad(&$mailObject)
126   {
127     /* Kolab shared folder names are like ' shared.uid@server.de ' 
128         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
129         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
130     if(get_class($mailObject) == "mailgroup"){
131      $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
132     }
134     /* Convert attributes and objectClasses */
135     foreach ($this->attribute_map as $dest => $source){
136       /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
137       if (isset($mailObject->attrs[$source])){
138         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
139         unset ($mailObject->attrs[$source]);
140       */
142       if (isset($mailObject->attrs[$source])){
143         unset($mailObject->attrs[$source]['count']);
144         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
145         $mailObject->$dest=        $mailObject->attrs[$source];
147         unset ($mailObject->$dest['count']);
148         unset ($mailObject->attrs[$source]);
149       }
150     }
152     /* Adjust server name if needed */
153     foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
154       if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
155         $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
156         break;
157       }
158     }
159   }
162   function fixAttributesOnStore(&$mailObject)
163   {
164     global $config;
165   
166     /* If quota is empty, remove quota restrictions by setting quota to 0 */
167     if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
168       $mailObject->attrs['gosaMailQuota'] = 0;
169     }
171     /* Convert attributes and objectClasses */
172     foreach ($this->attribute_map as $source => $dest){
173       if (isset($mailObject->attrs[$source])){
174         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
175         unset ($mailObject->attrs[$source]);
176       }
177     }
178     $objectclasses= array();
179     foreach ($mailObject->attrs['objectClass'] as $oc){
180       if ($oc !=  'kolabInetOrgPerson' && $oc !=  'kolabSharedFolder'){
181         $objectclasses[]= $oc;
182       }
183     }
184     $mailObject->attrs['objectClass']= $objectclasses;
185     if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
186   
187       /* Add kolabSharedFoleder Class */
188       $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
190       /* Work on acl attribute */
191       $new_acl= array();
192       foreach ($mailObject->attrs['acl'] as $uacl){
194         /* Get user=(mail) & acls  */
195         list($user, $acl) = split(" ", $uacl);
196       
197         /* Add al users which have seperated acls 
198            %members% are all users in this group, 
199            which have the standard group acl
200         */
201         if ($user != "%members%"){
202           $new_acl[$user]= $uacl;
203         } else {
204         
205           /* All groupmembers will be added */
206           $ldap = $config->get_ldap_link();
207           $ldap->cd($config->current['BASE']);
208           foreach ($mailObject->members as $member){
210             /* Get user mail address .... */
211             $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
212             $res = $ldap->fetch();
214             /* Default mail address is set to uid - 
215                So if there is no mail address defined the uid is added 
216              */
217             $mail = $member;
219             /* Use mail address if it is available */
220             if(isset($res['mail'][0])){
221               $mail = $res['mail'][0];
222             }
224             /* only append this mail/permission string to acl,
225                if there arn't already some (special) configs for this user */
226             $found =false;
227             foreach($mailObject->imapacl as $mailA => $acl){
228               if(strtolower(trim($mailA))==strtolower(trim($mail))){
229                 $found = true;
230               }
231             }
233             /* Skipp user, with no email adress too */     
234             if($member == $mail){
235               $found = true;
236             }
237    
238             /* Append new user acl */
239             if(!$found){
240               $new_acl[$member]= "$mail $acl";
241             }
243             /* Old line */
244             //  $new_acl[$member]= "$member $acl";
245           }
246         }
247       }
248  
249       /* Save shared folder target */
250       $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->uid;
252       /* Kolab shared folder names are like ' shared.uid@server.de ' 
253         So overwrite uid to match these folder names. Else we can't read quota settings etc. 
254         #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
255       $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
256   
257       /* Assign new acls */
258       $mailObject->attrs['acl']= array();
259       foreach ($new_acl as $key => $value){
260         $mailObject->attrs['acl'][]= $value;
261       }
262     } else {
263       $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
264     }
266     /* Remove imap:// tagging */
267     $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
268     $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
269     $mailObject->attrs['kolabDeleteFlag']= array();
270   }
272   function fixAttributesOnRemove(&$mailObject)
273   {
274     /* Add attribute for object deletion and remove GOsa specific
275        values from entry. */
276     foreach($this->attribute_map as $kolabAttr){
277       $mailObject->attrs[$kolabAttr] = array();
278     }  
280     /* Only add kolab delete Flag in case of an user.mailAccount */
281     if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
282       $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
283     }
284   }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>