From 646a71d389ddf7ff2370a3deb32905b88363c306 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 1 Jul 2017 19:37:04 +0200 Subject: [PATCH] Add Email::debugDump() --- .../files/lib/system/email/Email.class.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/wcfsetup/install/files/lib/system/email/Email.class.php b/wcfsetup/install/files/lib/system/email/Email.class.php index 0027e417ad..a2fdf41396 100644 --- a/wcfsetup/install/files/lib/system/email/Email.class.php +++ b/wcfsetup/install/files/lib/system/email/Email.class.php @@ -531,4 +531,65 @@ class Email { public function getEmail() { return $this->getHeaderString()."\r\n\r\n".$this->getBodyString(); } + + /** + * Dumps this email to STDOUT and stops the script. + * + * @return string + */ + public function debugDump() { + if (ob_get_level()) { + // discard any output generated before the exception occurred, prevents exception + // being hidden inside HTML elements and therefore not visible in browser output + ob_end_clean(); + + // `identity` is the default "encoding" and basically means that the client + // must treat the content as if the header did not appear in first place, this + // also overrules the gzip header if present + @header('Content-Encoding: identity'); + HeaderUtil::exceptionDisableGzip(); + } + + $dumpBody = function ($body, $depth) use (&$dumpBody) { + $result = ''; + if ($body instanceof mime\MimePartFacade) { + return $dumpBody($body->getMimePart(), $depth); + } + if ($body instanceof mime\AbstractMultipartMimePart) { + $result .= "
".get_class($body).""; + foreach ($body->getMimeparts() as $part) { + $result .= $dumpBody($part, $depth + 1); + } + $result .= '
'; + } + else if ($body instanceof mime\RecipientAwareTextMimePart) { + $result .= "
".get_class($body).""; + if ($body instanceof mime\HtmlTextMimePart) { + $result .= ''; + } + else { + $result .= "
".StringUtil::encodeHTML($body->getContent())."
"; + } + $result .= '
'; + } + else if ($body instanceof mime\AttachmentMimePart) { + $result .= "
".get_class($body).""; + $result .= "
".implode('', array_map(function ($item) { + return "
".$item[0]."
".$item[1]."
"; + }, $body->getAdditionalHeaders()))."
"; + $result .= "<".strlen($body->getContent())." Bytes>"; + $result .= '
'; + } + else { + throw new \LogicException('Bug'); + } + + return $result; + }; + echo "

Message Headers

+
".StringUtil::encodeHTML($this->getHeaderString())."
+

Message Body

".$dumpBody($this->body, 2); + + exit; + } } -- 2.20.1