processDocumentPart handles MessagePartTypeDocument. Images with InlineData are transcoded; other already-resolved documents pass through.
(part MessagePart)
| 190 | // processDocumentPart handles MessagePartTypeDocument. |
| 191 | // Images with InlineData are transcoded; other already-resolved documents pass through. |
| 192 | func processDocumentPart(part MessagePart) (Document, *ImageResizeResult, error) { |
| 193 | if part.Document == nil { |
| 194 | return Document{}, nil, errors.New("ProcessAttachment: document part has nil Document field") |
| 195 | } |
| 196 | doc := *part.Document |
| 197 | |
| 198 | if len(doc.Source.InlineData) > 0 { |
| 199 | if IsImageMimeType(doc.MimeType) { |
| 200 | return transcodeImageWithMeta(doc.Name, doc.Source.InlineData, doc.MimeType) |
| 201 | } |
| 202 | return doc, nil, nil |
| 203 | } |
| 204 | |
| 205 | if doc.Source.InlineText != "" { |
| 206 | return doc, nil, nil |
| 207 | } |
| 208 | |
| 209 | return Document{}, nil, fmt.Errorf("ProcessAttachment: document %q has no inline content (InlineData and InlineText are both empty)", doc.Name) |
| 210 | } |
| 211 | |
| 212 | // transcodeImageWithMeta runs bytes through ResizeImage to normalise the image |
| 213 | // to JPEG or PNG within provider limits, then wraps the result in a Document. |
no test coverage detected