NormalizeImageMediaType lowercases and strips any parameters (e.g. "image/jpeg; charset=binary" -> "image/jpeg") and reports whether the result is a supported image type. Also folds the common "image/jpg" alias onto the canonical "image/jpeg".
(mime string)
| 58 | // result is a supported image type. Also folds the common "image/jpg" |
| 59 | // alias onto the canonical "image/jpeg". |
| 60 | func NormalizeImageMediaType(mime string) (string, bool) { |
| 61 | mt := strings.ToLower(strings.TrimSpace(mime)) |
| 62 | if i := strings.IndexByte(mt, ';'); i >= 0 { |
| 63 | mt = strings.TrimSpace(mt[:i]) |
| 64 | } |
| 65 | if mt == "image/jpg" { |
| 66 | mt = "image/jpeg" |
| 67 | } |
| 68 | return mt, supportedImageMediaTypes[mt] |
| 69 | } |
| 70 | |
| 71 | // DetectImageMediaType sniffs the media type from the leading bytes and |
| 72 | // reports whether it is a supported image. Used when an attachment has |
no outgoing calls