[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /***************************************************************************\ 3 * EGroupWare - EMailAdmin * 4 * http://www.egroupware.org * 5 * Written by : Lars Kneschke [lkneschke@linux-at-work.de] * 6 * ------------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; version 2 of the License. * 10 \***************************************************************************/ 11 /* $Id: class.cyrusimap.inc.php 21515 2006-05-06 11:08:11Z ralfbecker $ */ 12 13 include_once (EGW_SERVER_ROOT."/emailadmin/inc/class.defaultimap.inc.php"); 14 15 class cyrusimap extends defaultimap 16 { 17 #function cyrusimap() 18 #{ 19 #} 20 21 function addAccount($_hookValues) 22 { 23 if($this->profileData['imapEnableCyrusAdmin'] != 'yes' || 24 empty($this->profileData['imapAdminUsername']) || 25 empty($this->profileData['imapAdminPW']) ) { 26 return false; 27 } 28 29 #_debug_array($_hookValues); 30 $username = $_hookValues['account_lid']; 31 $userPassword = $_hookValues['new_passwd']; 32 33 #_debug_array($this->profileData); 34 $imapAdminUsername = $this->profileData['imapAdminUsername']; 35 $imapAdminPW = $this->profileData['imapAdminPW']; 36 37 38 // create the mailbox 39 if($mbox = @imap_open ($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) 40 { 41 $list = imap_getmailboxes($mbox, $this->getMailboxString(), "INBOX"); 42 $delimiter = isset($list[0]->delimiter) ? $list[0]->delimiter : '.'; 43 // create the users folders 44 45 $folderNames = array( 46 'user'.$delimiter.$username , 47 'user'.$delimiter.$username.$delimiter.'Trash' , 48 'user'.$delimiter.$username.$delimiter.'Sent' 49 ); 50 51 foreach($folderNames as $mailBoxName) 52 { 53 if(imap_createmailbox($mbox,imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) 54 { 55 if(!imap_setacl($mbox, $mailBoxName, $username, "lrswipcda")) 56 { 57 # log error message 58 } 59 } 60 } 61 imap_close($mbox); 62 } 63 else 64 { 65 #_debug_array(imap_errors()); 66 return false; 67 } 68 69 // subscribe to the folders 70 if($mbox = @imap_open($this->getMailboxString(), $username, $userPassword)) 71 { 72 imap_subscribe($mbox,$this->getMailboxString('INBOX')); 73 imap_subscribe($mbox,$this->getMailboxString('INBOX.Sent')); 74 imap_subscribe($mbox,$this->getMailboxString('INBOX.Trash')); 75 imap_close($mbox); 76 } 77 else 78 { 79 # log error message 80 } 81 } 82 83 function deleteAccount($_hookValues) 84 { 85 if($this->profileData['imapEnableCyrusAdmin'] != 'yes' || 86 empty($this->profileData['imapAdminUsername']) || 87 empty($this->profileData['imapAdminPW']) ) { 88 return false; 89 } 90 91 $username = $_hookValues['account_lid']; 92 93 $imapAdminUsername = $this->profileData['imapAdminUsername']; 94 $imapAdminPW = $this->profileData['imapAdminPW']; 95 96 if($mbox = @imap_open($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) 97 { 98 $list = imap_getmailboxes($mbox, $this->getMailboxString(), "INBOX"); 99 $delimiter = isset($list[0]->delimiter) ? $list[0]->delimiter : '.'; 100 101 $mailBoxName = 'user'.$delimiter.$username; 102 // give the admin account the rights to delete this mailbox 103 if(imap_setacl($mbox, $mailBoxName, $imapAdminUsername, "lrswipcda")) 104 { 105 if(imap_deletemailbox($mbox, 106 imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) 107 { 108 return true; 109 } 110 else 111 { 112 // not able to delete mailbox 113 return false; 114 } 115 } 116 else 117 { 118 // not able to set acl 119 return false; 120 } 121 } 122 else 123 { 124 // imap open failed 125 return false; 126 } 127 } 128 129 function updateAccount($_hookValues) 130 { 131 if($this->profileData['imapEnableCyrusAdmin'] != 'yes' || 132 empty($this->profileData['imapAdminUsername']) || 133 empty($this->profileData['imapAdminPW']) ) { 134 return false; 135 } 136 #_debug_array($_hookValues); 137 $username = $_hookValues['account_lid']; 138 if(isset($_hookValues['new_passwd'])) 139 $userPassword = $_hookValues['new_passwd']; 140 141 #_debug_array($this->profileData); 142 $imapAdminUsername = $this->profileData['imapAdminUsername']; 143 $imapAdminPW = $this->profileData['imapAdminPW']; 144 145 // create the mailbox 146 if($mbox = @imap_open ($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) 147 { 148 $list = imap_getmailboxes($mbox, $this->getMailboxString(), "INBOX"); 149 $delimiter = isset($list[0]->delimiter) ? $list[0]->delimiter : '.'; 150 // create the users folders 151 152 if($_hookValues['account_lid'] != $_hookValues['old_loginid']) { 153 @imap_renamemailbox($mbox, $this->getMailboxString('user'.$delimiter.$_hookValues['old_loginid']), $this->getMailboxString('user'.$delimiter.$username)); 154 155 if(strpos($_hookValues['account_lid'],'.') && function_exists('imap_getacl')) { 156 // this is a hack for some broken cyrus imap server versions 157 // after the account rename to l.kneschke for example, the acl got renamed to l^kneschke 158 // which is wrong! also the acl need to be renamed to l.kneschke too 159 // l^kneschke is only the name for the folder in the filesystem 160 // we search for broken acl entries and replace them with the correct ones 161 $list = imap_list($mbox, $this->getMailboxString('user'.$delimiter.$username), '*'); 162 foreach($list as $longMailboxName) { 163 $shortMailboxName = preg_replace("/{.*}/",'',$longMailboxName); 164 $currentACL = imap_getacl ($mbox, $shortMailboxName); 165 foreach((array)$currentACL as $accountName => $acl) { 166 $pos = strpos($accountName, '^'); 167 if($pos !== false) { 168 imap_setacl ($mbox, $shortMailboxName, $accountName, ""); 169 imap_setacl ($mbox, $shortMailboxName, $_hookValues['account_lid'], $acl); 170 } 171 } 172 } 173 } 174 } 175 176 $folderNames = array( 177 'user'.$delimiter.$username , 178 'user'.$delimiter.$username.$delimiter.'Trash' , 179 'user'.$delimiter.$username.$delimiter.'Sent' 180 ); 181 182 // create the users folders 183 foreach($folderNames as $mailBoxName) 184 { 185 if(imap_createmailbox($mbox,imap_utf7_encode("{".$this->profileData['imapServer']."}$mailBoxName"))) 186 { 187 if(!imap_setacl($mbox, $mailBoxName, $username, "lrswipcda")) 188 { 189 # log error message 190 } 191 } 192 } 193 imap_close($mbox); 194 } 195 else 196 { 197 return false; 198 } 199 200 // we can only subscribe to the folders, if we have the users password 201 if(isset($_hookValues['new_passwd'])) 202 { 203 if($mbox = @imap_open($this->getMailboxString(), $username, $userPassword)) 204 { 205 imap_subscribe($mbox,$this->getMailboxString('INBOX')); 206 imap_subscribe($mbox,$this->getMailboxString('INBOX' .$delimiter. 'Sent')); 207 imap_subscribe($mbox,$this->getMailboxString('INBOX' .$delimiter. 'Trash')); 208 imap_close($mbox); 209 } 210 else 211 { 212 # log error message 213 } 214 } 215 } 216 } 217 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |