qp

package module
v0.0.0-...-4c33c0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2014 License: MIT Imports: 8 Imported by: 0

README

This repository contains the package mime/qp that provides functions to deal with quoted-printable and email header encoding.

Documentation

Documentation

Overview

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

Index

Examples

Constants

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

Variables

View Source
var StdWordEncoder = &WordEncoder{"UTF-8", Q, true}

StdWordEncoder is a RFC 2047 encoder for UTF-8 strings using Q encoding.

Functions

func Decode

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

func DecodeHeader(header string) (text string, charset string, err error)
Example
// 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.Println("error:", err)
	return
}
fmt.Printf("Text: %q, charset: %q", text, charset)
Output:

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

func DecodeString

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

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

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

¡Hola, señor!

func DecodeWord

func DecodeWord(s string) (text string, charset string, err error)

DecodeWord decodes an encoded-word returning the decoded text and the charset. This function does not do any charset conversion, the returned text is encoded in the returned charset. So text is not necessarily encoded in UTF-8.

func Encode

func Encode(dst, src []byte) (n int)

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

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns the quoted-printable encoding of src.

Example
data := []byte("¡Hola, señor!")
str := EncodeToString(data)
fmt.Println(str)
Output:

=C2=A1Hola, se=C3=B1or!

func MaxDecodedLen

func MaxDecodedLen(n int) int

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

func MaxEncodedLen

func MaxEncodedLen(n int) int

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

func NewDecoder

func NewDecoder(r io.Reader) io.Reader

NewDecoder returns a new quoted-printable stream decoder.

func NewEncoder

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.

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

Caf=C3=A9

Types

type WordEncoder

type WordEncoder struct {
	// contains filtered or unexported fields
}

WordEncoder in an encoder for encoded words.

func NewWordEncoder

func NewWordEncoder(charset string, enc string) (*WordEncoder, error)

NewWordEncoder returns a new WordEncoder to encode strings in the specified charset using the encoding enc.

Example
e, err := NewWordEncoder("UTF-8", B)
if err != nil {
	fmt.Println("error:", err)
	return
}
fmt.Printf(e.EncodeHeader("Caf\xc3"))
Output:

=?UTF-8?B?Q2Fmww==?=

func (*WordEncoder) EncodeHeader

func (e *WordEncoder) EncodeHeader(s string) string

EncodeHeader encodes a string to be used as a MIME header value. It works like EncodeWord but it encodes the input only if it contains non-ASCII characters.

func (*WordEncoder) EncodeWord

func (e *WordEncoder) EncodeWord(s string) string

EncodeWord encodes a string into an encoded-word.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL