Browse Source

Resize e-mail iframe with content

master
Simon Ser 4 years ago
parent
commit
721c3ce3eb
No known key found for this signature in database GPG Key ID: FDE7BE0E88F5E48
4 changed files with 14 additions and 1 deletions
  1. +8
    -0
      plugins/base/public/assets/script.js
  2. +1
    -0
      plugins/base/public/foot.html
  3. +2
    -1
      plugins/base/public/message.html
  4. +3
    -0
      plugins/base/routes.go

+ 8
- 0
plugins/base/public/assets/script.js 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);
}

+ 1
- 0
plugins/base/public/foot.html View File

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

+ 2
- 1
plugins/base/public/message.html View File

@@ -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}}


+ 3
- 0
plugins/base/routes.go View File

@@ -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…
Cancel
Save