Skip to content

Commit

Permalink
Resolve #910 MailSo\Base\Http::GetHost(): Return value must be of typ…
Browse files Browse the repository at this point in the history
…e string
  • Loading branch information
the-djmaze committed Feb 4, 2023
1 parent fc5b26d commit be0348b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
15 changes: 5 additions & 10 deletions snappymail/v/0.0.0/app/libraries/MailSo/Base/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,18 @@ public function IsSecure(bool $bCheckProxy = true) : bool
));
}

public function GetHost(bool $bWithRemoteUserData = false, bool $bWithoutWWW = true, bool $bWithoutPort = false) : string
public function GetHost(bool $bWithoutWWW = true, bool $bWithoutPort = false) : string
{
$sHost = static::GetServer('HTTP_HOST', '');
if (!\strlen($sHost)) {
$sName = static::GetServer('SERVER_NAME');
$sName = static::GetServer('SERVER_NAME', '');
$iPort = (int) static::GetServer('SERVER_PORT', 80);

$sHost = (\in_array($iPort, array(80, 433))) ? $sName : $sName.':'.$iPort;
}

if ($bWithoutWWW) {
$sHost = 'www.' === \substr(\strtolower($sHost), 0, 4) ? \substr($sHost, 4) : $sHost;
}

if ($bWithRemoteUserData) {
$sUser = \trim(static::GetServer('REMOTE_USER', ''));
$sHost = (\strlen($sUser) ? $sUser.'@' : '').$sHost;
if ($bWithoutWWW && 'www.' === \substr(\strtolower($sHost), 0, 4)) {
$sHost = \substr($sHost, 4);
}

return $bWithoutPort ? \preg_replace('/:\d+$/', '', $sHost) : $sHost;
Expand Down Expand Up @@ -249,6 +244,6 @@ public function GetUrl() : string

public function GetFullUrl() : string
{
return $this->GetScheme().'://'.$this->GetHost(true, false).$this->GetPath();
return $this->GetScheme().'://'.$this->GetHost(false).$this->GetPath();
}
}
10 changes: 5 additions & 5 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function __construct()
. '][' . \MailSo\Base\Http::GetServer('SERVER_SOFTWARE', '~')
. '][' . (\MailSo\Base\Utils::FunctionCallable('php_sapi_name') ? \php_sapi_name() : '~')
. '][Streams:' . \implode(',', \stream_get_transports())
. '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . \MailSo\Base\Http::GetServer('REQUEST_URI', '') . ']'
. '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false) . \MailSo\Base\Http::GetServer('REQUEST_URI', '') . ']'
);
}

Expand Down Expand Up @@ -293,13 +293,13 @@ protected function compileLogParams(string $sLine, ?Model\Account $oAccount = nu

if (false !== \strpos($sLine, '{request:domain}')) {
$sLine = \str_replace('{request:domain}',
Utils::UrlEncode($this->Http()->GetHost(false, true, true), $bUrlEncode), $sLine);
Utils::UrlEncode($this->Http()->GetHost(true, true), $bUrlEncode), $sLine);
}

if (false !== \strpos($sLine, '{request:domain-clear}')) {
$sLine = \str_replace('{request:domain-clear}',
Utils::UrlEncode(
\MailSo\Base\Utils::GetClearDomainName($this->Http()->GetHost(false, true, true)), $bUrlEncode), $sLine);
Utils::UrlEncode(\MailSo\Base\Utils::GetClearDomainName($this->Http()->GetHost(true, true)), $bUrlEncode),
$sLine);
}

$aClear['/\{request:([^}]*)\}/i'] = 'request';
Expand Down Expand Up @@ -907,7 +907,7 @@ protected function loginErrorDelay(): void

protected function getAdditionalLogParamsByUserLogin(string $sLogin, bool $bAdmin = false): array
{
$sHost = $bAdmin ? $this->Http()->GetHost(false, true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
$sHost = $bAdmin ? $this->Http()->GetHost(true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
return array(
'{imap:login}' => $sLogin,
'{imap:host}' => $sHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function resolveLoginCredentials(string &$sEmail, string &$sPassword, str
$bAdded = false;

if ($this->Config()->Get('login', 'determine_user_domain', false)) {
$sUserHost = \trim($this->Http()->GetHost(false, true, true));
$sUserHost = \trim($this->Http()->GetHost(true, true));
$this->Logger()->Write('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN');

$aDomainParts = \explode('.', $sUserHost);
Expand Down
2 changes: 1 addition & 1 deletion snappymail/v/0.0.0/app/libraries/RainLoop/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static function RunResult() : bool

$oHttp = \MailSo\Base\Http::SingletonInstance();
if ($oConfig->Get('security', 'force_https', false) && !$oHttp->IsSecure()) {
\header('Location: https://'.$oHttp->GetHost(false, false).$oHttp->GetUrl());
\header('Location: https://'.$oHttp->GetHost(false).$oHttp->GetUrl());
exit;
}

Expand Down

0 comments on commit be0348b

Please sign in to comment.