Code refactoring

This commit is contained in:
RainLoop Team 2015-03-18 16:33:48 +04:00
parent f817a680a2
commit d8c9f7ec14
15 changed files with 469 additions and 189 deletions

View file

@ -1245,6 +1245,17 @@ END;
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue));
}
/**
* @param string $sValue
*
* @return string
*/
public static function Trim($sValue)
{
return \trim(\preg_replace('/^[\x00-\x1F]+/u', '',
\preg_replace('/[\x00-\x1F]+$/u', '', \trim($sValue))));
}
/**
* @param string $sDir
*

View file

@ -194,8 +194,8 @@ class ImapClient extends \MailSo\Net\NetClient
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$sLogin = \trim($sLogin);
$sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
$sPassword = $sPassword;
$this->sLogginedUser = $sLogin;
@ -326,7 +326,7 @@ class ImapClient extends \MailSo\Net\NetClient
try
{
$this->SendRequestWithCheck('AUTHENTICATE', array('XOAUTH2', trim($sXOAuth2Token)));
$this->SendRequestWithCheck('AUTHENTICATE', array('XOAUTH2', \trim($sXOAuth2Token)));
}
catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException)
{

View file

@ -58,9 +58,11 @@ class Email
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
$this->sDisplayName = \trim($sDisplayName);
$this->sRemark = \trim($sRemark);
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sRemark = \MailSo\Base\Utils::Trim($sRemark);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
@ -88,6 +90,7 @@ class Email
*/
public static function Parse($sEmailAddress)
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();

View file

@ -26,6 +26,7 @@ class EmailCollection extends \MailSo\Base\Collection
{
parent::__construct();
$sEmailAddresses = \MailSo\Base\Utils::Trim($sEmailAddresses);
if (0 < \strlen($sEmailAddresses))
{
$this->parseEmailAddresses($sEmailAddresses);
@ -213,7 +214,7 @@ class EmailCollection extends \MailSo\Base\Collection
$this->Add(
\MailSo\Mime\Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
);
$iEmailStartPos = $iCurrentPos + 1;
}
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException)

View file

@ -186,7 +186,7 @@ class SmtpClient extends \MailSo\Net\NetClient
*/
public function Login($sLogin, $sPassword)
{
$sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
$sLogin = \MailSo\Base\Utils::IdnToAscii(\MailSo\Base\Utils::Trim($sLogin));
if ($this->IsAuthSupported('LOGIN'))
{
@ -283,7 +283,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{
try
{
$this->sendRequestWithCheck('AUTH', 235, 'XOAUTH2 '.trim($sXOAuth2Token));
$this->sendRequestWithCheck('AUTH', 235, 'XOAUTH2 '.\trim($sXOAuth2Token));
}
catch (\MailSo\Smtp\Exceptions\NegativeResponseException $oException)
{
@ -315,7 +315,9 @@ class SmtpClient extends \MailSo\Net\NetClient
*/
public function MailFrom($sFrom, $sSizeIfSupported = '', $bDsn = false)
{
$sFrom = \MailSo\Base\Utils::IdnToAscii($sFrom, true);
$sFrom = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sFrom), true);
$sCmd = 'FROM:<'.$sFrom.'>';
$sSizeIfSupported = (string) $sSizeIfSupported;
@ -356,7 +358,9 @@ class SmtpClient extends \MailSo\Net\NetClient
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$sTo = \MailSo\Base\Utils::IdnToAscii($sTo, true);
$sTo = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sTo), true);
$sCmd = 'TO:<'.$sTo.'>';
if ($bDsn && $this->IsSupported('DSN'))
@ -495,6 +499,9 @@ class SmtpClient extends \MailSo\Net\NetClient
*/
public function Vrfy($sUser)
{
$sUser = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sUser));
$this->sendRequestWithCheck('VRFY', array(250, 251, 252), $sUser);
return $this;

View file

@ -385,12 +385,6 @@ class Actions
}
}
// $sSubQuerty = \trim(\trim($this->Http()->GetQuery('s', '')), ' /');
// $sSubSubQuerty = \trim(\trim($this->Http()->GetQuery('ss', '')), ' /');
//
// $sQuery .= 0 < \strlen($sSubQuerty) ? '/'.$sSubQuerty : '';
// $sQuery .= 0 < \strlen($sSubSubQuerty) ? '/'.$sSubSubQuerty : '';
if ('' === $this->GetSpecAuthToken())
{
$aPaths = \explode('/', $sQuery);
@ -1632,7 +1626,7 @@ class Actions
$aResult['UserBackgroundHash'] = (string) $oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']);
// if (!empty($aResult['UserBackgroundName']) && !empty($aResult['UserBackgroundHash']))
// {
// $aResult['IncludeBackground'] = './?/Raw/&s=/{{USER}}/UserBackground/&ss=/'.
// $aResult['IncludeBackground'] = './?/Raw/&q[]=/{{USER}}/UserBackground/&q[]=/'.
// $aResult['UserBackgroundHash'].'/';
// }
}
@ -1834,7 +1828,8 @@ class Actions
{
$this->Plugins()->RunHook('filter.login-credentials.step-1', array(&$sEmail, &$sPassword));
$sEmail = \MailSo\Base\Utils::StrToLowerIfAscii($sEmail);
$sEmail = \MailSo\Base\Utils::StrToLowerIfAscii(
\MailSo\Base\Utils::Trim($sEmail));
if (false === \strpos($sEmail, '@'))
{
@ -2069,7 +2064,7 @@ class Actions
*/
public function DoLogin()
{
$sEmail = \trim($this->GetActionParam('Email', ''));
$sEmail = \MailSo\Base\Utils::Trim($this->GetActionParam('Email', ''));
$sPassword = $this->GetActionParam('Password', '');
$sLanguage = $this->GetActionParam('Language', '');
$bSignMe = '1' === (string) $this->GetActionParam('SignMe', '0');
@ -7707,8 +7702,8 @@ class Actions
\array_shift($aParams);
$sLast = \array_pop($aParams);
$sUrl = $this->Http()->GetFullUrl().'?/Raw/&s=/'.implode('/', $aParams).'/&ss=/'.$sLast;
$sFullUrl = 'https://docs.google.com/viewer?embedded=true&url='.urlencode($sUrl);
$sUrl = $this->Http()->GetFullUrl().'?/Raw/&q[]=/'.\implode('/', $aParams).'/&q[]=/'.$sLast;
$sFullUrl = 'https://docs.google.com/viewer?embedded=true&url='.\urlencode($sUrl);
@\header('Content-Type: text/html; charset=utf-8');
echo '<html style="height: 100%; width: 100%; margin: 0; padding: 0"><head></head>'.
@ -8725,7 +8720,7 @@ class Actions
*/
public function GetActionParam($sKey, $mDefault = null)
{
return is_array($this->aCurrentActionParams) && isset($this->aCurrentActionParams[$sKey]) ?
return \is_array($this->aCurrentActionParams) && isset($this->aCurrentActionParams[$sKey]) ?
$this->aCurrentActionParams[$sKey] : $mDefault;
}