[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 /* $Id: class.bo.inc.php 21720 2006-06-06 10:24:49Z lkneschke $ */ 14 15 class bo 16 { 17 var $sessionData; 18 var $LDAPData; 19 20 var $SMTPServerType = array(); // holds a list of config options 21 22 var $imapClass; // holds the imap/pop3 class 23 var $smtpClass; // holds the smtp class 24 25 function bo($_profileID=-1,$_restoreSesssion=true) 26 { 27 $this->soemailadmin =& CreateObject('emailadmin.so'); 28 29 $this->SMTPServerType = array( 30 '1' => array( 31 'fieldNames' => array( 32 'smtpServer', 33 'smtpPort', 34 'smtpAuth', 35 'smtpType' 36 ), 37 'description' => lang('standard SMTP-Server'), 38 'classname' => 'defaultsmtp' 39 ), 40 '2' => array( 41 'fieldNames' => array( 42 'smtpServer', 43 'smtpPort', 44 'smtpAuth', 45 'smtpType', 46 'editforwardingaddress', 47 'smtpLDAPServer', 48 'smtpLDAPAdminDN', 49 'smtpLDAPAdminPW', 50 'smtpLDAPBaseDN', 51 'smtpLDAPUseDefault' 52 ), 53 'description' => lang('Postfix with LDAP'), 54 'classname' => 'postfixldap' 55 ) 56 ); 57 58 $this->IMAPServerType = array( 59 '1' => array( 60 'fieldNames' => array( 61 'imapServer', 62 'imapPort', 63 'imapType', 64 'imapLoginType', 65 'imapTLSEncryption', 66 'imapTLSAuthentication', 67 'imapoldcclient' 68 ), 69 'description' => lang('standard POP3 server'), 70 'protocol' => 'pop3', 71 'classname' => 'defaultpop' 72 ), 73 '2' => array( 74 'fieldNames' => array( 75 'imapServer', 76 'imapPort', 77 'imapType', 78 'imapLoginType', 79 'imapTLSEncryption', 80 'imapTLSAuthentication', 81 'imapoldcclient' 82 ), 83 'description' => lang('standard IMAP server'), 84 'protocol' => 'imap', 85 'classname' => 'defaultimap' 86 ), 87 '3' => array( 88 'fieldNames' => array( 89 'imapServer', 90 'imapPort', 91 'imapType', 92 'imapLoginType', 93 'imapTLSEncryption', 94 'imapTLSAuthentication', 95 'imapoldcclient', 96 'imapEnableCyrusAdmin', 97 'imapAdminUsername', 98 'imapAdminPW', 99 'imapEnableSieve', 100 'imapSieveServer', 101 'imapSievePort' 102 ), 103 'description' => lang('Cyrus IMAP Server'), 104 'protocol' => 'imap', 105 'classname' => 'cyrusimap' 106 ) 107 ); 108 109 if ($_restoreSesssion) $this->restoreSessionData(); 110 111 if($_profileID >= 0) 112 { 113 $this->profileID = $_profileID; 114 115 $this->profileData = $this->getProfile($_profileID); 116 117 $this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname']; 118 $this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname']; 119 } 120 } 121 122 function addAccount($_hookValues) 123 { 124 $this->profileData = $this->getUserProfile('felamimail', $_hookValues['account_groups']); 125 126 $this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname']; 127 $this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname']; 128 129 130 if (!empty($this->imapClass)) 131 { 132 ExecMethod("emailadmin.".$this->imapClass.".addAccount",$_hookValues,3,$this->profileData); 133 } 134 135 if (!empty($this->smtpClass)) 136 { 137 ExecMethod("emailadmin.".$this->smtpClass.".addAccount",$_hookValues,3,$this->profileData); 138 } 139 } 140 141 function deleteAccount($_hookValues) 142 { 143 $this->profileData = $this->getUserProfile('felamimail', $_hookValues['account_groups']); 144 145 $this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname']; 146 $this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname']; 147 148 if (!empty($this->imapClass)) 149 { 150 ExecMethod("emailadmin.".$this->imapClass.".deleteAccount",$_hookValues,3,$this->profileData); 151 } 152 153 if (!empty($this->smtpClass)) 154 { 155 ExecMethod("emailadmin.".$this->smtpClass.".deleteAccount",$_hookValues,3,$this->profileData); 156 } 157 } 158 159 function deleteProfile($_profileID) 160 { 161 $this->soemailadmin->deleteProfile($_profileID); 162 } 163 164 function encodeHeader($_string, $_encoding='q') 165 { 166 switch($_encoding) 167 { 168 case "q": 169 if(!preg_match("/[\x80-\xFF]/",$_string)) 170 { 171 // nothing to quote, only 7 bit ascii 172 return $_string; 173 } 174 175 $string = imap_8bit($_string); 176 $stringParts = explode("=\r\n",$string); 177 while(list($key,$value) = each($stringParts)) 178 { 179 if(!empty($retString)) $retString .= " "; 180 $value = str_replace(" ","_",$value); 181 // imap_8bit does not convert "?" 182 // it does not need, but it should 183 $value = str_replace("?","=3F",$value); 184 $retString .= "=?".strtoupper($this->displayCharset)."?Q?".$value."?="; 185 } 186 #exit; 187 return $retString; 188 break; 189 default: 190 return $_string; 191 } 192 } 193 194 function getAccountEmailAddress($_accountName, $_profileID) 195 { 196 $profileData = $this->getProfile($_profileID); 197 198 $smtpClass = $this->SMTPServerType[$profileData['smtpType']]['classname']; 199 200 return empty($smtpClass) ? False : ExecMethod("emailadmin.$smtpClass.getAccountEmailAddress",$_accountName,3,$profileData); 201 } 202 203 function getFieldNames($_serverTypeID, $_class) 204 { 205 switch($_class) 206 { 207 case 'imap': 208 return $this->IMAPServerType[$_serverTypeID]['fieldNames']; 209 break; 210 case 'smtp': 211 return $this->SMTPServerType[$_serverTypeID]['fieldNames']; 212 break; 213 } 214 } 215 216 # function getIMAPClass($_profileID) 217 # { 218 # if(!is_object($this->imapClass)) 219 # { 220 # $profileData = $this->getProfile($_profileID); 221 # $this->imapClass =& CreateObject('emailadmin.cyrusimap',$profileData); 222 # } 223 # 224 # return $this->imapClass; 225 # } 226 227 function getIMAPServerTypes() 228 { 229 foreach($this->IMAPServerType as $key => $value) 230 { 231 $retData[$key]['description'] = $value['description']; 232 $retData[$key]['protocol'] = $value['protocol']; 233 } 234 235 return $retData; 236 } 237 238 function getLDAPStorageData($_serverid) 239 { 240 $storageData = $this->soemailadmin->getLDAPStorageData($_serverid); 241 return $storageData; 242 } 243 244 function getMailboxString($_folderName) 245 { 246 if (!empty($this->imapClass)) 247 { 248 return ExecMethod("emailadmin.".$this->imapClass.".getMailboxString",$_folderName,3,$this->profileData); 249 } 250 else 251 { 252 return false; 253 } 254 } 255 256 function getProfile($_profileID) 257 { 258 $profileData = $this->soemailadmin->getProfileList($_profileID); 259 $found = false; 260 if (is_array($profileData) && count($profileData)) 261 { 262 foreach($profileData as $n => $data) 263 { 264 if ($data['ProfileID'] == $_profileID) 265 { 266 $found = $n; 267 break; 268 } 269 } 270 } 271 if ($found === false) // no existing profile selected 272 { 273 if (is_array($profileData) && count($profileData)) // if we have a profile use that 274 { 275 reset($profileData); 276 list($found,$data) = each($profileData); 277 $this->profileID = $_profileID = $data['profileID']; 278 } 279 elseif ($GLOBALS['egw_info']['server']['smtp_server']) // create a default profile, from the data in the api config 280 { 281 $this->profileID = $_profileID = $this->soemailadmin->addProfile(array( 282 'description' => $GLOBALS['egw_info']['server']['smtp_server'], 283 'defaultDomain' => $GLOBALS['egw_info']['server']['mail_suffix'], 284 'organisationName' => '', 285 'userDefinedAccounts' => '', 286 ),array( 287 'smtpServer' => $GLOBALS['egw_info']['server']['smtp_server'], 288 'smtpPort' => $GLOBALS['egw_info']['server']['smtp_port'], 289 'smtpAuth' => '', 290 'smtpType' => '1', 291 ),array( 292 'imapServer' => $GLOBALS['egw_info']['server']['mail_server'] ? 293 $GLOBALS['egw_info']['server']['mail_server'] : $GLOBALS['egw_info']['server']['smtp_server'], 294 'imapPort' => '143', 295 'imapType' => '2', // imap 296 'imapLoginType' => $GLOBALS['egw_info']['server']['mail_login_type'] ? 297 $GLOBALS['egw_info']['server']['mail_login_type'] : 'standard', 298 'imapTLSEncryption' => '', 299 'imapTLSAuthentication' => '', 300 'imapoldcclient' => '', 301 )); 302 $profileData[$found = 0] = array( 303 'smtpType' => '1', 304 'imapType' => '2', 305 ); 306 } 307 } 308 $fieldNames = array(); 309 if (isset($profileData[$found])) 310 { 311 $fieldNames = array_merge($this->SMTPServerType[$profileData[$found]['smtpType']]['fieldNames'], 312 $this->IMAPServerType[$profileData[$found]['imapType']]['fieldNames']); 313 } 314 $fieldNames[] = 'description'; 315 $fieldNames[] = 'defaultDomain'; 316 $fieldNames[] = 'profileID'; 317 $fieldNames[] = 'organisationName'; 318 $fieldNames[] = 'userDefinedAccounts'; 319 $fieldNames[] = 'ea_appname'; 320 $fieldNames[] = 'ea_group'; 321 322 return $this->soemailadmin->getProfile($_profileID, $fieldNames); 323 } 324 325 function getProfileList($_profileID='') 326 { 327 return $this->soemailadmin->getProfileList($_profileID); 328 } 329 330 # function getSMTPClass($_profileID) 331 # { 332 # if(!is_object($this->smtpClass)) 333 # { 334 # $profileData = $this->getProfile($_profileID); 335 # $this->smtpClass =& CreateObject('emailadmin.postfixldap',$profileData); 336 # } 337 # 338 # return $this->smtpClass; 339 # } 340 341 function getSMTPServerTypes() 342 { 343 foreach($this->SMTPServerType as $key => $value) 344 { 345 $retData[$key] = $value['description']; 346 } 347 348 return $retData; 349 } 350 351 function getUserProfile($_appName='', $_groups='') 352 { 353 $appName = ($_appName != '' ? $_appName : $GLOBALS['egw_info']['flags']['currentapp']); 354 if(!is_array($_groups)) 355 { 356 // initialize with 0 => means no group id 357 $groups = array(0); 358 $userGroups = $GLOBALS['egw']->accounts->membership($GLOBALS['egw_info']['user']['account_id']); 359 foreach((array)$userGroups as $groupInfo) 360 { 361 $groups[] = $groupInfo['account_id']; 362 } 363 } 364 else 365 { 366 $groups = $_groups; 367 } 368 369 return $this->soemailadmin->getUserProfile($appName, $groups); 370 } 371 372 function getUserData($_accountID, $_usecache) 373 { 374 if ($_usecache) 375 { 376 $userData = $this->userSessionData[$_accountID]; 377 } 378 else 379 { 380 $userData = $this->soemailadmin->getUserData($_accountID); 381 $bofelamimail =& CreateObject('felamimail.bofelamimail'); 382 $bofelamimail->openConnection('','',true); 383 $userQuota = 384 $bofelamimail->imapGetQuota($GLOBALS['egw']->accounts->id2name($_accountID)); 385 if(is_array($userQuota)) 386 { 387 $userData['quotaLimit'] = $userQuota['limit']; 388 } 389 $bofelamimail->closeConnection(); 390 $this->userSessionData[$_accountID] = $userData; 391 $this->saveSessionData(); 392 } 393 return $userData; 394 } 395 396 function restoreSessionData() 397 { 398 $this->sessionData = $GLOBALS['egw']->session->appsession('session_data'); 399 $this->userSessionData = $GLOBALS['egw']->session->appsession('user_session_data'); 400 } 401 402 function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy) 403 { 404 if (!empty($this->smtpClass)) 405 { 406 $smtpClass = &CreateObject('emailadmin.'.$this->smtpClass,$this->profileID); 407 $smtpClass->saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy); 408 } 409 410 } 411 412 /** 413 * called by the validation hook in setup 414 * 415 * @param array $settings following keys: mail_server, mail_server_type {IMAP|IMAPS|POP-3|POP-3S}, 416 * mail_login_type {standard|vmailmgr}, mail_suffix (domain), smtp_server, smtp_port, smtp_auth_user, smtp_auth_passwd 417 */ 418 function setDefaultProfile($settings) 419 { 420 if (($profiles = $this->soemailadmin->getProfileList(0,true))) 421 { 422 $profile = array_shift($profiles); 423 } 424 else 425 { 426 $profile = array( 427 'smtpType' => 1, 428 'description' => 'default profile (created by setup)', 429 'ea_appname' => '', 430 'ea_group' => 0, 431 ); 432 } 433 foreach(array( 434 'mail_server' => 'imapServer', 435 'mail_server_type' => array( 436 'imap' => array( 437 'imapType' => 2, 438 'imapPort' => 143, 439 'imapTLSEncryption' => null, 440 ), 441 'imaps' => array( 442 'imapType' => 2, 443 'imapPort' => 993, 444 'imapTLSEncryption' => 'yes', 445 ), 446 'pop3' => array( 447 'imapType' => 1, 448 'imapPort' => 110, 449 'imapTLSEncryption' => null, 450 ), 451 'pop3s' => array( 452 'imapType' => 1, 453 'imapPort' => 995, 454 'imapTLSEncryption' => 'yes', 455 ), 456 ), 457 'mail_login_type' => 'imapLoginType', 458 'mail_suffix' => 'defaultDomain', 459 'smtp_server' => 'smtpServer', 460 'smtp_port' => 'smtpPort', 461 ) as $setup_name => $ea_name_data) 462 { 463 if (!is_array($ea_name_data)) 464 { 465 $profile[$ea_name_data] = $settings[$setup_name]; 466 } 467 else 468 { 469 foreach($ea_name_data as $setup_val => $ea_data) 470 { 471 if ($setup_val == $settings[$setup_name]) 472 { 473 foreach($ea_data as $var => $val) 474 { 475 if ($var != 'imapType' || $val != 2 || $profile[$var] < 3) // dont kill special imap server types 476 { 477 $profile[$var] = $val; 478 } 479 } 480 break; 481 } 482 } 483 } 484 } 485 $this->soemailadmin->updateProfile($profile); 486 //echo "<p>EMailAdmin profile update: ".print_r($profile,true)."</p>\n"; exit; 487 } 488 489 function saveProfile($_globalSettings, $_smtpSettings, $_imapSettings) 490 { 491 if(!isset($_globalSettings['profileID'])) 492 { 493 $_globalSettings['ea_order'] = count($this->getProfileList()) + 1; 494 $this->soemailadmin->addProfile($_globalSettings, $_smtpSettings, $_imapSettings); 495 } 496 else 497 { 498 $this->soemailadmin->updateProfile($_globalSettings, $_smtpSettings, $_imapSettings); 499 } 500 $all = $_globalSettings+$_smtpSettings+$_imapSettings; 501 if (!$all['ea_group'] && !$all['ea_application']) // standard profile update eGW config 502 { 503 $new_config = array(); 504 foreach(array( 505 'imapServer' => 'mail_server', 506 'imapType' => 'mail_server_type', 507 'imapLoginType' => 'mail_login_type', 508 'defaultDomain' => 'mail_suffix', 509 'smtpServer' => 'smtp_server', 510 'smtpPort' => 'smtp_port', 511 ) as $ea_name => $config_name) 512 { 513 if (isset($all[$ea_name])) 514 { 515 if ($ea_name != 'imapType') 516 { 517 $new_config[$config_name] = $all[$ea_name]; 518 } 519 else // imap type 520 { 521 $new_config[$config_name] = ($all['imapType'] == 1 ? 'pop3' : 'imap').($all['imapTLSEncryption'] ? 's' : ''); 522 } 523 } 524 } 525 if (count($new_config)) 526 { 527 $config =& CreateObject('phpgwapi.config','phpgwapi'); 528 529 foreach($new_config as $name => $value) 530 { 531 $config->save_value($name,$value,'phpgwapi'); 532 } 533 //echo "<p>eGW configuration update: ".print_r($new_config,true)."</p>\n"; 534 } 535 } 536 } 537 538 function saveSessionData() 539 { 540 $GLOBALS['egw']->session->appsession('session_data','',$this->sessionData); 541 $GLOBALS['egw']->session->appsession('user_session_data','',$this->userSessionData); 542 } 543 544 function saveUserData($_accountID, $_formData, $_boAction) 545 { 546 $this->userSessionData[$_accountID]['mailLocalAddress'] = $_formData["mailLocalAddress"]; 547 $this->userSessionData[$_accountID]['accountStatus'] = $_formData["accountStatus"]; 548 $this->userSessionData[$_accountID]['deliveryMode'] = $_formData["deliveryMode"]; 549 $this->userSessionData[$_accountID]['qmailDotMode'] = $_formData["qmailDotMode"]; 550 $this->userSessionData[$_accountID]['deliveryProgramPath'] = $_formData["deliveryProgramPath"]; 551 $this->userSessionData[$_accountID]['quotaLimit'] = $_formData["quotaLimit"]; 552 553 switch ($_boAction) 554 { 555 case 'add_mailAlternateAddress': 556 if (is_array($this->userSessionData[$_accountID]['mailAlternateAddress'])) 557 { 558 $count = count($this->userSessionData[$_accountID]['mailAlternateAddress']); 559 } 560 else 561 { 562 $count = 0; 563 $this->userSessionData[$_accountID]['mailAlternateAddress'] = array(); 564 } 565 566 $this->userSessionData[$_accountID]['mailAlternateAddress'][$count] = 567 $_formData['add_mailAlternateAddress']; 568 569 $this->saveSessionData(); 570 571 break; 572 573 case 'remove_mailAlternateAddress': 574 $i=0; 575 576 while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailAlternateAddress'])) 577 { 578 #print ".. $key: $value<br>"; 579 if ($key != $_formData['remove_mailAlternateAddress']) 580 { 581 $newMailAlternateAddress[$i]=$value; 582 #print "!! $i: $value<br>"; 583 $i++; 584 } 585 } 586 $this->userSessionData[$_accountID]['mailAlternateAddress'] = $newMailAlternateAddress; 587 588 $this->saveSessionData(); 589 590 break; 591 592 case 'add_mailRoutingAddress': 593 if (is_array($this->userSessionData[$_accountID]['mailRoutingAddress'])) 594 { 595 $count = count($this->userSessionData[$_accountID]['mailRoutingAddress']); 596 } 597 else 598 { 599 $count = 0; 600 $this->userSessionData[$_accountID]['mailRoutingAddress'] = array(); 601 } 602 603 $this->userSessionData[$_accountID]['mailRoutingAddress'][$count] = 604 $_formData['add_mailRoutingAddress']; 605 606 $this->saveSessionData(); 607 608 break; 609 610 case 'remove_mailRoutingAddress': 611 $i=0; 612 613 while(list($key, $value) = @each($this->userSessionData[$_accountID]['mailRoutingAddress'])) 614 { 615 if ($key != $_formData['remove_mailRoutingAddress']) 616 { 617 $newMailRoutingAddress[$i]=$value; 618 $i++; 619 } 620 } 621 $this->userSessionData[$_accountID]['mailRoutingAddress'] = $newMailRoutingAddress; 622 623 $this->saveSessionData(); 624 625 break; 626 627 case 'save': 628 $this->soemailadmin->saveUserData( 629 $_accountID, 630 $this->userSessionData[$_accountID]); 631 $bofelamimail =& CreateObject('felamimail.bofelamimail'); 632 $bofelamimail->openConnection('','',true); 633 $bofelamimail->imapSetQuota($GLOBALS['egw']->accounts->id2name($_accountID), 634 $this->userSessionData[$_accountID]['quotaLimit']); 635 $bofelamimail->closeConnection(); 636 $GLOBALS['egw']->accounts->cache_invalidate($_accountID); 637 638 639 break; 640 } 641 } 642 643 function setOrder($_order) 644 { 645 if(is_array($_order)) { 646 $this->soemailadmin->setOrder($_order); 647 } 648 } 649 650 function updateAccount($_hookValues) 651 { 652 $this->profileData = $this->getUserProfile('felamimail', $_hookValues['account_groups']); 653 654 $this->imapClass = $this->IMAPServerType[$this->profileData['imapType']]['classname']; 655 $this->smtpClass = $this->SMTPServerType[$this->profileData['smtpType']]['classname']; 656 657 if (!empty($this->imapClass)) 658 { 659 ExecMethod("emailadmin.".$this->imapClass.".updateAccount",$_hookValues,3,$this->profileData); 660 } 661 662 if (!empty($this->smtpClass)) 663 { 664 ExecMethod("emailadmin.".$this->smtpClass.".updateAccount",$_hookValues,3,$this->profileData); 665 } 666 } 667 668 } 669 ?>
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 |