mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 16:37:02 +03:00
Added "use_local_proxy_for_external_images" setting (Closes #211)
This commit is contained in:
parent
a19e19d866
commit
3ae18e76c6
16 changed files with 230 additions and 43 deletions
|
|
@ -1215,6 +1215,7 @@ class Actions
|
|||
$aResult['AllowLanguagesOnLogin'] = (bool) $oConfig->Get('login', 'allow_languages_on_login', true);
|
||||
$aResult['AttachmentLimit'] = ((int) $oConfig->Get('webmail', 'attachment_size_limit', 10)) * 1024 * 1024;
|
||||
$aResult['SignMe'] = (string) $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DEFAILT_OFF);
|
||||
$aResult['UseLocalProxyForExternalImages'] = (bool) $oConfig->Get('labs', 'use_local_proxy_for_external_images', false);
|
||||
|
||||
// user
|
||||
$aResult['EditorDefaultType'] = (string) $oConfig->Get('webmail', 'editor_default_type', '');
|
||||
|
|
@ -2172,6 +2173,8 @@ class Actions
|
|||
return $self->ValidateTheme($sTheme);
|
||||
});
|
||||
|
||||
$this->setConfigFromParams($oConfig, 'UseLocalProxyForExternalImages', 'labs', 'use_local_proxy_for_external_images', 'bool');
|
||||
|
||||
$this->setConfigFromParams($oConfig, 'AllowLanguagesOnSettings', 'webmail', 'allow_languages_on_settings', 'bool');
|
||||
$this->setConfigFromParams($oConfig, 'AllowLanguagesOnLogin', 'login', 'allow_languages_on_login', 'bool');
|
||||
$this->setConfigFromParams($oConfig, 'AttachmentLimit', 'webmail', 'attachment_size_limit', 'int');
|
||||
|
|
@ -7009,6 +7012,7 @@ class Actions
|
|||
'ThreadsLen' => $mResponse->ThreadsLen(),
|
||||
'ParentThread' => $mResponse->ParentThread(),
|
||||
'Sensitivity' => $mResponse->Sensitivity(),
|
||||
'ExternalProxy' => false,
|
||||
'ReadReceipt' => ''
|
||||
));
|
||||
|
||||
|
|
@ -7095,9 +7099,24 @@ class Actions
|
|||
$mResult['DraftInfo'] = $mResponse->DraftInfo();
|
||||
$mResult['InReplyTo'] = $mResponse->InReplyTo();
|
||||
$mResult['References'] = $mResponse->References();
|
||||
|
||||
$fAdditionalExternalFilter = null;
|
||||
if (!!$this->Config()->Get('labs', 'use_local_proxy_for_external_images', false))
|
||||
{
|
||||
$sIndexPrefix = 0 < strlen(APP_INDEX_FILE) ? APP_INDEX_FILE : './';
|
||||
$fAdditionalExternalFilter = function ($sUrl) use ($sIndexPrefix) {
|
||||
return $sIndexPrefix.'?/ProxyExternal/'.\RainLoop\Utils::EncodeKeyValues(array(
|
||||
'Token' => \RainLoop\Utils::GetConnectionToken(),
|
||||
'Url' => $sUrl
|
||||
)).'/';
|
||||
};
|
||||
}
|
||||
|
||||
$mResult['Html'] = 0 === \strlen($sHtml) ? '' : \MailSo\Base\HtmlUtils::ClearHtml(
|
||||
$sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls, false,
|
||||
!!$this->Config()->Get('labs', 'allow_smart_html_links', true));
|
||||
!!$this->Config()->Get('labs', 'allow_smart_html_links', true), $fAdditionalExternalFilter);
|
||||
|
||||
$mResult['ExternalProxy'] = null !== $fAdditionalExternalFilter;
|
||||
|
||||
$mResult['PlainRaw'] = $sPlain;
|
||||
$mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ Enables caching in the system'),
|
|||
'fast_cache_memcache_host' => array('127.0.0.1'),
|
||||
'fast_cache_memcache_port' => array(11211),
|
||||
'fast_cache_memcache_expire' => array(43200),
|
||||
'use_local_proxy_for_external_images' => array(false),
|
||||
'dev_email' => array(''),
|
||||
'dev_password' => array('')
|
||||
)
|
||||
|
|
|
|||
|
|
@ -337,6 +337,66 @@ class ServiceActions
|
|||
return $this->privateUpload('UploadBackground');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function ServiceProxyExternal()
|
||||
{
|
||||
$bResult = false;
|
||||
$sData = empty($this->aPaths[1]) ? '' : $this->aPaths[1];
|
||||
if (!empty($sData) && $this->oActions->Config()->Get('labs', 'use_local_proxy_for_external_images', false))
|
||||
{
|
||||
$this->oActions->verifyCacheByKey($sData);
|
||||
|
||||
$aData = \RainLoop\Utils::DecodeKeyValues($sData);
|
||||
if (\is_array($aData) && !empty($aData['Token']) && !empty($aData['Url']) && $aData['Token'] === \RainLoop\Utils::GetConnectionToken())
|
||||
{
|
||||
$sUrl = $aData['Url'];
|
||||
|
||||
$aOptions = array(
|
||||
CURLOPT_URL => $sUrl,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_USERAGENT => 'RainLoop External Proxy',
|
||||
CURLOPT_FAILONERROR => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => false,
|
||||
CURLOPT_TIMEOUT => (int) 10
|
||||
);
|
||||
|
||||
$oCurl = \curl_init();
|
||||
\curl_setopt_array($oCurl, $aOptions);
|
||||
|
||||
$mResult = \curl_exec($oCurl);
|
||||
|
||||
$iCode = (int) \curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
|
||||
$sContentType = (string) \curl_getinfo($oCurl, CURLINFO_CONTENT_TYPE);
|
||||
$sContentType = \trim(\strtolower($sContentType));
|
||||
|
||||
if (false !== $mResult && 200 === $iCode &&
|
||||
\in_array($sContentType, array('image/png', 'image/jpeg', 'image/jpg', 'image/bmp', 'image/gif')))
|
||||
{
|
||||
$bResult = true;
|
||||
|
||||
$this->oActions->cacheByKey($sData);
|
||||
|
||||
\header('Content-Type: '.$sContentType);
|
||||
echo $mResult;
|
||||
}
|
||||
|
||||
if (\is_resource($oCurl))
|
||||
{
|
||||
\curl_close($oCurl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$bResult)
|
||||
{
|
||||
$this->oHttp->StatusHeader(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue