mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
fix: custom message bad pgp using template
This commit is contained in:
@ -29,6 +29,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pmcrypto "github.com/ProtonMail/gopenpgp/crypto"
|
pmcrypto "github.com/ProtonMail/gopenpgp/crypto"
|
||||||
@ -488,23 +489,43 @@ func (im *imapMailbox) fetchMessage(m *pmapi.Message) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *imapMailbox) customMessage(m *pmapi.Message, err error, attachBody bool) {
|
const customMessageTemplate = `
|
||||||
// Assuming quoted-printable.
|
<html>
|
||||||
origBody := strings.Replace(m.Body, "=", "=3D", -1)
|
<head></head>
|
||||||
m.Body = "Content-Type: text/html\r\n"
|
<body style="font-family: Arial,'Helvetica Neue',Helvetica,sans-serif; font-size: 14px;">
|
||||||
m.Body = "\n<html><head></head><body style=3D\"font-family: Arial,'Helvetica Neue',Helvetica,sans-serif; font-size: 14px; \">\n"
|
<div style="color:#555; background-color:#cf9696; padding:20px; border-radius: 4px;">
|
||||||
m.Body += "<div style=3D\"color:#555; background-color:#cf9696; padding:20px; border-radius: 4px;\" >\n<strong>Decryption error</strong><br/>Decryption of this message's encrypted content failed.<pre>\n"
|
<strong>Decryption error</strong><br/>
|
||||||
m.Body += err.Error()
|
Decryption of this message's encrypted content failed.
|
||||||
m.Body += "\n</pre></div>\n"
|
<pre>{{.Error}}</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
if attachBody {
|
{{if .AttachBody}}
|
||||||
m.Body += "<div style=3D\"color:#333; background-color:#f4f4f4; border: 1px solid #acb0bf; border-radius: 2px; padding:1rem; margin:1rem 0; font-family:monospace; font-size: 1em;\" ><pre>\n"
|
<div style="color:#333; background-color:#f4f4f4; border: 1px solid #acb0bf; border-radius: 2px; padding:1rem; margin:1rem 0; font-family:monospace; font-size: 1em;">
|
||||||
m.Body += origBody
|
<pre>{{.Body}}</pre>
|
||||||
m.Body += "\n</pre></div>\n"
|
</div>
|
||||||
|
{{- end}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
|
type customMessageData struct {
|
||||||
|
Error string
|
||||||
|
AttachBody bool
|
||||||
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Body += "</body></html>"
|
func (im *imapMailbox) customMessage(m *pmapi.Message, err error, attachBody bool) {
|
||||||
m.MIMEType = "text/html"
|
t := template.Must(template.New("customMessage").Parse(customMessageTemplate))
|
||||||
|
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
t.Execute(b, customMessageData{
|
||||||
|
Error: err.Error(),
|
||||||
|
AttachBody: attachBody,
|
||||||
|
Body: m.Body,
|
||||||
|
})
|
||||||
|
|
||||||
|
m.MIMEType = pmapi.ContentTypeHTML
|
||||||
|
m.Body = b.String()
|
||||||
|
|
||||||
// NOTE: we need to set header in custom message header, so we check that is non-nil.
|
// NOTE: we need to set header in custom message header, so we check that is non-nil.
|
||||||
if m.Header == nil {
|
if m.Header == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user