diff --git a/internal/imap/mailbox_message.go b/internal/imap/mailbox_message.go
index 5b970461..ce912de6 100644
--- a/internal/imap/mailbox_message.go
+++ b/internal/imap/mailbox_message.go
@@ -29,6 +29,7 @@ import (
"regexp"
"sort"
"strings"
+ "text/template"
"time"
pmcrypto "github.com/ProtonMail/gopenpgp/crypto"
@@ -488,23 +489,43 @@ func (im *imapMailbox) fetchMessage(m *pmapi.Message) (err error) {
return
}
+const customMessageTemplate = `
+
+
+
+
+
Decryption error
+ Decryption of this message's encrypted content failed.
+
{{.Error}}
+
+
+ {{if .AttachBody}}
+
+ {{- end}}
+
+
+`
+
+type customMessageData struct {
+ Error string
+ AttachBody bool
+ Body string
+}
+
func (im *imapMailbox) customMessage(m *pmapi.Message, err error, attachBody bool) {
- // Assuming quoted-printable.
- origBody := strings.Replace(m.Body, "=", "=3D", -1)
- m.Body = "Content-Type: text/html\r\n"
- m.Body = "\n\n"
- m.Body += "\n
Decryption errorDecryption of this message's encrypted content failed.
\n"
- m.Body += err.Error()
- m.Body += "\n
\n"
+ t := template.Must(template.New("customMessage").Parse(customMessageTemplate))
- if attachBody {
- m.Body += "\n"
- m.Body += origBody
- m.Body += "\n
\n"
- }
+ b := new(bytes.Buffer)
+ t.Execute(b, customMessageData{
+ Error: err.Error(),
+ AttachBody: attachBody,
+ Body: m.Body,
+ })
- m.Body += ""
- m.MIMEType = "text/html"
+ 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.
if m.Header == nil {