Resize e-mail iframe with content

This commit is contained in:
Simon Ser 2019-12-18 16:11:45 +01:00
parent af5ffd12f9
commit 721c3ce3eb
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 14 additions and 1 deletions

View 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);
}

View file

@ -1,2 +1,3 @@
<script src="/plugins/base/assets/script.js"></script>
</body> </body>
</html> </html>

View file

@ -114,7 +114,8 @@
<p><a href="{{.Message.Uid}}/reply?part={{.PartPath}}">Reply</a></p> <p><a href="{{.Message.Uid}}/reply?part={{.PartPath}}">Reply</a></p>
{{if .IsHTML}} {{if .IsHTML}}
<!-- TODO: add a src fallback --> <!-- 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}} {{else}}
<pre>{{.Body}}</pre> <pre>{{.Body}}</pre>
{{end}} {{end}}

View file

@ -247,6 +247,9 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
isHTML := false isHTML := false
if strings.EqualFold(mimeType, "text/html") { if strings.EqualFold(mimeType, "text/html") {
p := bluemonday.UGCPolicy() p := bluemonday.UGCPolicy()
// TODO: be more strict
p.AllowElements("style")
p.AllowAttrs("style")
body = p.Sanitize(body) body = p.Sanitize(body)
isHTML = true isHTML = true
} }