dc75674c264866d1c3b5a99affe85396a60a47b6
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 */
21 class mailMethodGolab extends mailMethodCyrus
22 {
23 var $mbox= "-";
24 var $config;
25 var $gosaMailServer= "";
26 var $uattrib= "mail";
28 var $attribute_map= array("gosaMailAlternateAddress" => "alias",
29 "gosaMailQuota" => "cyrus-userquota",
30 "gosaMailServer" => "kolabHomeServer");
32 function mailMethodGolab(&$config)
33 {
34 $this->config= $config->data['SERVERS']['IMAP'];
35 }
37 function updateMailbox($folder)
38 {
39 }
41 function setQuota($folder, $gosaMailQuota)
42 {
43 return (TRUE);
44 }
46 /* Get quota and divide it by 1024, because in gosa we display in MB
47 but we get Kb */
48 function getQuota($folder)
49 {
50 $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
52 /* Only use lower case folder names, if folder name is like "@domain.com" */
53 if(preg_match("/@/",$folder)){
54 $folder = strtolower($folder);
55 }
57 error_reporting(0);
59 /* Load quota settings */
60 $quota_value = @imap_get_quota($this->mbox, $folder);
61 if(is_array($quota_value)) {
62 if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
63 /* use for PHP >= 4.3 */
64 $result['quotaUsage']= (int) ($quota_value["STORAGE"]['usage'] / 1024);
65 $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
66 } else {
67 /* backward icompatible */
68 $result['quotaUsage']= (int) ($quota_value['usage'] / 1024);
69 $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
70 }
71 }elseif(!$quota_value){
72 return(false);
73 }
75 error_reporting(E_ALL | E_STRICT);
77 return ($result);
78 }
81 function fixAttributesOnLoad(&$mailObject)
82 {
83 /* Kolab shared folder names are like ' shared.uid@server.de '
84 So overwrite uid to match these folder names. Else we can't read quota settings etc.
85 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
86 if(get_class($mailObject) == "mailgroup"){
87 $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
88 }
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;
122 /* If quota is empty, remove quota restrictions by setting quota to 0 */
123 if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
124 $mailObject->attrs['gosaMailQuota'] = 0;
125 }
127 /* Convert attributes and objectClasses */
128 foreach ($this->attribute_map as $source => $dest){
129 if (isset($mailObject->attrs[$source])){
130 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
131 unset ($mailObject->attrs[$source]);
132 }
133 }
134 $objectclasses= array();
135 foreach ($mailObject->attrs['objectClass'] as $oc){
136 if ($oc != 'kolabInetOrgPerson' && $oc != 'kolabSharedFolder'){
137 $objectclasses[]= $oc;
138 }
139 }
140 $mailObject->attrs['objectClass']= $objectclasses;
141 if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
143 /* Add kolabSharedFoleder Class */
144 $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
146 /* Work on acl attribute */
147 $new_acl= array();
148 foreach ($mailObject->attrs['acl'] as $uacl){
150 /* Get user=(mail) & acls */
151 list($user, $acl) = split(" ", $uacl);
153 /* Add al users which have seperated acls
154 %members% are all users in this group,
155 which have the standard group acl
156 */
157 if ($user != "%members%"){
158 $new_acl[$user]= $uacl;
159 } else {
161 /* All groupmembers will be added */
162 $ldap = $config->get_ldap_link();
163 $ldap->cd($config->current['BASE']);
164 foreach ($mailObject->members as $member){
166 /* Get user mail address .... */
167 $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
168 $res = $ldap->fetch();
170 /* Default mail address is set to uid -
171 So if there is no mail address defined the uid is added
172 */
173 $mail = $member;
175 /* Use mail address if it is available */
176 if(isset($res['mail'][0])){
177 $mail = $res['mail'][0];
178 }
180 /* only append this mail/permission string to acl,
181 if there arn't already some (special) configs for this user */
182 $found =false;
183 foreach($mailObject->imapacl as $mailA => $acl){
184 if(strtolower(trim($mailA))==strtolower(trim($mail))){
185 $found = true;
186 }
187 }
189 /* Skipp user, with no email adress too */
190 if($member == $mail){
191 $found = true;
192 }
194 /* Append new user acl */
195 if(!$found){
196 $new_acl[$member]= "$mail $acl";
197 }
199 /* Old line */
200 // $new_acl[$member]= "$member $acl";
201 }
202 }
203 }
205 /* Save shared folder target */
206 $mailObject->attrs['gosaSharedFolderTarget']= "kolab+".$mailObject->mail;
208 /* Kolab shared folder names are like ' shared.uid@server.de '
209 So overwrite uid to match these folder names. Else we can't read quota settings etc.
210 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
211 $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
213 /* Assign new acls */
214 $mailObject->attrs['acl']= array();
215 foreach ($new_acl as $key => $value){
216 $mailObject->attrs['acl'][]= $value;
217 }
218 } else {
219 $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
220 }
222 /* Remove imap:// tagging */
223 $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
224 $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
225 $mailObject->attrs['kolabDeleteFlag']= array();
226 }
228 function fixAttributesOnRemove(&$mailObject)
229 {
230 /* Add attribute for object deletion and remove GOsa specific
231 values from entry. */
232 foreach($this->attribute_map as $kolabAttr){
233 $mailObject->attrs[$kolabAttr] = array();
234 }
236 /* Only add kolab delete Flag in case of an user.mailAccount */
237 if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
238 $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
239 }else{
240 /* Kolab shared folder names are like ' shared.uid@server.de '
241 So overwrite uid to match these folder names. Else we can't read quota settings etc.
242 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
243 $mailObject->uid = $mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
245 }
246 }
249 function deleteMailbox($folder)
250 {
251 /* Remove shared folders and skip removing users.
252 KolabD is not able to remove shared folders yet, so we do it instead */
253 if(!(preg_match("/^user\//",$folder))){
254 return mailMethodCyrus::deleteMailbox($folder);
255 }
256 return (TRUE);
257 }
258 }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>