Functions
AddExtensionType
function
#
AddExtensionType sets the MIME type associated with
the extension ext to typ. The extension should begin with
a leading dot, as in ".html".
func AddExtensionType(ext string, typ string) error
Decode
method
#
Decode decodes an RFC 2047 encoded-word.
func (d *WordDecoder) Decode(word string) (string, error)
Encode
method
#
Encode returns the encoded-word form of s. If s is ASCII without special
characters, it is returned unchanged. The provided charset is the IANA
charset name of s. It is case insensitive.
func (e WordEncoder) Encode(charset string, s string) string
ExtensionsByType
function
#
ExtensionsByType returns the extensions known to be associated with the MIME
type typ. The returned extensions will each begin with a leading dot, as in
".html". When typ has no associated extensions, ExtensionsByType returns an
nil slice.
func ExtensionsByType(typ string) ([]string, error)
FormatMediaType
function
#
FormatMediaType serializes mediatype t and the parameters
param as a media type conforming to RFC 2045 and RFC 2616.
The type and parameter names are written in lower-case.
When any of the arguments result in a standard violation then
FormatMediaType returns the empty string.
func FormatMediaType(t string, param map[string]string) string
ParseMediaType
function
#
ParseMediaType parses a media type value and any optional
parameters, per RFC 1521. Media types are the values in
Content-Type and Content-Disposition headers (RFC 2183).
On success, ParseMediaType returns the media type converted
to lowercase and trimmed of white space and a non-nil map.
If there is an error parsing the optional parameter,
the media type will be returned along with the error
[ErrInvalidMediaParameter].
The returned map, params, maps from the lowercase
attribute to the attribute value with its case preserved.
func ParseMediaType(v string) (mediatype string, params map[string]string, err error)
TypeByExtension
function
#
TypeByExtension returns the MIME type associated with the file extension ext.
The extension ext should begin with a leading dot, as in ".html".
When ext has no associated type, TypeByExtension returns "".
Extensions are looked up first case-sensitively, then case-insensitively.
The built-in table is small but on unix it is augmented by the local
system's MIME-info database or mime.types file(s) if available under one or
more of these names:
/usr/local/share/mime/globs2
/usr/share/mime/globs2
/etc/mime.types
/etc/apache2/mime.types
/etc/apache/mime.types
On Windows, MIME types are extracted from the registry.
Text types have the charset parameter set to "utf-8" by default.
func TypeByExtension(ext string) string
bEncode
method
#
bEncode encodes s using base64 encoding and writes it to buf.
func (e WordEncoder) bEncode(buf *strings.Builder, charset string, s string)
checkMediaTypeDisposition
function
#
func checkMediaTypeDisposition(s string) error
closeWord
function
#
closeWord writes the end of an encoded-word into buf.
func closeWord(buf *strings.Builder)
consumeMediaParam
function
#
func consumeMediaParam(v string) (param string, value string, rest string)
consumeToken
function
#
consumeToken consumes a token from the beginning of provided
string, per RFC 2045 section 5.1 (referenced from 2183), and return
the token consumed and the rest of the string. Returns ("", v) on
failure to consume at least one character.
func consumeToken(v string) (token string, rest string)
consumeValue
function
#
consumeValue consumes a "value" per RFC 2045, where a value is
either a 'token' or a 'quoted-string'. On success, consumeValue
returns the value consumed (and de-quoted/escaped, if a
quoted-string) and the rest of the string. On failure, returns
("", v).
func consumeValue(v string) (value string, rest string)
convert
method
#
func (d *WordDecoder) convert(buf *strings.Builder, charset string, content []byte) error
decode
function
#
func decode(encoding byte, text string) ([]byte, error)
decode2231Enc
function
#
func decode2231Enc(v string) (string, bool)
encodeWord
method
#
encodeWord encodes a string into an encoded-word.
func (e WordEncoder) encodeWord(charset string, s string) string
fromHex
function
#
func fromHex(b byte) (byte, error)
hasNonWhitespace
function
#
hasNonWhitespace reports whether s (assumed to be ASCII) contains at least
one byte of non-whitespace.
func hasNonWhitespace(s string) bool
init
function
#
func init()
init
function
#
func init()
init
function
#
func init()
init
function
#
func init()
init
function
#
func init()
init
function
#
func init()
initMime
function
#
func initMime()
initMimeForTests
function
#
func initMimeForTests() map[string]string
initMimeForTests
function
#
func initMimeForTests() map[string]string
initMimeForTests
function
#
func initMimeForTests() map[string]string
initMimePlan9
function
#
func initMimePlan9()
initMimeUnix
function
#
func initMimeUnix()
initMimeWindows
function
#
func initMimeWindows()
isNotTokenChar
function
#
func isNotTokenChar(r rune) bool
isTSpecial
function
#
isTSpecial reports whether rune is in 'tspecials' as defined by RFC
1521 and RFC 2045.
func isTSpecial(r rune) bool
isToken
function
#
isToken reports whether s is a 'token' as defined by RFC 1521
and RFC 2045.
func isToken(s string) bool
isTokenChar
function
#
isTokenChar reports whether rune is in 'token' as defined by RFC
1521 and RFC 2045.
func isTokenChar(r rune) bool
isUTF8
function
#
func isUTF8(charset string) bool
ishex
function
#
func ishex(c byte) bool
loadMimeFile
function
#
func loadMimeFile(filename string)
loadMimeFile
function
#
func loadMimeFile(filename string)
loadMimeGlobsFile
function
#
func loadMimeGlobsFile(filename string) error
needsEncoding
function
#
func needsEncoding(s string) bool
openWord
method
#
openWord writes the beginning of an encoded-word into buf.
func (e WordEncoder) openWord(buf *strings.Builder, charset string)
percentHexUnescape
function
#
func percentHexUnescape(s string) (string, error)
qDecode
function
#
qDecode decodes a Q encoded string.
func qDecode(s string) ([]byte, error)
qEncode
method
#
qEncode encodes s using Q encoding and writes it to buf. It splits the
encoded-words when necessary.
func (e WordEncoder) qEncode(buf *strings.Builder, charset string, s string)
readHexByte
function
#
readHexByte returns the byte from its quoted-printable representation.
func readHexByte(a byte, b byte) (byte, error)
setExtensionType
function
#
func setExtensionType(extension string, mimeType string) error
setMimeTypes
function
#
setMimeTypes is used by initMime's non-test path, and by tests.
func setMimeTypes(lowerExt map[string]string, mixExt map[string]string)
splitWord
method
#
splitWord closes the current encoded-word and opens a new one.
func (e WordEncoder) splitWord(buf *strings.Builder, charset string)
unhex
function
#
func unhex(c byte) byte
writeQString
function
#
writeQString encodes s using Q encoding and writes it to buf.
func writeQString(buf *strings.Builder, s string)