diff --git a/plugins/avatars/index.php b/plugins/avatars/index.php index c0ad97660..54d026aa5 100644 --- a/plugins/avatars/index.php +++ b/plugins/avatars/index.php @@ -1,4 +1,8 @@ + if ($aResult) { + static::cacheImage($sEmail, $aResult); + } + return $aResult; + } + private static function getUrl(string $sUrl) : ?array { $oHTTP = \SnappyMail\HTTP\Request::factory(/*'socket' or 'curl'*/); @@ -297,17 +351,21 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin $oHTTP->proxy_auth = \RainLoop\Api::Config()->Get('labs', 'curl_proxy_auth', ''); $oHTTP->max_response_kb = 0; $oHTTP->timeout = 15; // timeout in seconds. - $oResponse = $oHTTP->doRequest('GET', $sUrl); - if ($oResponse) { - if (200 === $oResponse->status && \str_starts_with($oResponse->getHeader('content-type'), 'image/')) { - return [ - $oResponse->getHeader('content-type'), - $oResponse->body - ]; + try { + $oResponse = $oHTTP->doRequest('GET', $sUrl); + if ($oResponse) { + if (200 === $oResponse->status && \str_starts_with($oResponse->getHeader('content-type'), 'image/')) { + return [ + $oResponse->getHeader('content-type'), + $oResponse->body + ]; + } + \SnappyMail\Log::notice('Avatar', "error {$oResponse->status} for {$sUrl}"); + } else { + \SnappyMail\Log::warning('Avatar', "failed for {$sUrl}"); } - \SnappyMail\Log::notice('Avatar', "error {$oResponse->status} for {$sUrl}"); - } else { - \SnappyMail\Log::warning('Avatar', "failed for {$sUrl}"); + } catch (\Throwable $e) { + \SnappyMail\Log::notice('Avatar', "error {$e->getMessage()}"); } return null; }