Skip to content

Commit

Permalink
feat: Expose ParseMediaType
Browse files Browse the repository at this point in the history
The standard library mime.ParseMediaType does not handle some edge
cases. This commit exposes a package-level ParseMediaType function,
allowing the standard library calls to be replaced with a custom
function.
  • Loading branch information
jameshoulahan committed Oct 19, 2022
1 parent dde421c commit ccc4a12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions imap/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package imap

import (
"bytes"
"mime"
"strings"

"github.com/ProtonMail/gluon/rfc822"
Expand Down Expand Up @@ -147,7 +146,7 @@ func getMIMEInfo(section *rfc822.Section) (string, string, map[string]string, er
}

func addDispInfo(c *paramList, writer parListWriter, header *rfc822.Header) {
if contentDisp, contentDispParams, err := mime.ParseMediaType(header.Get("Content-Disposition")); err == nil {
if contentDisp, contentDispParams, err := rfc822.ParseMediaType(header.Get("Content-Disposition")); err == nil {
writer.writeByte(' ')
fields := c.newChildList(writer)
fields.addString(writer, contentDisp).addMap(writer, contentDispParams)
Expand Down
5 changes: 4 additions & 1 deletion rfc822/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"strings"
)

// ParseMediaType parses a MIME media type.
var ParseMediaType = mime.ParseMediaType

type MIMEType string

const (
Expand Down Expand Up @@ -40,7 +43,7 @@ func ParseMIMEType(val string) (MIMEType, map[string]string, error) {
val = string(TextPlain)
}

mimeType, mimeParams, err := mime.ParseMediaType(val)
mimeType, mimeParams, err := ParseMediaType(val)
if err != nil {
return "", nil, err
}
Expand Down

0 comments on commit ccc4a12

Please sign in to comment.