mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 11:44:38 +03:00
expose fewer internals in packages, for easier software reuse
- prometheus is now behind an interface, they aren't dependencies for the reusable components anymore. - some dependencies have been inverted: instead of packages importing a main package to get configuration, the main package now sets configuration in these packages. that means fewer internals are pulled in. - some functions now have new parameters for values that were retrieved from package "mox-".
This commit is contained in:
27
message/decode.go
Normal file
27
message/decode.go
Normal file
@ -0,0 +1,27 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/encoding/ianaindex"
|
||||
)
|
||||
|
||||
// DecodeReader returns a reader that reads from r, decoding as charset. If
|
||||
// charset is empty, us-ascii, utf-8 or unknown, the original reader is
|
||||
// returned and no decoding takes place.
|
||||
func DecodeReader(charset string, r io.Reader) io.Reader {
|
||||
switch strings.ToLower(charset) {
|
||||
case "", "us-ascii", "utf-8":
|
||||
return r
|
||||
}
|
||||
enc, _ := ianaindex.MIME.Encoding(charset)
|
||||
if enc == nil {
|
||||
enc, _ = ianaindex.IANA.Encoding(charset)
|
||||
}
|
||||
// todo: ianaindex doesn't know all encodings, e.g. gb2312. should we transform them, with which code?
|
||||
if enc == nil {
|
||||
return r
|
||||
}
|
||||
return enc.NewDecoder().Reader(r)
|
||||
}
|
Reference in New Issue
Block a user