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