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

View File

@ -33,7 +33,7 @@ func (h *handler) matchPart(p *Part) bool {
} }
func (h *handler) matchPartSkipAttachment(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 { 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" return t == "multipart/mixed" || t == "multipart/related"
} }
func (p *Part) isAttachment() bool { func (p *Part) IsAttachment() bool {
disp, _, err := p.ContentDisposition() disp, _, err := p.ContentDisposition()
if err != nil { if err != nil {
disp = "" disp = ""

View File

@ -184,9 +184,7 @@ Feature: SMTP sending of PLAIN messages to Internal recipient
Content-Disposition: attachment; filename="index.html" Content-Disposition: attachment; filename="index.html"
Content-Transfer-Encoding: base64 Content-Transfer-Encoding: base64
IDwhRE9DVFlQRSBodG1sPg0KPGh0bWw+DQo8aGVhZD4NCjx0aXRsZT5QYWdlIFRpdGxlPC90 PCFET0NUWVBFIGh0bWw+
aXRsZT4NCjwvaGVhZD4NCjxib2R5Pg0KDQo8aDE+TXkgRmlyc3QgSGVhZGluZzwvaDE+DQo8
cD5NeSBmaXJzdCBwYXJhZ3JhcGguPC9wPg0KDQo8L2JvZHk+DQo8L2h0bWw+IA==
--------------WI90RPIYF20K6dGXjs7dm2mi --------------WI90RPIYF20K6dGXjs7dm2mi
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;
name="test.docx" name="test.docx"
@ -669,7 +667,7 @@ Feature: SMTP sending of PLAIN messages to Internal recipient
"content-disposition": "attachment", "content-disposition": "attachment",
"content-disposition-filename": "index.html", "content-disposition-filename": "index.html",
"transfer-encoding": "base64", "transfer-encoding": "base64",
"body-is": "PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+Cjx0aXRsZT5QYWdlIFRpdGxlPC90aXRsZT4KPC9o\r\nZWFkPgo8Ym9keT4KCjxoMT5NeSBGaXJzdCBIZWFkaW5nPC9oMT4KPHA+TXkgZmlyc3QgcGFyYWdy\r\nYXBoLjwvcD4KCgogPC9ib2R5PjwvaHRtbD4=" "body-is": "PCFET0NUWVBFIGh0bWw+"
}, },
{ {
"content-type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "content-type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",