diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 4e00eb153a..3442e8e943 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -54,6 +54,8 @@ class EMailTemplate implements IEMailTemplate { protected $headerAdded = false; /** @var bool indicated if the body is already opened */ protected $bodyOpened = false; + /** @var bool indicated if there is a list open in the body */ + protected $bodyListOpened = false; /** @var bool indicated if the footer is added */ protected $footerAdded = false; @@ -172,6 +174,34 @@ EOF; +EOF; + + protected $listBegin = << + + + + +EOF; + + protected $listItem = << + + + + +EOF; + + protected $listEnd = << + + + +
+

%s

+
+

%s

+
EOF; protected $buttonGroup = <<bodyOpened) { + return; + } + + $this->htmlBody .= $this->bodyBegin; + $this->bodyOpened = true; + } + /** * Adds a paragraph to the body of the email * @@ -367,10 +409,7 @@ EOF; $plainText = $text; } - if (!$this->bodyOpened) { - $this->htmlBody .= $this->bodyBegin; - $this->bodyOpened = true; - } + $this->ensureBodyIsOpened(); $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); if ($plainText !== false) { @@ -378,6 +417,66 @@ EOF; } } + /** + * Adds a list item to the body of the email + * + * @param string $text + * @param string $metaInfo + * @param string $icon Absolute path, must be 16*16 pixels + * @param string $plainText Text that is used in the plain text email + * if empty the $text is used, if false none will be used + * @param string $plainMetaInfo Meta info that is used in the plain text email + * if empty the $metaInfo is used, if false none will be used + * @since 12.0.0 + */ + public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = '') { + $this->ensureBodyListOpened(); + + if ($plainText === '') { + $plainText = $text; + } + if ($plainMetaInfo === '') { + $plainMetaInfo = $metaInfo; + } + + $htmlText = htmlspecialchars($text); + if ($metaInfo) { + $htmlText = '' . htmlspecialchars($metaInfo) . '
' . $htmlText; + } + if ($icon !== '') { + $icon = '•'; + } else { + $icon = '•'; + } + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); + if ($plainText !== false) { + $this->plainBody .= ' * ' . $plainText; + if ($plainMetaInfo !== false) { + $this->plainBody .= ' (' . $plainMetaInfo . ')'; + } + $this->plainBody .= PHP_EOL; + } + } + + protected function ensureBodyListOpened() { + if ($this->bodyListOpened) { + return; + } + + $this->ensureBodyIsOpened(); + $this->bodyListOpened = true; + $this->htmlBody .= $this->listBegin; + } + + protected function ensureBodyListClosed() { + if (!$this->bodyListOpened) { + return; + } + + $this->bodyListOpened = false; + $this->htmlBody .= $this->listEnd; + } + /** * Adds a button group of two buttons to the body of the email * @@ -405,10 +504,8 @@ EOF; $plainTextRight = $textRight; } - if (!$this->bodyOpened) { - $this->htmlBody .= $this->bodyBegin; - $this->bodyOpened = true; - } + $this->ensureBodyIsOpened(); + $this->ensureBodyListClosed(); $color = $this->themingDefaults->getColorPrimary(); @@ -433,10 +530,8 @@ EOF; return; } - if (!$this->bodyOpened) { - $this->htmlBody .= $this->bodyBegin; - $this->bodyOpened = true; - } + $this->ensureBodyIsOpened(); + $this->ensureBodyListClosed(); if ($plainText === '') { $plainText = $text; @@ -453,6 +548,20 @@ EOF; } + /** + * Close the HTML body when it is open + */ + protected function ensureBodyIsClosed() { + if (!$this->bodyOpened) { + return; + } + + $this->ensureBodyListClosed(); + + $this->htmlBody .= $this->bodyEnd; + $this->bodyOpened = false; + } + /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * @@ -468,10 +577,7 @@ EOF; } $this->footerAdded = true; - if ($this->bodyOpened) { - $this->htmlBody .= $this->bodyEnd; - $this->bodyOpened = false; - } + $this->ensureBodyIsClosed(); $this->htmlBody .= vsprintf($this->footer, [$text]); $this->htmlBody .= $this->tail; @@ -487,9 +593,7 @@ EOF; public function renderHtml() { if (!$this->footerAdded) { $this->footerAdded = true; - if ($this->bodyOpened) { - $this->htmlBody .= $this->bodyEnd; - } + $this->ensureBodyIsClosed(); $this->htmlBody .= $this->tail; } return $this->htmlBody; @@ -503,9 +607,7 @@ EOF; public function renderText() { if (!$this->footerAdded) { $this->footerAdded = true; - if ($this->bodyOpened) { - $this->htmlBody .= $this->bodyEnd; - } + $this->ensureBodyIsClosed(); $this->htmlBody .= $this->tail; } return $this->plainBody; diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 05e2fe92be..6df83b4d10 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -80,6 +80,20 @@ interface IEMailTemplate { */ public function addBodyText($text, $plainText = ''); + /** + * Adds a list item to the body of the email + * + * @param string $text + * @param string $metaInfo + * @param string $icon Absolute path, must be 16*16 pixels + * @param string $plainText Text that is used in the plain text email + * if empty the $text is used, if false none will be used + * @param string $plainMetaInfo Meta info that is used in the plain text email + * if empty the $metaInfo is used, if false none will be used + * @since 12.0.0 + */ + public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = ''); + /** * Adds a button group of two buttons to the body of the email *