From 693a81bfa367089de4b61ee1ea104c85e6bc6d1c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Jul 2024 15:29:45 +0200 Subject: fix(mail): Fix big logos in mail templates for Outlook Signed-off-by: Joas Schilling --- lib/private/Mail/EMailTemplate.php | 12 ++++++++++-- lib/private/Mail/Mailer.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) (limited to 'lib/private/Mail') diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 80740e14aca..cbb006203e1 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -76,7 +76,7 @@ EOF;
- +
@@ -308,6 +308,8 @@ EOF; protected Defaults $themingDefaults, protected IURLGenerator $urlGenerator, protected IFactory $l10nFactory, + protected ?int $logoWidth, + protected ?int $logoHeight, protected string $emailId, protected array $data, ) { @@ -330,8 +332,14 @@ EOF; } $this->headerAdded = true; + $logoSizeDimensions = ''; + if ($this->logoWidth && $this->logoHeight) { + // Provide a logo size when we have the dimensions so that it displays nicely in Outlook + $logoSizeDimensions = ' width="' . $this->logoWidth . '" height="' . $this->logoHeight . '"'; + } + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName(), $logoSizeDimensions]); } /** diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index e866cbfdbbc..4ddb748fc26 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -52,6 +52,12 @@ use Symfony\Component\Mime\Exception\RfcComplianceException; * @package OC\Mail */ class Mailer implements IMailer { + // Do not move this block or change it's content without contacting the release crew + public const DEFAULT_DIMENSIONS = '252x120'; + // Do not move this block or change it's content without contacting the release crew + + public const MAX_LOGO_SIZE = 105; + private ?MailerInterface $instance = null; public function __construct( @@ -109,10 +115,37 @@ class Mailer implements IMailer { ); } + $logoDimensions = $this->config->getAppValue('theming', 'logoDimensions', self::DEFAULT_DIMENSIONS); + if (str_contains($logoDimensions, 'x')) { + [$width, $height] = explode('x', $logoDimensions); + $width = (int) $width; + $height = (int) $height; + + if ($width > self::MAX_LOGO_SIZE || $height > self::MAX_LOGO_SIZE) { + if ($width === $height) { + $logoWidth = self::MAX_LOGO_SIZE; + $logoHeight = self::MAX_LOGO_SIZE; + } elseif ($width > $height) { + $logoWidth = self::MAX_LOGO_SIZE; + $logoHeight = (int) (($height / $width) * self::MAX_LOGO_SIZE); + } else { + $logoWidth = (int) (($width / $height) * self::MAX_LOGO_SIZE); + $logoHeight = self::MAX_LOGO_SIZE; + } + } else { + $logoWidth = $width; + $logoHeight = $height; + } + } else { + $logoWidth = $logoHeight = null; + } + return new EMailTemplate( $this->defaults, $this->urlGenerator, $this->l10nFactory, + $logoWidth, + $logoHeight, $emailId, $data ); -- cgit v1.2.3