fix(GODT-3176): assume inline if content id is present.

This commit is contained in:
Romain Le Jeune
2024-01-18 16:45:08 +00:00
committed by Jakub Cuth
parent 76d257af21
commit 773a230d14
3 changed files with 77 additions and 4 deletions

View File

@ -119,7 +119,7 @@ func parse(p *parser.Parser, allowInvalidAddressLists bool) (Message, error) {
}
if err := patchInlineImages(p); err != nil {
return Message{}, err
return Message{}, errors.Wrap(err, "patching inline images failed")
}
m, err := parseMessageHeader(p.Root().Header, allowInvalidAddressLists)
@ -671,11 +671,10 @@ func patchInlineImages(p *parser.Parser) error {
if rfc822.MIMEType(contentType) == rfc822.TextPlain {
result[i] = &inlinePatchBodyOnly{part: curPart, contentTypeMap: contentTypeMap}
} else if strings.HasPrefix(contentType, "image/") {
disposition, _, err := curPart.ContentDisposition()
disposition, err := getImageContentDisposition(curPart)
if err != nil {
return fmt.Errorf("failted to get content disposition for child %v:%w", i, err)
return fmt.Errorf("failed to get content disposition for child %v:%w", i, err)
}
if disposition == "inline" && !curPart.HasContentID() {
if rfc822.MIMEType(prevContentType) == rfc822.TextPlain {
result[i-1] = &inlinePatchBodyWithInlineImage{
@ -707,6 +706,23 @@ func patchInlineImages(p *parser.Parser) error {
return nil
}
func getImageContentDisposition(curPart *parser.Part) (string, error) {
disposition, _, err := curPart.ContentDisposition()
if err == nil {
return disposition, nil
}
if curPart.Header.Get("Content-Disposition") != "" {
return "", err
}
if curPart.HasContentID() {
return "inline", nil
}
return "attachment", nil
}
type inlinePatchJob interface {
Patch()
}