feat(GODT-3113): Do not render HTML for attachment.

This commit is contained in:
Romain Le Jeune
2023-11-10 08:36:46 +00:00
parent 2a78b5c144
commit 0303ba38e8
4 changed files with 9 additions and 18 deletions

View File

@ -197,6 +197,9 @@ func convertForeignEncodings(p *parser.Parser) error {
return p.NewWalker().
RegisterContentTypeHandler("text/html", func(p *parser.Part) error {
if p.IsAttachment() {
return nil
}
if err := p.ConvertToUTF8(); err != nil {
return err
}
@ -313,24 +316,14 @@ func collectBodyParts(p *parser.Parser, preferredContentType string) (parser.Par
return bestChoice(childParts, preferredContentType), nil
}).
RegisterRule("text/plain", func(p *parser.Part, visit parser.Visit) (interface{}, error) {
disp, _, err := p.ContentDisposition()
if err != nil {
disp = ""
}
if disp == "attachment" {
if p.IsAttachment() {
return parser.Parts{}, nil
}
return parser.Parts{p}, nil
}).
RegisterRule("text/html", func(p *parser.Part, visit parser.Visit) (interface{}, error) {
disp, _, err := p.ContentDisposition()
if err != nil {
disp = ""
}
if disp == "attachment" {
if p.IsAttachment() {
return parser.Parts{}, nil
}

View File

@ -33,7 +33,7 @@ func (h *handler) matchPart(p *Part) bool {
}
func (h *handler) matchPartSkipAttachment(p *Part) bool {
return !p.isAttachment() && h.matchPart(p)
return !p.IsAttachment() && h.matchPart(p)
}
func (h *handler) matchType(p *Part) bool {

View File

@ -209,7 +209,7 @@ func (p *Part) isMultipartMixedOrRelated() bool {
return t == "multipart/mixed" || t == "multipart/related"
}
func (p *Part) isAttachment() bool {
func (p *Part) IsAttachment() bool {
disp, _, err := p.ContentDisposition()
if err != nil {
disp = ""