Documentation ¶
Overview ¶
Package i18nmail implements parsing of mail messages.
For the most part, this package follows the syntax as specified by RFC 5322. Notable divergences:
- Obsolete address formats are not parsed, including addresses with embedded route information.
- Group addresses are not parsed.
- The full range of spacing (the CFWS syntax element) is not supported, such as breaking addresses across lines.
Index ¶
- Constants
- Variables
- func DecodeHeaders(hdr map[string][]string) map[string][]string
- func DecodeRFC2047Word(s string) (string, error)
- func DecodeSMIME(ctx context.Context, sr *io.SectionReader) (*io.SectionReader, error)
- func HashBytes(data []byte) string
- func HeadDecode(head string) string
- func MakeMsgID() string
- func MakeSectionReader(r io.Reader, threshold int) (*io.SectionReader, error)
- func NewB64Decoder(enc *base64.Encoding, r io.Reader) io.Reader
- func NewB64FilterReader(r io.Reader) io.Reader
- func NewFilterReader(r io.Reader, okBytes []byte) io.Reader
- func SetLogger(lgr logr.Logger)
- func Walk(part MailPart, todo TodoFunc, dontDescend bool) error
- func WalkMessage(msg *mail.Message, todo TodoFunc, dontDescend bool, parent *MailPart) error
- func WalkMultipart(mp MailPart, todo TodoFunc, dontDescend bool) error
- type Address
- type DecoderFunc
- type Header
- type MailPart
- type TodoFunc
Constants ¶
const HashKeyName = "X-HashOfFullMessage"
HashKeyName is the header key name for the hash
const (
MaxWalkDepth = 32
)
MaxWalkDepth is the maximum depth Walk will descend.
Variables ¶
var ( // CheckEncoding is true if we should check Base64 encodings CheckEncoding = true // SaveBadInput is true if we should save bad input SaveBadInput = false // ErrStopWalk shall be returned by the TodoFunc to stop the walk silently. ErrStopWalk = errors.New("stop the walk") )
var AddressParser = &mail.AddressParser{WordDecoder: WordDecoder}
AddressParser is a mail address parser.
var ErrHeaderNotPresent = errors.New("mail: header not in message")
var WordDecoder = &mime.WordDecoder{ CharsetReader: func(charset string, input io.Reader) (io.Reader, error) { enc, err := htmlindex.Get(charset) if err != nil { return input, err } return transform.NewReader(input, enc.NewDecoder()), nil }, }
WordDecoder decodes mime rords.
Functions ¶
func DecodeHeaders ¶
DecodeHeaders decodes the headers.
func DecodeRFC2047Word ¶
DecodeRFC2047Word decodes the string as RFC2407.
func DecodeSMIME ¶ added in v0.24.4
func DecodeSMIME(ctx context.Context, sr *io.SectionReader) (*io.SectionReader, error)
DecodeSMIME decodes S/MIME smime.p7m if that's the only part.
func HeadDecode ¶
HeadDecode decodes mail header encoding (quopri or base64) such as =?iso-8859-2?Q?MEN-261_K=D6BE_k=E1r.pdf?=
func MakeMsgID ¶
func MakeMsgID() string
MakeMsgID creates a new, globally unique message ID, useable as a Message-ID as per RFC822/RFC2822.
func MakeSectionReader ¶
MakeSectionReader reads the reader and returns the byte slice.
If the read length is below the threshold, then the bytes are read into memory; otherwise, a temp file is created, and mmap-ed.
func NewB64Decoder ¶
NewB64Decoder returns a new filtering bae64 decoder.
func NewB64FilterReader ¶
NewB64FilterReader returns a base64 filtering reader.
func NewFilterReader ¶
NewFilterReader returns a reader which silently throws away bytes not in the okBytes slice.
func Walk ¶
Walk over the parts of the email, calling todo on every part.
By default this is recursive, except dontDescend is true.
func WalkMessage ¶
WalkMessage walks over the parts of the email, calling todo on every part. The part.Body given to todo is reused, so read if you want to use it!
By default this is recursive, except dontDescend is true.
Types ¶
type Address ¶
Address represents a single mail address. An address such as "Barry Gibbs <bg@example.com>" is represented as Address{Name: "Barry Gibbs", Address: "bg@example.com"}.
func ParseAddress ¶
ParseAddress parses a single RFC 5322 address, e.g. "Barry Gibbs <bg@example.com>"
func ParseAddressList ¶
ParseAddressList parses the given string as a list of addresses.
type DecoderFunc ¶
DecoderFunc is a type of a decoder (io.Reader wrapper)
type Header ¶
A Header represents the key-value pairs in a mail message header.
func (Header) AddressList ¶
AddressList parses the named header field as a list of addresses.
type MailPart ¶
type MailPart struct { // Body of the part. Body *io.SectionReader // MediaType is the parsed media type. MediaType map[string]string // Header of the mail part. Header textproto.MIMEHeader // Parent of this part. Parent *MailPart // ContenType for the part. ContentType string // Level is the depth level. Level int // Seq is a sequence number Seq int }
MailPart is part of a mail or multipart message.
func (MailPart) GetBody ¶ added in v0.23.0
func (mp MailPart) GetBody() *io.SectionReader
GetBody returns a fresh copy of mp.Body.