milterutil

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: BSD-2-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package milterutil includes utility functions and types that might be useful for writing milters or MTAs.

Index

Constants

View Source
const DefaultMaximumLineLength = 950

DefaultMaximumLineLength is the maximum line length (in bytes) that will be used by MaximumLineLengthTransformer when its MaximumLength value is zero. The SMTP protocol theoretically allows up to 1000 bytes. We default to 950 bytes since some MTAs do forceful line breaks at lower limits (e.g. 980 bytes).

Variables

This section is empty.

Functions

func CrLfToLf

func CrLfToLf(s string) string

CrLfToLf is a helper that uses CrLfToLfTransformer to replace all line endings to only LF.

postfix wants LF lines endings for header values. Using CRLF results in double CR sequences.

Types

type CrLfCanonicalizationTransformer

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

CrLfCanonicalizationTransformer is a transform.Transformer that replaces line endings in src with CR LF line endings in dst.

func (*CrLfCanonicalizationTransformer) Reset

func (*CrLfCanonicalizationTransformer) Transform

func (t *CrLfCanonicalizationTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

type CrLfToLfTransformer

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

CrLfToLfTransformer is a transform.Transformer that replaces all CR LF and single CR in src to LF in dst.

func (*CrLfToLfTransformer) Reset

func (t *CrLfToLfTransformer) Reset()

func (*CrLfToLfTransformer) Transform

func (t *CrLfToLfTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

type DoublePercentTransformer

type DoublePercentTransformer struct {
	transform.NopResetter
}

DoublePercentTransformer is a transform.Transformer that replaces all % in src with %% in dst.

func (*DoublePercentTransformer) Transform

func (t *DoublePercentTransformer) Transform(dst, src []byte, _ bool) (nDst, nSrc int, err error)

type FixedBufferScanner

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

FixedBufferScanner is a wrapper around a bufio.Scanner that produces fixed size chunks of data given an io.Reader.

func GetFixedBufferScanner

func GetFixedBufferScanner(bufferSize uint32, r io.Reader) *FixedBufferScanner

GetFixedBufferScanner returns a FixedBufferScanner of size bufferSize that is configured to read from r.

It is the responsibility of the caller to close r.

If the caller is done with the returned FixedBufferScanner its Close method should be called to release it to the shared pool of FixedBufferScanners.

func (*FixedBufferScanner) Bytes

func (f *FixedBufferScanner) Bytes() []byte

Bytes returns the current chunk of data

func (*FixedBufferScanner) Close

func (f *FixedBufferScanner) Close()

Close need to be called when you are done with the FixedBufferScanner because we maintain a shared pool of FixedBufferScanner objects.

Close does not close the underlying io.Reader. It is the responsibility of the caller to do this.

func (*FixedBufferScanner) Err

func (f *FixedBufferScanner) Err() error

Err returns the first non-EOF error that was encountered by the FixedBufferScanner.

func (*FixedBufferScanner) Scan

func (f *FixedBufferScanner) Scan() bool

Scan returns true when there is new data in Bytes

type MaximumLineLengthTransformer

type MaximumLineLengthTransformer struct {
	MaximumLength uint
	// contains filtered or unexported fields
}

MaximumLineLengthTransformer is a transform.Transformer that splits src into lines of at most MaximumLength bytes.

CR and LF are considered new line indicators. They do not count to the line length.

This transformer can handle UTF-8 input. Because of this we actually start tying to split lines at MaximumLength - 3 bytes. This way we can assure that one line is never bigger than MaximumLength bytes.

func (*MaximumLineLengthTransformer) Reset

func (t *MaximumLineLengthTransformer) Reset()

func (*MaximumLineLengthTransformer) Transform

func (t *MaximumLineLengthTransformer) Transform(dst, src []byte, _ bool) (nDst, nSrc int, err error)

type SMTPReplyTransformer

type SMTPReplyTransformer struct {
	Code uint16
	// contains filtered or unexported fields
}

SMTPReplyTransformer is a transform.Transformer that reads src and produces a valid SMTP response (including multi-line handling)

This transformer does not handle CR LF canonicalization, but it needs src to be properly encoded in this way.

When you combine this Transformer in a transform.Chain it can only handle lines with a maximum of 128 bytes.

func (*SMTPReplyTransformer) Reset

func (t *SMTPReplyTransformer) Reset()

func (*SMTPReplyTransformer) Transform

func (t *SMTPReplyTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

type SkipDoublePercentTransformer

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

SkipDoublePercentTransformer is a transform.Transformer that replaces all %% in src to % in dst. Single % signs are left as-is.

func (*SkipDoublePercentTransformer) Reset

func (t *SkipDoublePercentTransformer) Reset()

func (*SkipDoublePercentTransformer) Transform

func (t *SkipDoublePercentTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Jump to

Keyboard shortcuts

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