Resize e-mail iframe with content
This commit is contained in:
parent
af5ffd12f9
commit
721c3ce3eb
4 changed files with 14 additions and 1 deletions
8
plugins/base/public/assets/script.js
Normal file
8
plugins/base/public/assets/script.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
var emailFrame = document.getElementById("email-frame");
|
||||
if (emailFrame) {
|
||||
var resizeFrame = function() {
|
||||
emailFrame.style.height = emailFrame.contentWindow.document.documentElement.scrollHeight + "px";
|
||||
};
|
||||
emailFrame.addEventListener("load", resizeFrame);
|
||||
emailFrame.contentWindow.addEventListener("resize", resizeFrame);
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
<script src="/plugins/base/assets/script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -114,7 +114,8 @@
|
|||
<p><a href="{{.Message.Uid}}/reply?part={{.PartPath}}">Reply</a></p>
|
||||
{{if .IsHTML}}
|
||||
<!-- TODO: add a src fallback -->
|
||||
<iframe srcdoc="{{.Body}}" sandbox></iframe>
|
||||
<!-- allow-same-origin is required to resize the frame with its content -->
|
||||
<iframe id="email-frame" srcdoc="{{.Body}}" sandbox="allow-same-origin"></iframe>
|
||||
{{else}}
|
||||
<pre>{{.Body}}</pre>
|
||||
{{end}}
|
||||
|
|
|
@ -247,6 +247,9 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
|
|||
isHTML := false
|
||||
if strings.EqualFold(mimeType, "text/html") {
|
||||
p := bluemonday.UGCPolicy()
|
||||
// TODO: be more strict
|
||||
p.AllowElements("style")
|
||||
p.AllowAttrs("style")
|
||||
body = p.Sanitize(body)
|
||||
isHTML = true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue