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 /* Check if the mail account identification attribute
36 is overridden in the configuration file
37 */
38 if(isset($config->current['MAIL_ATTRIB']) && !empty($config->current['MAIL_ATTRIB'])){
39 $new_uattrib= strtolower($config->current['MAIL_ATTRIB']);
40 if(in_array($new_uattrib,array("mail","uid"))){
41 $this->uattrib = $new_uattrib;
42 }else{
43 trigger_error(sprintf("Unsupported MAIL_ATTRIB in gosa configuration specified, use 'mail' or 'uid', instead of '%s'.", $new_uattrib));
44 }
45 }
47 $this->config= $config->data['SERVERS']['IMAP'];
48 }
50 function updateMailbox($folder)
51 {
52 }
54 function setQuota($folder, $gosaMailQuota)
55 {
56 return (TRUE);
57 }
59 /* Get quota and divide it by 1024, because in gosa we display in MB
60 but we get Kb */
61 function getQuota($folder)
62 {
63 $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
65 /* Only use lower case folder names, if folder name is like "@domain.com" */
66 if(preg_match("/@/",$folder)){
67 $folder = strtolower($folder);
68 }
70 error_reporting(0);
72 /* Load quota settings */
73 $quota_value = @imap_get_quota($this->mbox, $folder);
74 if(is_array($quota_value)) {
75 if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
76 /* use for PHP >= 4.3 */
77 $result['quotaUsage']= (int) ($quota_value["STORAGE"]['usage'] / 1024);
78 $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
79 } else {
80 /* backward icompatible */
81 $result['quotaUsage']= (int) ($quota_value['usage'] / 1024);
82 $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
83 }
84 }elseif(!$quota_value){
85 return(false);
86 }
88 error_reporting(E_ALL);
90 return ($result);
91 }
94 function fixAttributesOnLoad(&$mailObject)
95 {
96 /* Kolab shared folder names are like ' shared.uid@server.de '
97 So overwrite uid to match these folder names. Else we can't read quota settings etc.
98 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
99 if(get_class($mailObject) == "mailgroup"){
100 $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
101 }
103 /* Convert attributes and objectClasses */
104 foreach ($this->attribute_map as $dest => $source){
105 /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
106 if (isset($mailObject->attrs[$source])){
107 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
108 unset ($mailObject->attrs[$source]);
109 */
111 if (isset($mailObject->attrs[$source])){
112 unset($mailObject->attrs[$source]['count']);
113 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
114 $mailObject->$dest= $mailObject->attrs[$source];
116 /* Ensure that cleanup will recognize the ampped attributes too */
117 if(isset($mailObject->saved_attributes)){
118 $mailObject->saved_attributes[$dest] = $mailObject->attrs[$source];
119 $mailObject->saved_attributes[$source] = $mailObject->attrs[$source];
120 }
122 unset ($mailObject->$dest['count']);
123 unset ($mailObject->attrs[$source]);
124 }
125 }
127 /* Adjust server name if needed */
128 foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
129 if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
130 $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
131 break;
132 }
133 }
134 }
137 function fixAttributesOnStore(&$mailObject)
138 {
139 global $config;
141 /* If quota is empty, remove quota restrictions by setting quota to 0 */
142 if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
143 $mailObject->attrs['gosaMailQuota'] = 0;
144 }
146 /* Convert attributes and objectClasses */
147 foreach ($this->attribute_map as $source => $dest){
148 if (isset($mailObject->attrs[$source])){
149 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
150 unset ($mailObject->attrs[$source]);
151 }
152 }
153 $objectclasses= array();
154 foreach ($mailObject->attrs['objectClass'] as $oc){
155 if ($oc != 'kolabInetOrgPerson' && $oc != 'kolabSharedFolder'){
156 $objectclasses[]= $oc;
157 }
158 }
159 $mailObject->attrs['objectClass']= $objectclasses;
160 if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
162 /* Add kolabSharedFoleder Class */
163 $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
165 /* Work on acl attribute */
166 $new_acl= array();
167 foreach ($mailObject->attrs['acl'] as $uacl){
169 /* Get user=(mail) & acls */
170 list($user, $acl) = split(" ", $uacl);
172 /* Add al users which have seperated acls
173 %members% are all users in this group,
174 which have the standard group acl
175 */
176 if ($user != "%members%"){
177 $new_acl[$user]= $uacl;
178 } else {
180 /* All groupmembers will be added */
181 $ldap = $config->get_ldap_link();
182 $ldap->cd($config->current['BASE']);
183 foreach ($mailObject->members as $member){
185 /* Get user mail address .... */
186 $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
187 $res = $ldap->fetch();
189 /* Default mail address is set to uid -
190 So if there is no mail address defined the uid is added
191 */
192 $mail = $member;
194 /* Use mail address if it is available */
195 if(isset($res['mail'][0])){
196 $mail = $res['mail'][0];
197 }
199 /* only append this mail/permission string to acl,
200 if there arn't already some (special) configs for this user */
201 $found =false;
202 foreach($mailObject->imapacl as $mailA => $acl){
203 if(strtolower(trim($mailA))==strtolower(trim($mail))){
204 $found = true;
205 }
206 }
208 /* Skipp user, with no email adress too */
209 if($member == $mail){
210 $found = true;
211 }
213 /* Append new user acl */
214 if(!$found){
215 $new_acl[$member]= "$mail $acl";
216 }
218 /* Old line */
219 // $new_acl[$member]= "$member $acl";
220 }
221 }
222 }
224 /* Kolab shared folder names are like ' shared.uid@server.de '
225 So overwrite uid to match these folder names. Else we can't read quota settings etc.
226 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
227 $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
229 /* Save shared folder target */
230 $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->cn."@".preg_replace("/^.*@/","",$mailObject->mail);
232 /* Assign new acls */
233 $mailObject->attrs['acl']= array();
234 foreach ($new_acl as $key => $value){
235 $mailObject->attrs['acl'][]= $value;
236 }
237 } else {
238 $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
239 }
241 /* Remove imap:// tagging */
242 $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
243 $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
244 $mailObject->attrs['kolabDeleteFlag']= array();
245 }
247 function fixAttributesOnRemove(&$mailObject)
248 {
249 /* Add attribute for object deletion and remove GOsa specific
250 values from entry. */
251 foreach($this->attribute_map as $kolabAttr){
252 $mailObject->attrs[$kolabAttr] = array();
253 }
255 /* Only add kolab delete Flag in case of an user.mailAccount */
256 if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
257 $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
258 }else{
259 /* Kolab shared folder names are like ' shared.uid@server.de '
260 So overwrite uid to match these folder names. Else we can't read quota settings etc.
261 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
262 $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
264 }
265 }
268 function deleteMailbox($folder)
269 {
270 /* Remove shared folders and skip removing users.
271 KolabD is not able to remove shared folders yet, so we do it instead */
272 if(preg_match("/^shared/",$folder)){
273 return mailMethodCyrus::deleteMailbox($folder);
274 }
275 return (TRUE);
276 }
277 }
279 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
280 ?>