quotedprintable.v2: gopkg.in/alexcesaro/quotedprintable.v2 Index | Examples | Files | Directories

package quotedprintable

import "gopkg.in/alexcesaro/quotedprintable.v2"

Package quotedprintable implements quoted-printable and message header encoding as specified by RFC 2045 and RFC 2047.



Package Files

header.go quotedprintable.go

func Decode Uses

func Decode(dst, src []byte) (n int, err error)

Decode decodes src into at most MaxDecodedLen(len(src)) bytes to dst, returning the actual number of bytes written to dst.

func DecodeHeader Uses

func DecodeHeader(header string) (text, charset string, err error)

DecodeHeader decodes a MIME header by decoding all encoded-words of the header. The returned text is encoded in the returned charset. Text is not necessarily encoded in UTF-8. Returned charset is always upper case. This function does not support decoding headers with multiple encoded-words using different charsets.


// text is not encoded in UTF-8 but in ISO-8859-1
text, charset, err := DecodeHeader("=?ISO-8859-1?Q?Caf=C3?=")
if err != nil {
fmt.Printf("Text: %q, charset: %q", text, charset)


Text: "Caf\xc3", charset: "ISO-8859-1"

func DecodeString Uses

func DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the quoted-printable string s.


str := "=C2=A1Hola, se=C3=B1or!"
data, err := DecodeString(str)
if err != nil {
    fmt.Println("error:", err)
fmt.Printf("%s\n", data)


¡Hola, señor!

func Encode Uses

func Encode(dst, src []byte) int

Encode encodes src into at most MaxEncodedLen(len(src)) bytes to dst, returning the actual number of bytes written to dst.

func EncodeToString Uses

func EncodeToString(src []byte) string

EncodeToString returns the quoted-printable encoding of src.


data := []byte("¡Hola, señor!")
str := EncodeToString(data)


=C2=A1Hola, se=C3=B1or!

func MaxDecodedLen Uses

func MaxDecodedLen(n int) int

MaxDecodedLen returns the maximum length of a decoding of n source bytes.

func MaxEncodedLen Uses

func MaxEncodedLen(n int) int

MaxEncodedLen returns the maximum length of an encoding of n source bytes.

func NeedsEncoding Uses

func NeedsEncoding(s string) bool

NeedsEncoding returns whether the given header content needs to be encoded into an encoded-words.

func NewDecoder Uses

func NewDecoder(r io.Reader) io.Reader

NewDecoder returns a new quoted-printable stream decoder.

func NewEncoder Uses

func NewEncoder(w io.Writer) io.Writer

NewEncoder returns a new quoted-printable stream encoder. Data written to the returned writer will be encoded and then written to w.


input := []byte("Café")
encoder := NewEncoder(os.Stdout)



type Encoding Uses

type Encoding string

Encoding represents the encoding used in encoded-words. It must be one of the two encodings defined in RFC 2047 ("B" or "Q" encoding).

const (
    // Q represents the Q-encoding defined in RFC 2047.
    Q   Encoding = "Q"
    // B represents the Base64 encoding defined in RFC 2045.
    B   Encoding = "B"

func (Encoding) NewHeaderEncoder Uses

func (enc Encoding) NewHeaderEncoder(charset string) *HeaderEncoder

NewHeaderEncoder returns a new HeaderEncoder to encode strings in the specified charset.

type HeaderEncoder Uses

type HeaderEncoder struct {
    // contains filtered or unexported fields

A HeaderEncoder is an RFC 2047 encoded-word encoder.

func (*HeaderEncoder) Encode Uses

func (e *HeaderEncoder) Encode(s string) string

Encode encodes a string to be used as a MIME header value.


internalPackage internal contains quoted-printable internals shared by mime and mime/quotedprintable.

Package quotedprintable imports 9 packages (graph) and is imported by 5 packages. Updated 2016-07-20. Refresh now. Tools for package owners.