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