0d51b2d23ccae8f30d98d33d0dc4d0cb4151f4c9
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 /* return all folders of the users mailbox*/
39 function getMailboxList($folder, $uid= "")
40 {
41 global $config;
42 $result = array();
44 /* Get domain an mail address if uid is an mail address */
45 $domain = "";
46 if(preg_match("/@/",$folder)){
47 $domain = preg_replace("/^.*@/","",$folder);
48 $folder = preg_replace("/@.*$/","",$folder);
49 }
51 /* Get list of mailboxes for combo box */
52 $cfg= $this->config[$this->gosaMailServer];
54 /* Create search pattern
55 (user/kekse*@domain.de
56 user.kekse*@domain.de
57 user.kekse* )
58 depending on given folder name) */
59 $q = $folder."*@".$domain;
60 $list = imap_listmailbox($this->mbox, $cfg["connect"], $q);
62 /* Create list of returned folder names */
63 if (is_array($list)){
64 foreach ($list as $val){
66 /* Cut domain name */
67 $val = preg_replace("/@.*$/","",$val);
68 $result[]=preg_replace ("/^.*".normalizePreg($folder)."/","INBOX", imap_utf7_decode ($val));
69 }
70 }
72 /* Append "INBOX" to the folder array if result is empty and request comes from user dialog */
73 if(empty($result) && !empty($uid)){
74 $result[] = "INBOX";
75 }
77 return ($result);
78 }
83 function updateMailbox($folder)
84 {
85 }
87 function setQuota($folder, $gosaMailQuota)
88 {
89 return (TRUE);
90 }
92 function deleteMailbox($folder)
93 {
94 return (TRUE);
95 }
98 /* Get quota and divide it by 1024, because in gosa we display in MB
99 but we get Kb */
100 function getQuota($folder)
101 {
102 $result= array('quotaUsage' => '', 'gosaMailQuota' => '');
104 error_reporting(0);
106 /* Load quota settings */
107 $quota_value = @imap_get_quota($this->mbox, $folder);
108 if(is_array($quota_value)) {
109 if (isset($quota_value["STORAGE"]) && is_array($quota_value["STORAGE"])){
110 /* use for PHP >= 4.3 */
111 $result['quotaUsage']= (int) ($quota_value["STORAGE"]['usage'] / 1024);
112 $result['gosaMailQuota']= (int) ($quota_value["STORAGE"]['limit'] / 1024);
113 } else {
114 /* backward icompatible */
115 $result['quotaUsage']= (int) ($quota_value['usage'] / 1024);
116 $result['gosaMailQuota']= (int) ($quota_value['limit'] / 1024);
117 }
118 }elseif(!$quota_value){
119 return(false);
120 }
122 error_reporting(E_ALL);
124 return ($result);
125 }
128 function fixAttributesOnLoad(&$mailObject)
129 {
130 /* Kolab shared folder names are like ' shared.uid@server.de '
131 So overwrite uid to match these folder names. Else we can't read quota settings etc.
132 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
133 if(get_class($mailObject) == "mailgroup"){
134 $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
135 }
137 /* Convert attributes and objectClasses */
138 foreach ($this->attribute_map as $dest => $source){
139 /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
140 if (isset($mailObject->attrs[$source])){
141 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
142 unset ($mailObject->attrs[$source]);
143 */
145 if (isset($mailObject->attrs[$source])){
146 unset($mailObject->attrs[$source]['count']);
147 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
148 $mailObject->$dest= $mailObject->attrs[$source];
150 unset ($mailObject->$dest['count']);
151 unset ($mailObject->attrs[$source]);
152 }
153 }
155 /* Adjust server name if needed */
156 foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
157 if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
158 $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
159 break;
160 }
161 }
162 }
165 function fixAttributesOnStore(&$mailObject)
166 {
167 global $config;
169 /* If quota is empty, remove quota restrictions by setting quota to 0 */
170 if(isset($mailObject->gosaMailQuota) && (empty($mailObject->gosaMailQuota))){
171 $mailObject->attrs['gosaMailQuota'] = 0;
172 }
174 /* Convert attributes and objectClasses */
175 foreach ($this->attribute_map as $source => $dest){
176 if (isset($mailObject->attrs[$source])){
177 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
178 unset ($mailObject->attrs[$source]);
179 }
180 }
181 $objectclasses= array();
182 foreach ($mailObject->attrs['objectClass'] as $oc){
183 if ($oc != 'kolabInetOrgPerson' && $oc != 'kolabSharedFolder'){
184 $objectclasses[]= $oc;
185 }
186 }
187 $mailObject->attrs['objectClass']= $objectclasses;
188 if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
190 /* Add kolabSharedFoleder Class */
191 $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
193 /* Work on acl attribute */
194 $new_acl= array();
195 foreach ($mailObject->attrs['acl'] as $uacl){
197 /* Get user=(mail) & acls */
198 list($user, $acl) = split(" ", $uacl);
200 /* Add al users which have seperated acls
201 %members% are all users in this group,
202 which have the standard group acl
203 */
204 if ($user != "%members%"){
205 $new_acl[$user]= $uacl;
206 } else {
208 /* All groupmembers will be added */
209 $ldap = $config->get_ldap_link();
210 $ldap->cd($config->current['BASE']);
211 foreach ($mailObject->members as $member){
213 /* Get user mail address .... */
214 $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
215 $res = $ldap->fetch();
217 /* Default mail address is set to uid -
218 So if there is no mail address defined the uid is added
219 */
220 $mail = $member;
222 /* Use mail address if it is available */
223 if(isset($res['mail'][0])){
224 $mail = $res['mail'][0];
225 }
227 /* only append this mail/permission string to acl,
228 if there arn't already some (special) configs for this user */
229 $found =false;
230 foreach($mailObject->imapacl as $mailA => $acl){
231 if(strtolower(trim($mailA))==strtolower(trim($mail))){
232 $found = true;
233 }
234 }
236 /* Skipp user, with no email adress too */
237 if($member == $mail){
238 $found = true;
239 }
241 /* Append new user acl */
242 if(!$found){
243 $new_acl[$member]= "$mail $acl";
244 }
246 /* Old line */
247 // $new_acl[$member]= "$member $acl";
248 }
249 }
250 }
252 /* Save shared folder target */
253 $mailObject->attrs['gosaSharedFolderTarget']= "kolab+shared.".$mailObject->uid;
255 /* Kolab shared folder names are like ' shared.uid@server.de '
256 So overwrite uid to match these folder names. Else we can't read quota settings etc.
257 #FIXME is there a better way to detect if it is 'shared.' or 'shared+' or 'kolab+shared.' or what ever ?*/
258 $mailObject->uid = "shared.".$mailObject->uid."@".preg_replace("/^.*@/","",$mailObject->mail);
260 /* Assign new acls */
261 $mailObject->attrs['acl']= array();
262 foreach ($new_acl as $key => $value){
263 $mailObject->attrs['acl'][]= $value;
264 }
265 } else {
266 $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
267 }
269 /* Remove imap:// tagging */
270 $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
271 $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
272 $mailObject->attrs['kolabDeleteFlag']= array();
273 }
275 function fixAttributesOnRemove(&$mailObject)
276 {
277 /* Add attribute for object deletion and remove GOsa specific
278 values from entry. */
279 foreach($this->attribute_map as $kolabAttr){
280 $mailObject->attrs[$kolabAttr] = array();
281 }
283 /* Only add kolab delete Flag in case of an user.mailAccount */
284 if(!in_array("posixGroup", $mailObject->attrs['objectClass'])){
285 $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
286 }
287 }
289 }
291 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
292 ?>