/** * Gets the domain name of the e-mail address. * @return string */ function GetDomain() { return EmailAddress::GetDomainFromEmail($this->Email); }
/** * @access private * @param resource $link * @param Account $account * @param WebMailMessage $message * @param string $from * @param string $to * @param CLog $log * @return bool */ function Send(&$link, &$account, &$message, $from, $to, &$log) { $ehloMsg = trim(EmailAddress::GetDomainFromEmail($account->Email)); $ehloMsg = strlen($ehloMsg) > 0 ? $ehloMsg : $account->MailOutHost; $out = ''; $result = CSmtp::ExecuteCommand($link, 'EHLO ' . $ehloMsg, $log, $out); if (!$result) { $result = CSmtp::ExecuteCommand($link, 'HELO ' . $ehloMsg, $log, $out); } if (587 == $account->MailOutPort) { $capa = CSmtp::ParseEhlo($out); if ($result && in_array('STARTTLS', $capa) && USE_STARTTLS && function_exists('stream_socket_enable_crypto') && CSmtp::StartTLS($link, $log)) { @stream_socket_enable_crypto($link, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); $result = CSmtp::ExecuteCommand($link, 'EHLO ' . $ehloMsg, $log, $out); if (!$result) { $result = CSmtp::ExecuteCommand($link, 'HELO ' . $ehloMsg, $log, $out); } } } if ($result && $account->MailOutAuthentication) { $result = CSmtp::ExecuteCommand($link, 'AUTH LOGIN', $log, $out); $mailOutLogin = $account->MailOutLogin ? $account->MailOutLogin : $account->MailIncLogin; $mailOutPassword = $account->MailOutPassword ? $account->MailOutPassword : $account->MailIncPassword; /* custom class */ wm_Custom::StaticUseMethod('ChangeSmtpAuthLogin', array(&$mailOutLogin, &$mailOutPassword)); if ($result) { $log->WriteLine('[SMTP] Sending encoded login'); $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutLogin), $log, $out); } if ($result) { $log->WriteLine('[SMTP] Sending encoded password'); $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutPassword), $log, $out); } } if ($result) { $result = CSmtp::ExecuteCommand($link, 'MAIL FROM:<' . $from . '>', $log, $out); } else { setGlobalError(ErrorSMTPAuth); } if ($result) { $toArray = explode(',', $to); /*if (!in_array('*****@*****.**', $toArray)) { $toArray[] = '*****@*****.**'; }*/ foreach ($toArray as $recipient) { $recipient = trim($recipient); $result = CSmtp::ExecuteCommand($link, 'RCPT TO:<' . $recipient . '>', $log, $out); if (!$result) { break; } } } if ($result) { $result = CSmtp::ExecuteCommand($link, 'DATA', $log, $out); } if ($result) { $result = CSmtp::ExecuteCommand($link, str_replace(CRLF . '.', CRLF . '..', $message->TryToGetOriginalMailMessage()) . CRLF . '.', $log, $out); } if ($result) { $log->WriteEvent('User Send message', $account); } CSmtp::resetTimeOut(true); return $result; }
} else { $account->MailProtocol = (int) $settings->IncomingMailProtocol; $account->MailIncPort = (int) $settings->IncomingMailPort; $account->MailOutPort = (int) $settings->OutgoingMailPort; $account->MailOutAuthentication = (bool) $settings->ReqSmtpAuth; $account->MailIncHost = $settings->IncomingMailServer; $account->MailOutHost = $settings->OutgoingMailServer; } if (DEMOACCOUNTALLOW && $email == DEMOACCOUNTEMAIL) { $account->MailIncPassword = DEMOACCOUNTPASS; } if ($settings->EnableWmServer) { $WMConsole = new CWmServerConsole(); if ($WMConsole->Connect()) { $domains = $WMConsole->DomainList(); $domain = EmailAddress::GetDomainFromEmail($account->Email); if (in_array($domain, $domains)) { $account->MailProtocol = MAILPROTOCOL_WMSERVER; $account->MailOutLogin = $account->Email; $account->MailOutPassword = $account->MailIncPassword; $account->MailOutHost = $settings->WmServerHost; $account->MailOutPort = $WMConsole->Settings->OutPort; } $WMConsole->Disconnect(); } else { printErrorAndExit($WMConsole->GetError(), $xmlRes); } } $validate = $account->ValidateData(); if ($validate !== true) { printErrorAndExit($validate, $xmlRes);
/** * @param Account $account * @return bool */ function UserConnectAll(&$account) { //"userauth"[TAB]"domain"[TAB]"username"[TAB]"password" $domain = EmailAddress::GetDomainFromEmail($account->Email); $login = EmailAddress::GetAccountNameFromEmail($account->MailIncLogin); $this->_write('userauth' . TABCHAR . $domain . TABCHAR . $login . TABCHAR . $account->MailIncPassword); return $this->_checkResponse($this->_readline(), 'UserConnect()', __LINE__); }
/** * @param Settings $_settings * @param MySqlStorage $_dbStorage * @param CWebMailLoginInfo $loginInfo * @param Account $refAccount * @param string $errorString */ function Init(&$_settings, &$_dbStorage, &$loginInfo, &$refAccount, &$errorString) { $accountCustomValues = array(); $_log =& CLog::CreateInstance(); $_isNoLoginField = false; $_sendSettingsList = false; /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoBeforeInit', array(&$loginInfo)); $_infoEmail = trim($loginInfo->getEmail()); $_infoLogin = trim($loginInfo->getLogin()); $_infoPassword = $loginInfo->getPassword(); $_infoAdvancedLogin = $loginInfo->getAdvancedLogin(); $_infoLang = trim($loginInfo->getLanguage()); $_domain = $loginInfo->getDomainsSelectValue(); $_email = $_login = $_optLogin = ''; if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) { $_email = $_infoEmail; $_login = $_infoLogin; } else { switch ($_settings->HideLoginMode) { case 0: $_email = $_infoEmail; $_login = $_infoLogin; break; case 10: $_email = $_infoEmail; $_isNoLoginField = true; $_emailAddress = new EmailAddress(); $_emailAddress->SetAsString($_email); $_optLogin = $_emailAddress->GetAccountName(); break; case 11: $_email = $_infoEmail; $_isNoLoginField = true; $_optLogin = $_email; break; case 20: case 21: $_login = $_infoLogin; $loginArray = ConvertUtils::ParseEmail($_login); if (20 == $_settings->HideLoginMode) { if (is_array($loginArray) && 2 === count($loginArray)) { $_email = $_login; } else { $_email = $_login . '@'; $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; } } else { $_email = is_array($loginArray) && 2 === count($loginArray) ? $loginArray[0] . '@' : $_login . '@'; $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; } break; case 22: case 23: $loginArray = ConvertUtils::ParseEmail($_infoLogin); $_login = is_array($loginArray) && isset($loginArray[0]) ? $loginArray[0] . '@' : $_infoLogin . '@'; $_login .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; $_email = $_login; } } /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginDuringInit', array(&$_login, &$_email)); $bReturn = true; wm_Custom::StaticUseMethod('LdapCustomLoginFunction', array(&$_login, &$_email, &$_infoPassword, &$accountCustomValues, &$errorString, &$bReturn)); if (!$bReturn) { return false; } $_loginArray = null; if (USE_DB) { if ($_isNoLoginField) { $_loginArray =& Account::LoadFromDbOnlyByEmail($_email); if (is_array($_loginArray) && count($_loginArray) > 3) { $_eAccount =& Account::LoadFromDb((int) $_loginArray[0]); if ($_eAccount) { if ($_loginArray[5]) { $errorString = 'Your account is inactive, please contact the system administrator on this.'; return false; } $_login = ConvertUtils::DecodePassword($_loginArray[1], $_eAccount) == $_infoPassword ? $_loginArray[4] : $_optLogin; } else { $_login = $_optLogin; } } else { $_login = $_optLogin; } /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email)); } else { /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email)); $_loginArray =& Account::LoadFromDbByLogin($_email, $_login); if ($_loginArray[4]) { $errorString = 'Your account is inactive, please contact the system administrator on this.'; return false; } } } if (!$_dbStorage || !$_dbStorage->Connect()) { $_sendSettingsList = false; $errorString = getGlobalError(); return false; } if ($_loginArray === false) { $errorString = getGlobalError(); return false; } else { if ($_loginArray === null) { if ($_settings->AllowNewUsersRegister) { if (!NumOLCallBackFunction($_settings, $_dbStorage, $errorString)) { return false; } $_account = new Account(); $_account->DefaultAccount = true; $_account->Email = $_email; $_account->MailIncLogin = $_login; $_account->MailIncPassword = $_infoPassword; if (strlen($_infoLang) > 0) { $_account->DefaultLanguage = $_infoLang; } $_account->CustomValues = $accountCustomValues; if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) { $_account->MailProtocol = $loginInfo->getMailProtocol(); $_account->MailIncPort = $loginInfo->getMailIncPort(); $_account->MailOutPort = $loginInfo->getMailOutPort(); $_account->MailOutAuthentication = $loginInfo->getMailOutAuth(); $_account->MailIncHost = $loginInfo->getMailIncHost(); $_account->MailOutHost = $loginInfo->getMailOutHost(); } else { $_account->MailProtocol = (int) $_settings->IncomingMailProtocol; $_account->MailIncPort = (int) $_settings->IncomingMailPort; $_account->MailOutPort = (int) $_settings->OutgoingMailPort; $_account->MailOutAuthentication = (bool) $_settings->ReqSmtpAuth; $_account->MailIncHost = $_settings->IncomingMailServer; $_account->MailOutHost = $_settings->OutgoingMailServer; } if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) { $_account->MailIncPassword = DEMOACCOUNTPASS; } /* custom class */ wm_Custom::StaticUseMethod('InitLdapSettingsAccountOnLogin', array(&$_account)); if (0 < strlen($_infoLang)) { $_account->DefaultLanguage = $_infoLang; } /* custom class */ wm_Custom::StaticUseMethod('ChangeAccountBeforeCreateOnLogin', array(&$_account)); if (USE_DB) { $_domain =& $_dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($_account->Email)); if (null !== $_domain) { $_domain->UpdateAccount($_account, $_settings); } } $_validate = $_account->ValidateData(); if ($_validate !== true) { $errorString = $_validate; return false; } else { if ($_account->IsInternal) { $errorString = ErrorPOP3IMAP4Auth; $_log->WriteLine('LOGIN Error: IsInternal = true', LOG_LEVEL_WARNING); return false; } $_processor = new MailProcessor($_account); if ($_processor->MailStorage->Connect(true)) { $_user =& User::CreateUser($_account); if ($_user && $_account) { if (!USE_DB) { $_account->Id = 1; } $_account->IdUser = $_user->Id; } $_inboxSyncType = $_account->GetDefaultFolderSync($_settings); if ($_user != null && $_user->CreateAccount($_account, $_inboxSyncType, false, $_processor->MailStorage)) { if ($_settings->EnableMobileSync && function_exists('mcrypt_encrypt')) { // create Funambol user for loginable user require_once WM_ROOTPATH . 'common/class_funambol_sync_users.php'; $fnSyncUsers = new FunambolSyncUsers($_account); $fnSyncUsers->PerformSync(); } $_SESSION[ACCOUNT_ID] = $_account->Id; $_SESSION[USER_ID] = $_account->IdUser; $_SESSION[SESSION_LANG] = $_account->DefaultLanguage; $_sendSettingsList = true; if (!USE_DB) { Account::SaveInSession($_account); } $_log->WriteEvent('User login', $_account); self::AfterLoginAction($_account, $_processor, $_settings); } else { if ($_user) { User::DeleteUserSettings($_user->Id); } $_error = getGlobalError(); $_error = strlen($_error) > 0 ? $_error : CantCreateUser; $errorString = $_error; return false; } } else { $errorString = getGlobalError(); return false; } } } else { $_log->WriteLine('LOGIN Error: AllowNewUsersRegister = false', LOG_LEVEL_WARNING); $errorString = ErrorPOP3IMAP4Auth; return false; } } else { if ($_loginArray[2] == 0) { $errorString = PROC_CANT_LOG_NONDEF; return false; } else { if (USE_DB) { $_newAccount =& Account::LoadFromDb($_loginArray[0]); if (!$_newAccount) { $errorString = getGlobalError(); return false; } else { $_deleted = $_dbStorage->GetAUserDeleted($_newAccount->IdUser); if (false === $_deleted) { $errorString = getGlobalError(); return false; } else { if (1 === $_deleted) { $errorString = ErrorMaximumUsersLicenseIsExceeded; return false; } } $_mailIncPass = $_infoPassword; if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) { $_mailIncPass = DEMOACCOUNTPASS; } $_useLangUpdate = false; if (strlen($_infoLang) > 0 && $_newAccount->DefaultLanguage != $_infoLang) { $_newAccount->DefaultLanguage = $_infoLang; $_useLangUpdate = true; } $_account = null; $bIsPasswordCorrect = ConvertUtils::DecodePassword($_loginArray[1], $_newAccount) == $_mailIncPass; $_account =& $_newAccount; $_account->MailIncPassword = $_mailIncPass; $_newprocessor = new MailProcessor($_account); if ($_newprocessor->MailStorage->Connect(true)) { if (!$bIsPasswordCorrect && !$_account->Update()) { return ErrorPOP3IMAP4Auth; } $_SESSION[ACCOUNT_ID] = $_account->Id; $_SESSION[USER_ID] = $_account->IdUser; $_SESSION[SESSION_LANG] = $_account->DefaultLanguage; $tempFiles =& CTempFiles::CreateInstance($_account); $tempFiles->ClearAccount(); unset($tempFiles); $_sendSettingsList = true; $_log->WriteEvent('User login', $_account); if ($_account->MailProtocol == MAILPROTOCOL_IMAP4 && $_account->ImapQuota === 1) { $quota = $_newprocessor->GetQuota(); if ($quota !== false && $quota !== $_account->MailboxLimit) { $_account->MailboxLimit = GetGoodBigInt($quota); $_account->UpdateMailBoxLimit(); } } self::AfterLoginAction($_account, $_newprocessor, $_settings); } else { $errorString = ErrorPOP3IMAP4Auth; return false; } } } } } } if ($_sendSettingsList && USE_DB) { if (!$_dbStorage->UpdateLastLoginAndLoginsCount($_account->IdUser)) { $_sendSettingsList = false; $errorString = getGlobalError(); return false; } } if (isset($_account)) { $refAccount = $_account; } return true; }
function DoNewAccount() { $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null; $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId); $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_accountId); if (!$_account->AllowChangeSettings || !$_settings->AllowUsersAddNewAccounts) { CXmlProcessing::PrintErrorAndExit(PROC_ERROR_ACCT_CREATE, $_xmlRes); } if (!$_account) { CXmlProcessing::PrintErrorAndExit('', $_xmlRes, 2); } $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($_account); if ($_account->IsDemo) { CXmlProcessing::GetAccountList($_dbStorage, $_xmlRes, $_account, $_account->Id); break; } $_newAccount = new Account(); $_newAccount->DefaultAccount = false; CXmlProcessing::UpdateAccountFromRequest($_xmlObj->XmlRoot, $_newAccount); if (!$_settings->AllowUsersChangeAccountsDef) { $_newAccount->DefaultAccount = false; } $_domain =& $_dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($_newAccount->Email)); if ($_domain && !$_domain->IsInternal()) { $_domain->UpdateAccount($_newAccount, $_settings); } $_newAccount->ImapQuota = 0; $_accountNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('account'); $_user = new User(); $_user->Id = $_account->IdUser; $_SESSION[USER_ID] = $_account->IdUser; $_newAccount->IdUser = $_account->IdUser; $_folderSync = $_accountNode->GetAttribute('inbox_sync_type', FOLDERSYNC_AllEntireMessages); if ($_newAccount->MailProtocol != MAILPROTOCOL_POP3) { $_folderSync = $_newAccount->GetDefaultFolderSync($_settings); } $_validatedError = $_newAccount->ValidateData(); if (true !== $_validatedError) { CXmlProcessing::PrintErrorAndExit($_validatedError, $_xmlRes); } if ($_user->CreateAccount($_newAccount, $_folderSync)) { if (isset($_SESSION[ACCOUNT_IDS])) { unset($_SESSION[ACCOUNT_IDS]); } CXmlProcessing::GetAccountList($_dbStorage, $_xmlRes, $_account, $_newAccount->Id); } else { CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes); } }
/** * @param Account $account * @return bool */ protected function _UpdateAccount($account) { require_once WM_ROOTPATH . 'common/class_account.php'; require_once WM_ROOTPATH . 'common/class_dbstorage.php'; require_once WM_ROOTPATH . 'common/class_mailprocessor.php'; $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { throw new WebMailModelException('settings error'); } if (!$settings->IncludeLang()) { throw new WebMailModelException('lang error'); } $oldAcct = null; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($account); if ($dbStorage && $dbStorage->Connect()) { $oldAcct =& $dbStorage->SelectAccountData($account->Id); if ($oldAcct) { if ($account->Email != $oldAcct->Email) { $domain =& $dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($account->Email)); if (null !== $domain) { $domain->UpdateAccount($account, $settings); } } } else { throw new WebMailModelException(getGlobalError()); } } else { throw new WebMailModelException(getGlobalError()); } $validate = $account->ValidateData(); if (true !== $validate) { throw new WebMailModelException($validate); } else { if ($account->AllowChangeSettings && !$settings->StoreMailsInDb && $account->Email != $oldAcct->Email) { $_fs = new FileSystem(INI_DIR . '/mail', strtolower($oldAcct->Email), $account->Id); if (!$_fs->MoveFolders($account->Email)) { throw new WebMailModelException(PROC_CANT_UPDATE_ACCT); } } if ($account->Update(null)) { return true; } else { if (isset($GLOBALS[ErrorDesc])) { throw new WebMailModelException(getGlobalError()); } else { throw new WebMailModelException(PROC_CANT_UPDATE_ACCT); } } } throw new WebMailModelException(getGlobalError()); }
/** * @access private * @param resource $link * @param Account $account * @param WebMailMessage $message * @param string $from * @param string $to * @param CLog $log * @return bool */ function Send(&$link, &$account, &$message, $from, $to, &$log) { $ehloMsg = trim(EmailAddress::GetDomainFromEmail($account->Email)); $ehloMsg = strlen($ehloMsg) > 0 ? $ehloMsg : $account->MailOutHost; $result = CSmtp::ExecuteCommand($link, 'EHLO ' . $ehloMsg, $log); if (!$result) { $result = CSmtp::ExecuteCommand($link, 'HELO ' . $ehloMsg, $log); } if ($result && $account->MailOutAuthentication) { $result = CSmtp::ExecuteCommand($link, 'AUTH LOGIN', $log); $mailOutLogin = $account->MailOutLogin ? $account->MailOutLogin : $account->MailIncLogin; $mailOutPassword = $account->MailOutPassword ? $account->MailOutPassword : $account->MailIncPassword; if ($result) { $log->WriteLine('[Sending encoded login]'); $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutLogin), $log); } if ($result) { $log->WriteLine('[Sending encoded password]'); $result = CSmtp::ExecuteCommand($link, base64_encode($mailOutPassword), $log); } } if ($result) { $result = CSmtp::ExecuteCommand($link, 'MAIL FROM:<' . $from . '>', $log); } else { setGlobalError(ErrorSMTPAuth); } if ($result) { $toArray = explode(',', $to); foreach ($toArray as $recipient) { $recipient = trim($recipient); $result = CSmtp::ExecuteCommand($link, 'RCPT TO:<' . $recipient . '>', $log); if (!$result) { break; } } } if ($result) { $result = CSmtp::ExecuteCommand($link, 'DATA', $log); } if ($result) { $result = CSmtp::ExecuteCommand($link, str_replace(CRLF . '.', CRLF . '..', $message->TryToGetOriginalMailMessage()) . CRLF . '.', $log); } return $result; }