iconv.go 654 B

123456789101112131415161718192021222324
  1. // iconv enables using GNU iconv for converting 7bit to UTF-8.
  2. // iconv supports a larger range of encodings.
  3. // It's a cgo package, the build system needs have Gnu library headers available.
  4. // when importing, place an underscore _ in front to import for side-effects
  5. package iconv
  6. import (
  7. "fmt"
  8. "io"
  9. "github.com/flashmob/go-guerrilla/mail"
  10. ico "gopkg.in/iconv.v1"
  11. )
  12. func init() {
  13. mail.Dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
  14. if cd, err := ico.Open("UTF-8", charset); err == nil {
  15. r := ico.NewReader(cd, input, 32)
  16. return r, nil
  17. }
  18. return nil, fmt.Errorf("unhandled charset %q", charset)
  19. }
  20. }