rfc822

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 12 Imported by: 17

Documentation

Overview

Package rfc822 implements methods for handling RFC822 messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonASCIIHeaderKey = fmt.Errorf("header key contains invalid characters")
	ErrKeyNotFound       = fmt.Errorf("invalid header key")
	ErrParseHeader       = fmt.Errorf("failed to parse header")
)
View Source
var ErrNoSuchPart = errors.New("no such parts exists")
View Source
var ParseMediaType = mime.ParseMediaType

ParseMediaType parses a MIME media type.

Functions

func EraseHeaderValue added in v0.15.0

func EraseHeaderValue(literal []byte, key string) ([]byte, error)

EraseHeaderValue removes the header from a literal.

func GetHeaderValue

func GetHeaderValue(literal []byte, key string) (string, error)

GetHeaderValue is a helper method that queries a header value in a message literal.

func GetMessageHash added in v0.17.0

func GetMessageHash(b []byte) (string, error)

GetMessageHash returns the hash of the given message. This takes into account: - the Subject header, - the From/To/Cc headers, - the Content-Type header of each (leaf) part, - the Content-Disposition header of each (leaf) part, - the (decoded) body of each part.

func SetHeaderValue

func SetHeaderValue(literal []byte, key, val string) ([]byte, error)

SetHeaderValue is a helper method that sets a header value in a message literal. It does not check whether the existing value already exists.

func SetHeaderValueNoMemCopy added in v0.15.0

func SetHeaderValueNoMemCopy(literal []byte, key, val string) (io.Reader, int, error)

SetHeaderValueNoMemCopy is the same as SetHeaderValue, except it does not allocate memory to modify the input literal. Instead, it returns an io.MultiReader that combines the sub-slices in the correct order. This enables us to only allocate memory for the new header field while re-using the old literal.

func Split

func Split(b []byte) ([]byte, []byte)

Types

type ByteScanner added in v0.12.0

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

func NewByteScanner added in v0.12.0

func NewByteScanner(data []byte, boundary []byte) (*ByteScanner, error)

func (*ByteScanner) ScanAll added in v0.12.0

func (s *ByteScanner) ScanAll() []Part
type Header struct {
	// contains filtered or unexported fields
}

func NewEmptyHeader added in v0.14.0

func NewEmptyHeader() *Header

NewEmptyHeader returns an empty header that can be filled with values.

func NewHeader added in v0.12.0

func NewHeader(data []byte) (*Header, error)

func (*Header) Del

func (h *Header) Del(key string)

func (*Header) Entries

func (h *Header) Entries(fn func(key, val string))

func (*Header) Fields

func (h *Header) Fields(fields []string) []byte

func (*Header) FieldsNot

func (h *Header) FieldsNot(fields []string) []byte

func (*Header) Get

func (h *Header) Get(key string) string

func (*Header) GetChecked added in v0.12.0

func (h *Header) GetChecked(key string) (string, bool)

func (*Header) GetLine

func (h *Header) GetLine(key string) []byte

func (*Header) GetRaw

func (h *Header) GetRaw(key string) []byte

func (*Header) Has

func (h *Header) Has(key string) bool

func (*Header) Raw

func (h *Header) Raw() []byte

func (*Header) Set

func (h *Header) Set(key, val string)

type MIMEType

type MIMEType string
const (
	TextPlain        MIMEType = "text/plain"
	TextHTML         MIMEType = "text/html"
	MultipartMixed   MIMEType = "multipart/mixed"
	MultipartRelated MIMEType = "multipart/related"
	MessageRFC822    MIMEType = "message/rfc822"
)

func ParseMIMEType added in v0.12.0

func ParseMIMEType(val string) (MIMEType, map[string]string, error)

func (MIMEType) IsMultiPart added in v0.12.0

func (mimeType MIMEType) IsMultiPart() bool

func (MIMEType) SubType added in v0.12.0

func (mimeType MIMEType) SubType() string

func (MIMEType) Type added in v0.12.0

func (mimeType MIMEType) Type() string

type MultipartWriter

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

func NewMultipartWriter

func NewMultipartWriter(w io.Writer, boundary string) *MultipartWriter

func (*MultipartWriter) AddPart

func (w *MultipartWriter) AddPart(fn func(io.Writer) error) error

func (*MultipartWriter) Done

func (w *MultipartWriter) Done() error

type Part

type Part struct {
	Data   []byte
	Offset int
}

type Section

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

func Parse

func Parse(literal []byte) *Section

func (*Section) Body

func (section *Section) Body() []byte

func (*Section) Children

func (section *Section) Children() ([]*Section, error)

func (*Section) ContentType

func (section *Section) ContentType() (MIMEType, map[string]string, error)

func (*Section) DecodedBody added in v0.14.0

func (section *Section) DecodedBody() ([]byte, error)

func (*Section) Header

func (section *Section) Header() []byte

func (*Section) Identifier

func (section *Section) Identifier() []int

func (*Section) Literal

func (section *Section) Literal() []byte

func (*Section) ParseHeader

func (section *Section) ParseHeader() (*Header, error)

func (*Section) Part

func (section *Section) Part(identifier ...int) (*Section, error)

func (*Section) Walk added in v0.14.0

func (section *Section) Walk(f func(*Section) error) error

Jump to

Keyboard shortcuts

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