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