fix(GODT-2887): Inline images with Apple Mail

Fix sending of inline images with Apple Mail when not using rich text.
This commit is contained in:
Leander Beernaert
2023-10-31 11:41:50 +01:00
parent 0f320dbd80
commit 96773f3225
7 changed files with 586 additions and 5 deletions

View File

@ -27,6 +27,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/emersion/go-message"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
"golang.org/x/net/html"
"golang.org/x/net/html/charset"
"golang.org/x/text/encoding"
@ -52,6 +53,14 @@ func (p *Part) ContentType() (string, map[string]string, error) {
return t, params, err
}
func (p *Part) ContentDisposition() (string, map[string]string, error) {
return p.Header.ContentDisposition()
}
func (p *Part) HasContentID() bool {
return len(p.Header.Get("content-id")) != 0
}
func (p *Part) Child(n int) (part *Part, err error) {
if len(p.children) < n {
return nil, errors.New("no such part")
@ -81,6 +90,14 @@ func (p *Part) AddChild(child *Part) {
}
}
func (p *Part) InsertChild(index int, child *Part) {
if p.isMultipartMixedOrRelated() {
p.children = slices.Insert(p.children, index, child)
} else {
p.AddChild(child)
}
}
func (p *Part) ConvertToUTF8() error {
logrus.Trace("Converting part to utf-8")
@ -183,6 +200,15 @@ func (p *Part) isMultipartMixed() bool {
return t == "multipart/mixed"
}
func (p *Part) isMultipartMixedOrRelated() bool {
t, _, err := p.ContentType()
if err != nil {
return false
}
return t == "multipart/mixed" || t == "multipart/related"
}
func getContentHeaders(header message.Header) message.Header {
var res message.Header