[903] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * http://www.linux-at-work.de * |
---|
| 6 | * Written by : Lars Kneschke [lkneschke@linux-at-work.de] * |
---|
| 7 | * ------------------------------------------------- * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
| 14 | class bo |
---|
| 15 | { |
---|
| 16 | var $sessionData; |
---|
| 17 | var $LDAPData; |
---|
| 18 | |
---|
| 19 | var $SMTPServerType = array(); // holds a list of config options |
---|
| 20 | |
---|
| 21 | var $imapClass; // holds the imap/pop3 class |
---|
| 22 | var $smtpClass; // holds the smtp class |
---|
| 23 | |
---|
| 24 | var $public_functions = array |
---|
| 25 | ( |
---|
| 26 | 'getFieldNames' => True, |
---|
| 27 | 'getLDAPStorageData' => True, |
---|
| 28 | 'getLocals' => True, |
---|
| 29 | 'getProfile' => True, |
---|
| 30 | 'getProfileList' => True, |
---|
| 31 | 'getRcptHosts' => True, |
---|
| 32 | 'getSMTPServerTypes' => True |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | function bo($_profileID=-1) |
---|
| 36 | { |
---|
| 37 | $this->soemailadmin = CreateObject('emailadmin.so'); |
---|
| 38 | |
---|
| 39 | $this->SMTPServerType = array( |
---|
| 40 | '1' => array( |
---|
| 41 | 'fieldNames' => array( |
---|
| 42 | 'smtpServer', |
---|
| 43 | 'smtpPort', |
---|
| 44 | 'smtpAuth', |
---|
| 45 | 'smtpType' |
---|
| 46 | ), |
---|
| 47 | 'description' => lang('standard SMTP-Server'), |
---|
| 48 | 'classname' => 'defaultsmtp' |
---|
| 49 | ), |
---|
| 50 | '2' => array( |
---|
| 51 | 'fieldNames' => array( |
---|
| 52 | 'smtpServer', |
---|
| 53 | 'smtpPort', |
---|
| 54 | 'smtpAuth', |
---|
| 55 | 'smtpType', |
---|
| 56 | 'smtpLDAPServer', |
---|
| 57 | 'smtpLDAPAdminDN', |
---|
| 58 | 'smtpLDAPAdminPW', |
---|
| 59 | 'smtpLDAPBaseDN', |
---|
| 60 | 'smtpLDAPUseDefault' |
---|
| 61 | ), |
---|
| 62 | 'description' => lang('Postfix with LDAP'), |
---|
| 63 | 'classname' => 'postfixldap' |
---|
| 64 | ) |
---|
| 65 | ); |
---|
| 66 | |
---|
| 67 | $this->IMAPServerType = array( |
---|
| 68 | '1' => array( |
---|
| 69 | 'fieldNames' => array( |
---|
| 70 | 'imapServer', |
---|
| 71 | 'imapPort', |
---|
| 72 | 'imapType', |
---|
| 73 | 'imapLoginType', |
---|
| 74 | 'imapTLSEncryption', |
---|
| 75 | 'imapTLSAuthentication', |
---|
| 76 | 'imapoldcclient' |
---|
| 77 | ), |
---|
| 78 | 'description' => lang('standard POP3 server'), |
---|
| 79 | 'protocol' => 'pop3', |
---|
| 80 | 'classname' => 'defaultpop' |
---|
| 81 | ), |
---|
| 82 | '2' => array( |
---|
| 83 | 'fieldNames' => array( |
---|
| 84 | 'imapServer', |
---|
| 85 | 'imapPort', |
---|
| 86 | 'imapType', |
---|
| 87 | 'imapLoginType', |
---|
| 88 | 'imapTLSEncryption', |
---|
| 89 | 'imapTLSAuthentication', |
---|
| 90 | 'imapoldcclient' |
---|
| 91 | ), |
---|
| 92 | 'description' => lang('standard IMAP server'), |
---|
| 93 | 'protocol' => 'imap', |
---|
| 94 | 'classname' => 'defaultimap' |
---|
| 95 | ), |
---|
| 96 | '3' => array( |
---|
| 97 | 'fieldNames' => array( |
---|
| 98 | 'imapServer', |
---|
| 99 | 'imapPort', |
---|
| 100 | 'imapDelimiter', |
---|
| 101 | 'imapType', |
---|
| 102 | 'imapLoginType', |
---|
| 103 | 'imapTLSEncryption', |
---|
| 104 | 'imapTLSAuthentication', |
---|
| 105 | 'imapoldcclient', |
---|
| 106 | 'imapEnableCyrusAdmin', |
---|
| 107 | 'imapAdminUsername', |
---|
| 108 | 'imapAdminPW', |
---|
| 109 | 'imapEnableSieve', |
---|
| 110 | 'imapSieveServer', |
---|
| 111 | 'imapSievePort' |
---|
| 112 | ), |
---|
| 113 | 'description' => lang('Cyrus IMAP Server'), |
---|
| 114 | 'protocol' => 'imap', |
---|
| 115 | 'classname' => 'cyrusimap' |
---|
| 116 | ) |
---|
| 117 | ); |
---|
| 118 | |
---|
| 119 | $this->restoreSessionData(); |
---|
| 120 | |
---|
| 121 | if($_profileID >= 0) |
---|
| 122 | { |
---|
| 123 | $this->profileID = $_profileID; |
---|
| 124 | |
---|
| 125 | $this->profileData = $this->getProfile($_profileID); |
---|
| 126 | |
---|
| 127 | $this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname']; |
---|
| 128 | $this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname']; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function addAccount($_hookValues) |
---|
| 133 | { |
---|
| 134 | if (!empty($this->imapClass)) |
---|
| 135 | { |
---|
| 136 | ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | if (!empty($this->smtpClass)) |
---|
| 140 | { |
---|
| 141 | ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData); |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | function deleteAccount($_hookValues) |
---|
| 146 | { |
---|
| 147 | if (!empty($this->imapClass)) |
---|
| 148 | { |
---|
| 149 | ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | if (!empty($this->smtpClass)) |
---|
| 153 | { |
---|
| 154 | ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | function deleteProfile($_profileID) |
---|
| 159 | { |
---|
| 160 | $this->soemailadmin->deleteProfile($_profileID); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | function encodeHeader($_string, $_encoding='q') |
---|
| 164 | { |
---|
| 165 | switch($_encoding) |
---|
| 166 | { |
---|
| 167 | case "q": |
---|
| 168 | if(!preg_match("/[\x80-\xFF]/",$_string)) |
---|
| 169 | { |
---|
| 170 | // nothing to quote, only 7 bit ascii |
---|
| 171 | return $_string; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | $string = imap_8bit($_string); |
---|
| 175 | $stringParts = explode("=\r\n",$string); |
---|
| 176 | while(list($key,$value) = each($stringParts)) |
---|
| 177 | { |
---|
| 178 | if(!empty($retString)) $retString .= " "; |
---|
| 179 | $value = str_replace(" ","_",$value); |
---|
| 180 | // imap_8bit does not convert "?" |
---|
| 181 | // it does not need, but it should |
---|
| 182 | $value = str_replace("?","=3F",$value); |
---|
| 183 | $retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?="; |
---|
| 184 | } |
---|
| 185 | #exit; |
---|
| 186 | return $retString; |
---|
| 187 | break; |
---|
| 188 | default: |
---|
| 189 | return $_string; |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | function getAccountEmailAddress($_accountName, $_profileID) |
---|
| 194 | { |
---|
| 195 | $profileData = $this->getProfile($_profileID); |
---|
| 196 | |
---|
| 197 | $smtpClass = $this->SMTPServerType[$profileData['smtpType']]['classname']; |
---|
| 198 | |
---|
| 199 | return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | function getFieldNames($_serverTypeID, $_class) |
---|
| 203 | { |
---|
| 204 | switch($_class) |
---|
| 205 | { |
---|
| 206 | case 'imap': |
---|
| 207 | return $this->IMAPServerType[$_serverTypeID]['fieldNames']; |
---|
| 208 | break; |
---|
| 209 | case 'smtp': |
---|
| 210 | return $this->SMTPServerType[$_serverTypeID]['fieldNames']; |
---|
| 211 | break; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | # function getIMAPClass($_profileID) |
---|
| 216 | # { |
---|
| 217 | # if(!is_object($this->imapClass)) |
---|
| 218 | # { |
---|
| 219 | # $profileData = $this->getProfile($_profileID); |
---|
| 220 | # $this->imapClass = CreateObject('emailadmin.cyrusimap',$profileData); |
---|
| 221 | # } |
---|
| 222 | # |
---|
| 223 | # return $this->imapClass; |
---|
| 224 | # } |
---|
| 225 | |
---|
| 226 | function getIMAPServerTypes() |
---|
| 227 | { |
---|
| 228 | foreach($this->IMAPServerType as $key => $value) |
---|
| 229 | { |
---|
| 230 | $retData[$key]['description'] = $value['description']; |
---|
| 231 | $retData[$key]['protocol'] = $value['protocol']; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | return $retData; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | function getLDAPStorageData($_serverid) |
---|
| 238 | { |
---|
| 239 | $storageData = $this->soemailadmin->getLDAPStorageData($_serverid); |
---|
| 240 | return $storageData; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | function getMailboxString($_folderName) |
---|
| 244 | { |
---|
| 245 | if (!empty($this->imapClass)) |
---|
| 246 | { |
---|
| 247 | return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData); |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | return false; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | function getProfile($_profileID) |
---|
| 256 | { |
---|
| 257 | $profileData = $this->soemailadmin->getProfileList($_profileID); |
---|
| 258 | $fieldNames = $this->SMTPServerType[$profileData[0]['smtpType']]['fieldNames']; |
---|
| 259 | $fieldNames = array_merge($fieldNames, $this->IMAPServerType[$profileData[0]['imapType']]['fieldNames']); |
---|
| 260 | $fieldNames[] = 'description'; |
---|
| 261 | $fieldNames[] = 'defaultDomain'; |
---|
| 262 | $fieldNames[] = 'profileID'; |
---|
| 263 | $fieldNames[] = 'organisationName'; |
---|
| 264 | $fieldNames[] = 'userDefinedAccounts'; |
---|
| 265 | |
---|
| 266 | return $this->soemailadmin->getProfile($_profileID, $fieldNames); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | function getProfileList($_profileID='') |
---|
| 270 | { |
---|
| 271 | $profileList = $this->soemailadmin->getProfileList($_profileID); |
---|
| 272 | return $profileList; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | # function getSMTPClass($_profileID) |
---|
| 276 | # { |
---|
| 277 | # if(!is_object($this->smtpClass)) |
---|
| 278 | # { |
---|
| 279 | # $profileData = $this->getProfile($_profileID); |
---|
| 280 | # $this->smtpClass = CreateObject('emailadmin.postfixldap',$profileData); |
---|
| 281 | # } |
---|
| 282 | # |
---|
| 283 | # return $this->smtpClass; |
---|
| 284 | # } |
---|
| 285 | |
---|
| 286 | function getSMTPServerTypes() |
---|
| 287 | { |
---|
| 288 | foreach($this->SMTPServerType as $key => $value) |
---|
| 289 | { |
---|
| 290 | $retData[$key] = $value['description']; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | return $retData; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | function getUserData($_accountID, $_usecache) |
---|
| 297 | { |
---|
| 298 | if ($_usecache) |
---|
| 299 | { |
---|
| 300 | $userData = $this->userSessionData[$_accountID]; |
---|
| 301 | } |
---|
| 302 | else |
---|
| 303 | { |
---|
| 304 | $userData = $this->soemailadmin->getUserData($_accountID); |
---|
| 305 | $bofelamimail = CreateObject('felamimail.bofelamimail'); |
---|
| 306 | $bofelamimail->openConnection('','',true); |
---|
| 307 | $userQuota = |
---|
| 308 | $bofelamimail->imapGetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID)); |
---|
| 309 | if(is_array($userQuota)) |
---|
| 310 | { |
---|
| 311 | $userData['quotaLimit'] = $userQuota['limit']; |
---|
| 312 | } |
---|
| 313 | $bofelamimail->closeConnection(); |
---|
| 314 | $this->userSessionData[$_accountID] = $userData; |
---|
| 315 | $this->saveSessionData(); |
---|
| 316 | } |
---|
| 317 | return $userData; |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | function restoreSessionData() |
---|
| 321 | { |
---|
| 322 | global $phpgw; |
---|
| 323 | |
---|
| 324 | $this->sessionData = $phpgw->session->appsession('session_data'); |
---|
| 325 | $this->userSessionData = $phpgw->session->appsession('user_session_data'); |
---|
| 326 | |
---|
| 327 | #while(list($key, $value) = each($this->userSessionData)) |
---|
| 328 | #{ |
---|
| 329 | # print "++ $key: $value<br>"; |
---|
| 330 | #} |
---|
| 331 | #print "restored Session<br>"; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings) |
---|
| 335 | { |
---|
| 336 | if(!isset($_globalSettings['profileID'])) |
---|
| 337 | { |
---|
| 338 | $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings); |
---|
| 339 | } |
---|
| 340 | else |
---|
| 341 | { |
---|
| 342 | $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | function saveSessionData() |
---|
| 347 | { |
---|
| 348 | global $phpgw; |
---|
| 349 | |
---|
| 350 | $phpgw->session->appsession('session_data','',$this->sessionData); |
---|
| 351 | $phpgw->session->appsession('user_session_data','',$this->userSessionData); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | function saveUserData($_accountID, $_formData, $_boAction) |
---|
| 355 | { |
---|
| 356 | $this->userSessionData[$_accountID]['mailLocalAddress'] = $_formData["mailLocalAddress"]; |
---|
| 357 | $this->userSessionData[$_accountID]['accountStatus'] = $_formData["accountStatus"]; |
---|
| 358 | $this->userSessionData[$_accountID]['deliveryMode'] = $_formData["deliveryMode"]; |
---|
| 359 | $this->userSessionData[$_accountID]['qmailDotMode'] = $_formData["qmailDotMode"]; |
---|
| 360 | $this->userSessionData[$_accountID]['deliveryProgramPath'] = $_formData["deliveryProgramPath"]; |
---|
| 361 | $this->userSessionData[$_accountID]['quotaLimit'] = $_formData["quotaLimit"]; |
---|
| 362 | |
---|
| 363 | switch ($_boAction) |
---|
| 364 | { |
---|
| 365 | case 'add_mailAlternateAddress': |
---|
| 366 | if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress'])) |
---|
| 367 | { |
---|
| 368 | $count = count($this->userSessionData[$_accountID]['mailAlternateAddress']); |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | $count = 0; |
---|
| 373 | $this->userSessionData[$_accountID]['mailAlternateAddress'] = array(); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | $this->userSessionData[$_accountID]['mailAlternateAddress'][$count] = |
---|
| 377 | $_formData['add_mailAlternateAddress']; |
---|
| 378 | |
---|
| 379 | $this->saveSessionData(); |
---|
| 380 | |
---|
| 381 | break; |
---|
| 382 | |
---|
| 383 | case 'remove_mailAlternateAddress': |
---|
| 384 | $i=0; |
---|
| 385 | |
---|
| 386 | while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress'])) |
---|
| 387 | { |
---|
| 388 | #print ".. $key: $value<br>"; |
---|
| 389 | if ($key != $_formData['remove_mailAlternateAddress']) |
---|
| 390 | { |
---|
| 391 | $newMailAlternateAddress[$i]=$value; |
---|
| 392 | #print "!! $i: $value<br>"; |
---|
| 393 | $i++; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | $this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress; |
---|
| 397 | |
---|
| 398 | $this->saveSessionData(); |
---|
| 399 | |
---|
| 400 | break; |
---|
| 401 | |
---|
| 402 | case 'add_mailRoutingAddress': |
---|
| 403 | if (is_array($this->userSessionData[$_accountID]['mailRoutingAddress'])) |
---|
| 404 | { |
---|
| 405 | $count = count($this->userSessionData[$_accountID]['mailRoutingAddress']); |
---|
| 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | $count = 0; |
---|
| 410 | $this->userSessionData[$_accountID]['mailRoutingAddress'] = array(); |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | $this->userSessionData[$_accountID]['mailRoutingAddress'][$count] = |
---|
| 414 | $_formData['add_mailRoutingAddress']; |
---|
| 415 | |
---|
| 416 | $this->saveSessionData(); |
---|
| 417 | |
---|
| 418 | break; |
---|
| 419 | |
---|
| 420 | case 'remove_mailRoutingAddress': |
---|
| 421 | $i=0; |
---|
| 422 | |
---|
| 423 | while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailRoutingAddress'])) |
---|
| 424 | { |
---|
| 425 | if ($key != $_formData['remove_mailRoutingAddress']) |
---|
| 426 | { |
---|
| 427 | $newMailRoutingAddress[$i]=$value; |
---|
| 428 | $i++; |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | $this->userSessionData[$_accountID]['mailRoutingAddress'] = $newMailRoutingAddress; |
---|
| 432 | |
---|
| 433 | $this->saveSessionData(); |
---|
| 434 | |
---|
| 435 | break; |
---|
| 436 | |
---|
| 437 | case 'save': |
---|
| 438 | $this->soemailadmin->saveUserData( |
---|
| 439 | $_accountID, |
---|
| 440 | $this->userSessionData[$_accountID]); |
---|
| 441 | $bofelamimail = CreateObject('felamimail.bofelamimail'); |
---|
| 442 | $bofelamimail->openConnection('','',true); |
---|
| 443 | $bofelamimail->imapSetQuota($GLOBALS['phpgw']->accounts->id2name($_accountID), |
---|
| 444 | $this->userSessionData[$_accountID]['quotaLimit']); |
---|
| 445 | $bofelamimail->closeConnection(); |
---|
| 446 | $GLOBALS['phpgw']->accounts->cache_invalidate($_accountID); |
---|
| 447 | |
---|
| 448 | |
---|
| 449 | break; |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | function updateAccount($_hookValues) |
---|
| 454 | { |
---|
| 455 | if (!empty($this->imapClass)) |
---|
| 456 | { |
---|
| 457 | ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | if (!empty($this->smtpClass)) |
---|
| 461 | { |
---|
| 462 | ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData); |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | } |
---|
| 467 | ?> |
---|