ecc405d8d83a8b7dbbde8e7a75085984f7023345
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 }
48 function deleteMailbox($folder)
49 {
50 return (TRUE);
51 }
54 function fixAttributesOnLoad(&$mailObject)
55 {
56 /* Convert attributes and objectClasses */
57 foreach ($this->attribute_map as $dest => $source){
58 /* Hickert 11.11.05 : Alternate email addresses were saved, but not displayed again.
59 if (isset($mailObject->attrs[$source])){
60 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
61 unset ($mailObject->attrs[$source]);
62 */
64 if (isset($mailObject->attrs[$source])){
65 unset($mailObject->attrs[$source]['count']);
66 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
67 $mailObject->$dest= $mailObject->attrs[$source];
69 unset ($mailObject->$dest['count']);
70 unset ($mailObject->attrs[$source]);
71 }
72 }
74 /* Adjust server name if needed */
75 foreach ($mailObject->config->data['SERVERS']['IMAP'] as $srv => $dummy){
76 if (preg_match("%".$mailObject->attrs['gosaMailServer'][0]."$%", $srv)){
77 $mailObject->attrs['gosaMailServer']= array(0 => $srv, "count" => 1);
78 break;
79 }
80 }
81 }
84 function fixAttributesOnStore(&$mailObject)
85 {
86 global $config;
87 /* Convert attributes and objectClasses */
88 foreach ($this->attribute_map as $source => $dest){
89 if (isset($mailObject->attrs[$source])){
90 $mailObject->attrs[$dest]= $mailObject->attrs[$source];
91 unset ($mailObject->attrs[$source]);
92 }
93 }
94 $objectclasses= array();
95 foreach ($mailObject->attrs['objectClass'] as $oc){
96 if ($oc != 'kolabInetOrgPerson' && $oc != 'kolabSharedFolder'){
97 $objectclasses[]= $oc;
98 }
99 }
100 $mailObject->attrs['objectClass']= $objectclasses;
101 if (in_array("posixGroup", $mailObject->attrs['objectClass'])){
103 /* Add kolabSharedFoleder Class */
104 $mailObject->attrs['objectClass'][]= 'kolabSharedFolder';
106 /* Work on acl attribute */
107 $new_acl= array();
108 foreach ($mailObject->attrs['acl'] as $uacl){
110 /* Get user=(mail) & acls */
111 list($user, $acl) = split(" ", $uacl);
113 /* Add al users which have seperated acls
114 %members% are all users in this group,
115 which have the standard group acl
116 */
117 if ($user != "%members%"){
118 $new_acl[$user]= $uacl;
119 } else {
121 /* All groupmembers will be added */
122 $ldap = $config->get_ldap_link();
123 $ldap->cd($config->current['BASE']);
124 foreach ($mailObject->members as $member){
126 /* Get user mail address .... */
127 $ldap->search("(&(objectClass=person)(|(uid=".$member.")(mail=".$member.")))",array("mail"));
128 $res = $ldap->fetch();
130 /* Default mail address is set to uid -
131 So if there is no mail address defined the uid is added
132 */
133 $mail = $member;
135 /* Use mail address if it is available */
136 if(isset($res['mail'][0])){
137 $mail = $res['mail'][0];
138 }
140 /* only append this mail/permission string to acl,
141 if there arn't already some (special) configs for this user */
142 $found =false;
143 foreach($mailObject->imapacl as $mailA => $acl){
144 if(strtolower(trim($mailA))==strtolower(trim($mail))){
145 $found = true;
146 }
147 }
149 /* Skipp user, with no email adress too */
150 if($member == $mail){
151 $found = true;
152 }
154 /* Append new user acl */
155 if(!$found){
156 $new_acl[$member]= "$mail $acl";
157 }
159 /* Old line */
160 // $new_acl[$member]= "$member $acl";
161 }
162 }
163 }
165 /* Assign new acls */
166 $mailObject->attrs['acl']= array();
167 foreach ($new_acl as $key => $value){
168 $mailObject->attrs['acl'][]= $value;
169 }
170 } else {
171 $mailObject->attrs['objectClass'][]= 'kolabInetOrgPerson';
172 }
174 /* Remove imap:// tagging */
175 $mailObject->attrs['kolabHomeServer']= preg_replace('%imap://%', '', $mailObject->attrs['kolabHomeServer']);
176 $mailObject->attrs['gosaMailServer']= $mailObject->attrs['kolabHomeServer'];
177 $mailObject->attrs['kolabDeleteFlag']= array();
178 }
180 function fixAttributesOnRemove(&$mailObject)
181 {
182 /* Add attribute for object deletion and remove GOsa specific
183 values from entry. */
184 unset ($mailObject->attrs['mail']);
185 $mailObject->attrs['kolabDeleteFlag']= preg_replace('%imap://%', '', $mailObject->gosaMailServer);
186 }
188 }
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>