plugins/viewhtml: convert mailto links

This commit is contained in:
Simon Ser 2020-02-25 14:06:10 +01:00
parent 62660f8d1d
commit 02faf6174b
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 32 additions and 9 deletions

View file

@ -431,6 +431,7 @@ func handleCompose(ctx *koushin.Context, msg *OutgoingMessage, draft *messagePat
func handleComposeNew(ctx *koushin.Context) error {
// These are common mailto URL query parameters
// TODO: cc, bcc
return handleCompose(ctx, &OutgoingMessage{
To: strings.Split(ctx.QueryParam("to"), ","),
Subject: ctx.QueryParam("subject"),

View file

@ -70,6 +70,14 @@ var allowedStyles = map[string]bool{
"list-style-position": true,
}
var mailtoParams = []string{
"subject",
"cc",
"bcc",
"body",
"in-reply-to",
}
type sanitizer struct {
msg *koushinbase.IMAPMessage
}
@ -80,17 +88,31 @@ func (san *sanitizer) sanitizeImageURL(src string) string {
return "about:blank"
}
// TODO: mid support?
if !strings.EqualFold(u.Scheme, "cid") || san.msg == nil {
switch strings.ToLower(u.Scheme) {
case "mailto":
mailtoQuery := u.Query()
composeURL := url.URL{Path: "/compose"}
composeQuery := make(url.Values)
composeQuery.Set("to", u.Opaque)
for _, k := range mailtoParams {
if v := mailtoQuery.Get(k); v != "" {
composeQuery.Set(k, v)
}
}
composeURL.RawQuery = composeQuery.Encode()
return composeURL.String()
case "cid":
// TODO: mid support?
part := san.msg.PartByID(u.Opaque)
if part == nil || !strings.HasPrefix(part.MIMEType, "image/") {
return "about:blank"
}
return part.URL(true).String()
default:
return "about:blank"
}
part := san.msg.PartByID(u.Opaque)
if part == nil || !strings.HasPrefix(part.MIMEType, "image/") {
return "about:blank"
}
return part.URL(true).String()
}
func (san *sanitizer) sanitizeCSSDecls(decls []*css.Declaration) []*css.Declaration {