Code

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