/** * @access protected * * @param string $sEmailAddresses = '' */ protected function __construct($sEmailAddresses = '') { parent::__construct(); $sEmailAddresses = \MailSo\Base\Utils::Trim($sEmailAddresses); if (0 < \strlen($sEmailAddresses)) { $this->parseEmailAddresses($sEmailAddresses); } }
/** * @param string $sLogin * @param string $sPassword * @param string $sProxyAuthUser = '' * @param bool $bUseAuthPlainIfSupported = false * * @return \MailSo\Imap\ImapClient * * @throws \MailSo\Base\Exceptions\InvalidArgumentException * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception */ public function Login($sLogin, $sPassword, $sProxyAuthUser = '', $bUseAuthPlainIfSupported = false) { if (!\MailSo\Base\Validator::NotEmptyString($sLogin, true) || !\MailSo\Base\Validator::NotEmptyString($sPassword, true)) { $this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \MailSo\Log\Enumerations\Type::ERROR, true); } $sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin)); $sPassword = $sPassword; $this->sLogginedUser = $sLogin; try { // TODO if (false && $this->IsSupported('AUTH=CRAM-MD5')) { $this->SendRequest('AUTHENTICATE', array('CRAM-MD5')); $aResponse = $this->parseResponseWithValidation(); if ($aResponse && \is_array($aResponse) && 0 < \count($aResponse) && \MailSo\Imap\Enumerations\ResponseType::CONTINUATION === $aResponse[\count($aResponse) - 1]->ResponseType) { $oContinuationResponse = null; foreach ($aResponse as $oResponse) { if ($oResponse && \MailSo\Imap\Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { $oContinuationResponse = $oResponse; } } if ($oContinuationResponse) { $sToken = \base64_encode("" . $sLogin . "" . $sPassword); if ($this->oLogger) { $this->oLogger->AddSecret($sToken); } $this->Logger()->WriteDump($aResponse); $this->sendRaw($sToken, true, '*******'); $this->parseResponseWithValidation(); } else { // TODO } } } else { if ($bUseAuthPlainIfSupported && $this->IsSupported('AUTH=PLAIN')) { $sToken = \base64_encode("" . $sLogin . "" . $sPassword); if ($this->oLogger) { $this->oLogger->AddSecret($sToken); } if ($this->IsSupported('AUTH=SASL-IR') && false) { $this->SendRequestWithCheck('AUTHENTICATE', array('PLAIN', $sToken)); } else { $this->SendRequest('AUTHENTICATE', array('PLAIN')); $this->parseResponseWithValidation(); $this->sendRaw($sToken, true, '*******'); $this->parseResponseWithValidation(); } } else { if ($this->oLogger) { $this->oLogger->AddSecret($this->EscapeString($sPassword)); } $this->SendRequestWithCheck('LOGIN', array($this->EscapeString($sLogin), $this->EscapeString($sPassword))); } } // else // { // $this->writeLogException( // new \MailSo\Imap\Exceptions\LoginBadMethodException(), // \MailSo\Log\Enumerations\Type::NOTICE, true); // } if (0 < \strlen($sProxyAuthUser)) { $this->SendRequestWithCheck('PROXYAUTH', array($this->EscapeString($sProxyAuthUser))); } } catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException) { $this->writeLogException(new \MailSo\Imap\Exceptions\LoginBadCredentialsException($oException->GetResponses(), '', 0, $oException), \MailSo\Log\Enumerations\Type::NOTICE, true); } $this->bIsLoggined = true; $this->aCapabilityItems = null; return $this; }
/** * @return array * * @throws \MailSo\Base\Exceptions\Exception */ public function DoLogin() { $sEmail = \MailSo\Base\Utils::Trim($this->GetActionParam('Email', '')); $sPassword = $this->GetActionParam('Password', ''); $sLanguage = $this->GetActionParam('Language', ''); $bSignMe = '1' === (string) $this->GetActionParam('SignMe', '0'); $sAdditionalCode = $this->GetActionParam('AdditionalCode', ''); $bAdditionalCodeSignMe = '1' === (string) $this->GetActionParam('AdditionalCodeSignMe', '0'); $oAccount = null; $sPassword = $this->clientRsaDecryptHelper($sPassword); $this->Logger()->AddSecret($sPassword); if (0 < \strlen($sEmail) && 0 < \strlen($sPassword) && $this->Config()->Get('security', 'allow_universal_login', true) && $this->Config()->Get('security', 'allow_admin_panel', true) && $sEmail === $this->Config()->Get('security', 'admin_login', '')) { if ($this->Config()->ValidatePassword($sPassword)) { $this->setAdminAuthToken($this->getAdminToken()); return $this->DefaultResponse(__FUNCTION__, true, array('Admin' => true)); } else { $this->loginErrorDelay(); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError); } } else { if ('*****@*****.**' === $sEmail && 0 < \strlen($sPassword) && \is_numeric($sPassword) && $this->Config()->Get('debug', 'enable', false)) { \sleep((int) $sPassword); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError); } } try { $oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe ? $this->generateSignMeToken($sEmail) : '', $sAdditionalCode, $bAdditionalCodeSignMe); } catch (\RainLoop\Exceptions\ClientException $oException) { if ($oException && \RainLoop\Notifications::AccountTwoFactorAuthRequired === $oException->getCode()) { return $this->DefaultResponse(__FUNCTION__, true, array('TwoFactorAuth' => true)); } else { throw $oException; } } $this->AuthToken($oAccount); if ($oAccount && 0 < \strlen($sLanguage)) { $oSettings = $this->SettingsProvider()->Load($oAccount); if ($oSettings) { $sLanguage = $this->ValidateLanguage($sLanguage); $sCurrentLanguage = $oSettings->GetConf('Language', ''); if ($sCurrentLanguage !== $sLanguage) { $oSettings->SetConf('Language', $sLanguage); $this->SettingsProvider()->Save($oAccount, $oSettings); } } } return $this->TrueResponse(__FUNCTION__); }
/** * @param string $sValue * * @return string */ public static function ClearXss($sValue) { return \MailSo\Base\Utils::Trim(\MailSo\Base\Utils::ClearNullBite(\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue))); }
/** * @return \MailSo\Smtp\SmtpClient * * @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Smtp\Exceptions\Exception */ public function Vrfy($sUser) { $sUser = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sUser)); $this->sendRequestWithCheck('VRFY', array(250, 251, 252), $sUser); return $this; }
/** * @param string $sEmailAddress * @return \MailSo\Mime\Email * * @throws \MailSo\Base\Exceptions\InvalidArgumentException */ public static function Parse($sEmailAddress) { $sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress); if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException(); } $sName = ''; $sEmail = ''; $sComment = ''; $bInName = false; $bInAddress = false; $bInComment = false; $iStartIndex = 0; $iEndIndex = 0; $iCurrentIndex = 0; while ($iCurrentIndex < \strlen($sEmailAddress)) { switch ($sEmailAddress[$iCurrentIndex]) { // case '\'': case '"': // $sQuoteChar = $sEmailAddress{$iCurrentIndex}; if (!$bInName && !$bInAddress && !$bInComment) { $bInName = true; $iStartIndex = $iCurrentIndex; } else { if (!$bInAddress && !$bInComment) { $iEndIndex = $iCurrentIndex; $sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1); $sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1); $iEndIndex = 0; $iCurrentIndex = 0; $iStartIndex = 0; $bInName = false; } } break; case '<': if (!$bInName && !$bInAddress && !$bInComment) { if ($iCurrentIndex > 0 && \strlen($sName) === 0) { $sName = \substr($sEmailAddress, 0, $iCurrentIndex); } $bInAddress = true; $iStartIndex = $iCurrentIndex; } break; case '>': if ($bInAddress) { $iEndIndex = $iCurrentIndex; $sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1); $sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1); $iEndIndex = 0; $iCurrentIndex = 0; $iStartIndex = 0; $bInAddress = false; } break; case '(': if (!$bInName && !$bInAddress && !$bInComment) { $bInComment = true; $iStartIndex = $iCurrentIndex; } break; case ')': if ($bInComment) { $iEndIndex = $iCurrentIndex; $sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1); $sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1); $iEndIndex = 0; $iCurrentIndex = 0; $iStartIndex = 0; $bInComment = false; } break; case '\\': $iCurrentIndex++; break; } $iCurrentIndex++; } if (\strlen($sEmail) === 0) { $aRegs = array(''); if (\preg_match('/[^@\\s]+@\\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0])) { $sEmail = $aRegs[0]; } else { $sName = $sEmailAddress; } } if (\strlen($sEmail) > 0 && \strlen($sName) == 0 && \strlen($sComment) == 0) { $sName = \str_replace($sEmail, '', $sEmailAddress); } $sEmail = \trim(\trim($sEmail), '<>'); $sEmail = \rtrim(\trim($sEmail), '.'); $sEmail = \trim($sEmail); $sName = \trim(\trim($sName), '"'); $sName = \trim($sName, '\''); $sComment = \trim(\trim($sComment), '()'); // Remove backslash $sName = \preg_replace('/\\\\(.)/s', '$1', $sName); $sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment); return Email::NewInstance($sEmail, $sName, $sComment); }