diff --git a/.devilbox/www/htdocs/assets/js/html-email.js b/.devilbox/www/htdocs/assets/js/html-email.js deleted file mode 100644 index 5e4725ce..00000000 --- a/.devilbox/www/htdocs/assets/js/html-email.js +++ /dev/null @@ -1,22 +0,0 @@ -class HtmlEmail extends HTMLElement { - constructor() { - super(); - this.attachShadow({ mode: 'open' }); - - let emailContent; - const templateId = this.dataset.templateId; - try { - emailContent = document.getElementById(templateId).innerHTML; - } catch (error) { - console.log(error); - return; - } - - const container = document.createElement('div'); - container.innerHTML = emailContent; - - this.shadowRoot.appendChild(container); - } -} - -customElements.define('html-email', HtmlEmail); diff --git a/.devilbox/www/htdocs/mail.php b/.devilbox/www/htdocs/mail.php index 5de1dc6d..21dc6990 100644 --- a/.devilbox/www/htdocs/mail.php +++ b/.devilbox/www/htdocs/mail.php @@ -24,6 +24,28 @@ require $VEN_DIR . DIRECTORY_SEPARATOR . 'Mail' . DIRECTORY_SEPARATOR .'mimeDeco require $LIB_DIR . DIRECTORY_SEPARATOR . 'Mail.php'; require $LIB_DIR . DIRECTORY_SEPARATOR . 'Sort.php'; +if (isset($_GET['get-body']) && is_numeric($_GET['get-body'])) { + $messageNumber = $_GET['get-body']; + $MyMbox = new \devilbox\Mail('/var/mail/devilbox'); + $message = $MyMbox->getMessage($messageNumber-1); + $structure = $message['decoded']; + + $body = null; + if (isset($structure->body)) { + $body = $structure->body; + } + elseif(isset($structure->parts[1]->body)) { + $body = $structure->parts[1]->body; + } + elseif(isset($structure->parts[0]->body)) { + $body = $structure->parts[0]->body; + } + + exit(json_encode(array( + 'raw' => htmlentities($message['raw']), + 'body' => $body, + ))); +} if (isset($_GET['delete']) && is_numeric($_GET['delete'])) { $message = $_GET['delete']; @@ -171,17 +193,6 @@ $messages = $MyMbox->get($sortOrderArr); body)) { - $body = $structure->body; - } - elseif(isset($structure->parts[1]->body)) { - $body = $structure->parts[1]->body; - } - elseif(isset($structure->parts[0]->body)) { - $body = $structure->parts[0]->body; - } ?> @@ -198,17 +209,13 @@ $messages = $MyMbox->get($sortOrderArr); - - - - - - +
+

-
+
@@ -227,12 +234,34 @@ $messages = $MyMbox->get($sortOrderArr); - diff --git a/.devilbox/www/include/lib/Mail.php b/.devilbox/www/include/lib/Mail.php index ecfecabd..5d9b3cfe 100644 --- a/.devilbox/www/include/lib/Mail.php +++ b/.devilbox/www/include/lib/Mail.php @@ -70,6 +70,22 @@ class Mail } + /** + * Returns a single message + * + * @param int $messageIndex The zero-based index of the message to return. + */ + public function getMessage($messageIndex){ + $message = $this->_Mbox->get($messageIndex); + $Decoder = new \Mail_mimeDecode($message, "\r\n"); + return array( + 'num' => $messageIndex + 1, + 'raw' => $message, + 'decoded' => $Decoder->decode($this->_defaultMimeParams) + ); + } + + /** * Retrieve emails. * @@ -87,13 +103,7 @@ class Mail // Get messages in reverse order (last entry first) for ($n = $total; $n >= 0; --$n) { - $message = $this->_Mbox->get($n); - $Decoder = new \Mail_mimeDecode($message, "\r\n"); - $messages[] = array( - 'num' => $n + 1, - 'raw' => $message, - 'decoded' => $Decoder->decode($this->_defaultMimeParams) - ); + $messages[] = $this->getMessage($n); } // Optionally sort messages diff --git a/.tests/tests/intranet-email.sh b/.tests/tests/intranet-email.sh index 4bcccea8..f03613ca 100755 --- a/.tests/tests/intranet-email.sh +++ b/.tests/tests/intranet-email.sh @@ -71,4 +71,4 @@ run "curl -sS --fail -XPOST 'http://localhost:${HOST_PORT_HTTPD}/mail.php' -d 'e # Validate run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/mail.php' | tac | tac | grep '${MY_MAIL}' >/dev/null" "${RETRIES}" run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/mail.php' | tac | tac | grep '${MY_SUBJ}' >/dev/null" "${RETRIES}" -run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/mail.php' | tac | tac | grep '${MY_MESS}' >/dev/null" "${RETRIES}" +run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/mail.php?get-body=1' | tac | tac | grep '${MY_MESS}' >/dev/null" "${RETRIES}"