Documentation ¶
Overview ¶
Package quotedprintable implements quoted-printable encoding as specified by RFC 2045.
Index ¶
Examples ¶
Constants ¶
const ( // BEncoding represents Base64 encoding scheme as defined by RFC 2045. BEncoding = WordEncoder('b') // QEncoding represents the Q-encoding scheme as defined by RFC 2047. QEncoding = WordEncoder('q') )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a quoted-printable decoder.
type WordDecoder ¶
type WordDecoder struct { // CharsetReader, if non-nil, defines a function to generate // charset-conversion readers, converting from the provided // charset into UTF-8. // Charsets are always lower-case. utf-8, iso-8859-1 and us-ascii charsets // are handled by default. // One of the the CharsetReader's result values must be non-nil. CharsetReader func(charset string, input io.Reader) (io.Reader, error) }
A WordDecoder decodes MIME headers containing RFC 2047 encoded-words.
func (*WordDecoder) Decode ¶
func (d *WordDecoder) Decode(word string) (string, error)
Decode decodes an encoded-word. If word is not a valid RFC 2047 encoded-word, word is returned unchanged.
Example ¶
dec := new(WordDecoder) header, err := dec.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=") if err != nil { panic(err) } fmt.Println(header) dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) { switch charset { case "x-case": // Fake character set for example. // Real use would integrate with packages such // as code.google.com/p/go-charset content, err := ioutil.ReadAll(input) if err != nil { return nil, err } return bytes.NewReader(bytes.ToUpper(content)), nil } return nil, fmt.Errorf("unhandled charset %q", charset) } header, err = dec.Decode("=?x-case?q?hello!?=") if err != nil { panic(err) } fmt.Println(header)
Output: ¡Hola, señor! HELLO!
func (*WordDecoder) DecodeHeader ¶
func (d *WordDecoder) DecodeHeader(header string) (string, error)
DecodeHeader decodes all encoded-words of the given string. It returns an error if and only if CharsetReader of d returns an error.
Example ¶
dec := new(WordDecoder) header, err := dec.DecodeHeader("=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>") if err != nil { panic(err) } fmt.Println(header) header, err = dec.DecodeHeader("=?utf-8?q?=C2=A1Hola,?= =?utf-8?q?_se=C3=B1or!?=") if err != nil { panic(err) } fmt.Println(header) dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) { switch charset { case "x-case": // Fake character set for example. // Real use would integrate with packages such // as code.google.com/p/go-charset content, err := ioutil.ReadAll(input) if err != nil { return nil, err } return bytes.NewReader(bytes.ToUpper(content)), nil } return nil, fmt.Errorf("unhandled charset %q", charset) } header, err = dec.DecodeHeader("=?x-case?q?hello_?= =?x-case?q?world!?=") if err != nil { panic(err) } fmt.Println(header)
Output: Éric <eric@example.org>, Anaïs <anais@example.org> ¡Hola, señor! HELLO WORLD!
type WordEncoder ¶
type WordEncoder byte
A WordEncoder is a RFC 2047 encoded-word encoder.
func (WordEncoder) Encode ¶
func (e WordEncoder) Encode(charset, s string) string
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.
Example ¶
fmt.Println(QEncoding.Encode("utf-8", "¡Hola, señor!")) fmt.Println(QEncoding.Encode("utf-8", "Hello!")) fmt.Println(BEncoding.Encode("UTF-8", "¡Hola, señor!")) fmt.Println(QEncoding.Encode("ISO-8859-1", "Caf\xE9"))
Output: =?utf-8?q?=C2=A1Hola,_se=C3=B1or!?= Hello! =?UTF-8?b?wqFIb2xhLCBzZcOxb3Ih?= =?ISO-8859-1?q?Caf=E9?=
type Writer ¶
type Writer struct { // Binary mode treats the writer's input as pure binary and processes end of // line bytes as binary data. Binary bool // contains filtered or unexported fields }
A Writer is a quoted-printable writer that implements io.WriteCloser.