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