coding

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxQPLineLen = 1024

MaxQPLineLen is the maximum line length we allow before inserting `=\r\n`. Prevents buffer overflows in mime/quotedprintable.Reader.

Variables

This section is empty.

Functions

func ConvertToUTF8String

func ConvertToUTF8String(charset string, textBytes []byte) (string, error)

ConvertToUTF8String uses the provided charset to decode a slice of bytes into a normal UTF-8 string.

func DecodeExtHeader

func DecodeExtHeader(input string) string

DecodeExtHeader decodes a single line (per RFC 2047, aka Message Header Extensions) using Golang's mime.WordDecoder.

func FindCharsetInHTML

func FindCharsetInHTML(html string) string

FindCharsetInHTML looks for charset in the HTML meta tag (v4.01 and v5).

func FromIDHeader

func FromIDHeader(v string) string

FromIDHeader decodes a Content-ID or Message-ID header value (RFC 2392) into a utf-8 string. Example: "<foo%3fbar+baz>" becomes "foo?bar baz".

func NewCharsetReader

func NewCharsetReader(charset string, input io.Reader) (io.Reader, error)

NewCharsetReader generates charset-conversion readers, converting from the provided charset into UTF-8. CharsetReader is a factory signature defined by Go's mime.WordDecoder.

This function is similar to: https://godoc.org/golang.org/x/net/html/charset#NewReaderLabel

func NewExtMimeDecoder

func NewExtMimeDecoder() *mime.WordDecoder

NewExtMimeDecoder creates new MIME word decoder which allows decoding of additional charsets.

func RFC2047Decode

func RFC2047Decode(s string) string

RFC2047Decode returns a decoded string if the input uses RFC2047 encoding, otherwise it will return the input.

RFC2047 Example: `=?UTF-8?B?bmFtZT0iw7DCn8KUwoo=?=`

func ToIDHeader

func ToIDHeader(v string) string

ToIDHeader encodes a Content-ID or Message-ID header value (RFC 2392) from a utf-8 string.

Types

type Base64Cleaner

type Base64Cleaner struct {
	// Report of non-whitespace characters detected while cleaning base64 data.
	Errors []error
	// contains filtered or unexported fields
}

Base64Cleaner improves the tolerance of in Go's built-in base64 decoder by stripping out characters that would cause decoding to fail.

func NewBase64Cleaner

func NewBase64Cleaner(r io.Reader) *Base64Cleaner

NewBase64Cleaner returns a Base64Cleaner object for the specified reader. Base64Cleaner implements the io.Reader interface.

func (*Base64Cleaner) Read

func (bc *Base64Cleaner) Read(p []byte) (n int, err error)

Read method for io.Reader interface.

type QPCleaner

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

QPCleaner scans quoted printable content for invalid characters and encodes them so that Go's quoted-printable decoder does not abort with an error.

func NewQPCleaner

func NewQPCleaner(r io.Reader) *QPCleaner

NewQPCleaner returns a QPCleaner for the specified reader.

func (*QPCleaner) Read

func (qp *QPCleaner) Read(dest []byte) (n int, err error)

Read method for io.Reader interface.

Jump to

Keyboard shortcuts

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