From bb938fc0182f25f485cf9591c1de4299e23ccd98 Mon Sep 17 00:00:00 2001 From: Aravindo Wingeier Date: Fri, 19 Jan 2018 20:28:41 +0100 Subject: [PATCH] fix #34 and #32: display HTML or Text by default. (#35) * fix #34 and #32: display HTML or Text by default. * cleanup --- CHANGELOG.md | 2 ++ src/config.sample.php | 3 ++ src/frontend.template.php | 66 ++++++++++++++------------------------- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d0737..33d8a56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). - fixed problem where only one domain is defined - horizontal spacing for header (from @Spegeli) and style - fix: restore focus on reload +- Added $config['prefer_plaintext'] = true; Prefer HTML or Text and removed toggle buttons. + ### Added - Added multiple domain support (https://github.com/synox/disposable-mailbox/issues/21) diff --git a/src/config.sample.php b/src/config.sample.php index 238b638..1282595 100644 --- a/src/config.sample.php +++ b/src/config.sample.php @@ -31,3 +31,6 @@ $config['delete_messages_older_than'] = '30 days ago'; // Mails to those usernames can not be accessed: $config['blocked_usernames'] = array('root', 'admin', 'administrator', 'hostmaster', 'postmaster', 'webmaster'); +// Mails are usually show as Text and only if not available as HTML. You can turn this around to prefer HTML over text. +$config['prefer_plaintext'] = true; + diff --git a/src/frontend.template.php b/src/frontend.template.php index 4080ed7..59c8e03 100644 --- a/src/frontend.template.php +++ b/src/frontend.template.php @@ -63,22 +63,6 @@ $purifier = new HTMLPurifier($purifier_config); }, 15000); - function showHtml(id) { - document.getElementById('email-' + id + '-html').style.display = 'block'; - document.getElementById('email-' + id + '-plain').style.display = 'none'; - document.getElementById('show-html-button-' + id).style.display = 'none'; - document.getElementById('show-plain-button-' + id).style.display = 'inline-block'; - return false; - } - - function showPlain(id) { - document.getElementById('email-' + id + '-html').style.display = 'none'; - document.getElementById('email-' + id + '-plain').style.display = 'block'; - document.getElementById('show-html-button-' + id).style.display = 'inline-block'; - document.getElementById('show-plain-button-' + id).style.display = 'none'; - return false; - } - function copyToClipboard(text) { var inp = document.createElement('input'); document.body.appendChild(inp); @@ -188,19 +172,6 @@ $purifier = new HTMLPurifier($purifier_config);
- - - Download @@ -244,19 +215,30 @@ $purifier = new HTMLPurifier($purifier_config); ?>
- -
- textPlain, FILTER_SANITIZE_SPECIAL_CHARS); - // Keep newlines - $text = str_replace(' ', '
', $text); - echo \AutoLinkExtension::auto_link_text($text) - ?> -
- + purify($email->textHtml); + + $safeText = $purifier->purify($email->textPlain); + $safeText = nl2br($safeText); + $safeText = \AutoLinkExtension::auto_link_text($safeText); + + $hasHtml = strlen(trim($safeHtml)) > 0; + $hasText = strlen(trim($safeText)) > 0; + + if ($config['prefer_plaintext']) { + if ($hasText) { + echo $safeText; + } else { + echo $safeHtml; + } + } else { + if ($hasHtml) { + echo $safeHtml; + } else { + echo $safeText; + } + } + ?>