Code

Updated copy paste method
[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 getQuota($folder)
48   {
49     $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
51     /* Load quota settings */
52     $folder = $folder;
54     /* try to read quota with style of users
55        user/name@server.de
56      */
57     $quota_value = @imap_get_quota($this->mbox, str_replace("user.","user/",$folder));
59     /* If obove method failed, try to read quota with style of users
60        user.name@server.de
61      */
62     if(!is_array($quota_value)){
63       $quota_value = @imap_get_quota($this->mbox, $folder);
64     }
66     if(is_array($quota_value)) {
67       if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
68         /* use for PHP >= 4.3 */
69         $result['quotaUsage']=    ($quota_value["STORAGE"]['usage'] / 1024);
70         $result['gosaMailQuota']= ($quota_value["STORAGE"]['limit'] / 1024);
71       } else {
72         /* backward icompatible */
73         $result['quotaUsage']=    ($quota_value['usage'] / 1024);
74         $result['gosaMailQuota']= ($quota_value['limit'] / 1024);
75       }
76     }
77     return ($result);
78   }
82   function deleteMailbox($folder)
83   {
84     return (TRUE);
85   }
88   function fixAttributesOnLoad(&$mailObject)
89   {
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     /* Convert attributes and objectClasses */
122     foreach ($this->attribute_map as $source => $dest){
123       if (isset($mailObject->attrs[$source])){
124         $mailObject->attrs[$dest]= $mailObject->attrs[$source];
125         unset ($mailObject->attrs[$source]);
126       }
127     }
128     $objectclasses= array();
129     foreach ($mailObject->attrs['objectClass'] as $oc){
130       if ($oc !=  'kolabInetOrgPerson' && $oc !=  'kolabSharedFolder'){
131         $objectclasses[]= $oc;
132       }
133     }
134     $mailObject->attrs['objectClass']= $objectclasses;
135     if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
136   
137       /* Add kolabSharedFoleder Class */
138       $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
140       /* Work on acl attribute */
141       $new_acl= array();
142       foreach ($mailObject->attrs['acl'] as $uacl){
144         /* Get user=(mail) & acls  */
145         list($user, $acl) = split(" ", $uacl);
146       
147         /* Add al users which have seperated acls 
148            %members% are all users in this group, 
149            which have the standard group acl
150         */
151         if ($user != "%members%"){
152           $new_acl[$user]= $uacl;
153         } else {
154         
155           /* All groupmembers will be added */
156           $ldap = $config->get_ldap_link();
157           $ldap->cd($config->current['BASE']);
158           foreach ($mailObject->members as $member){
160             /* Get user mail address .... */
161             $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
162             $res = $ldap->fetch();
164             /* Default mail address is set to uid - 
165                So if there is no mail address defined the uid is added 
166              */
167             $mail = $member;
169             /* Use mail address if it is available */
170             if(isset($res['mail'][0])){
171               $mail = $res['mail'][0];
172             }
174             /* only append this mail/permission string to acl,
175                if there arn't already some (special) configs for this user */
176             $found =false;
177             foreach($mailObject->imapacl as $mailA => $acl){
178               if(strtolower(trim($mailA))==strtolower(trim($mail))){
179                 $found = true;
180               }
181             }
183             /* Skipp user, with no email adress too */     
184             if($member == $mail){
185               $found = true;
186             }
187    
188             /* Append new user acl */
189             if(!$found){
190               $new_acl[$member]= "$mail $acl";
191             }
193             /* Old line */
194             //  $new_acl[$member]= "$member $acl";
195           }
196         }
197       }
198   
199       /* Assign new acls */
200       $mailObject->attrs['acl']= array();
201       foreach ($new_acl as $key => $value){
202         $mailObject->attrs['acl'][]= $value;
203       }
204     } else {
205       $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
206     }
208     /* Remove imap:// tagging */
209     $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
210     $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
211     $mailObject->attrs['kolabDeleteFlag']= array();
212   }
214   function fixAttributesOnRemove(&$mailObject)
215   {
216     /* Add attribute for object deletion and remove GOsa specific
217        values from entry. */
218     foreach($this->attribute_map as $kolabAttr){
219       $mailObject->attrs[$kolabAttr] = array();
220     }  
221     //$mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
222   }
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>