Documentation ¶
Index ¶
- Variables
- func IsSpam(header mail.Header) (bool, string)
- func IsSpamKey(headerKey string) bool
- func RFC5322AddrSpecs(addrs []*Addr) []string
- func TryMimeDecode(input string) string
- func WriteHeader(w io.Writer, header mail.Header) error
- type Addr
- func NewAddr(address *mail.Address) (*Addr, error)
- func ParseAddress(rfc5322Address string) (*Addr, error)
- func ParseAddresses(rawAddresses string, limit int) (addrs []*Addr, errs []error)
- func ParseAddressesFromHeader(header mail.Header, fieldName string, limit int) ([]*Addr, error)
- func SingleFrom(header mail.Header) (*Addr, bool)
- type ChanMTA
- type DummyMTA
- type MTA
- type MTAEnvelope
- type Message
- type Sendmail
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidAddress = errors.New("invalid email address")
var RobustAddressParser = mail.AddressParser{ TryMimeDecoder, }
Decodes the Name (not used at the moment). mail.ParseAddress and mail.ParseAddressList yield errors on encoded input, so we should this
var TryMimeDecoder = &mime.WordDecoder{ CharsetReader: func(charset string, input io.Reader) (io.Reader, error) { if enc, err := htmlindex.Get(charset); err == nil { return enc.NewDecoder().Reader(input), nil } else { return input, nil } }, }
CharsetReader never returns an error
Functions ¶
func IsSpam ¶
like https://github.com/rspamd/rspamd/blob/master/rules/regexp/upstream_spam_filters.lua#L50
func RFC5322AddrSpecs ¶ added in v0.10.5
func TryMimeDecode ¶
"[DecodeHeader] decodes all encoded-words of the given string"
Types ¶
type Addr ¶
type Addr struct { Display string // RFC 5322 display-name Local string // RFC 5322 local-part, only a subset of ASCII is allowed Domain string // RFC 5322 domain }
func ParseAddress ¶
parses an address like "Alice <alice@example.org>", "<alice@example.org>" or "alice@example.org" returns the canonicalized address
It is recommended to canonicalize or parse all input data (from form post data, url parameters, SMTP commands, header fields).
func ParseAddresses ¶
ParseAddresses expects one RFC 5322 address-list per line. It does lax parsing and is intended for user input.
func ParseAddressesFromHeader ¶
ParseAddressesFromHeader parses email addresses from a header line. In contrast to ParseAddresses, parsing is strictly.
func (*Addr) DisplayOrLocal ¶
Returns a.Display if it exists, else a.Local.
rspamd has the rule "SPOOF_DISPLAY_NAME" which yields a huge penalty if the "From" field looks like "foo@example.net via List<list@example.com>" [1]. To be on the safe side, we crop the result at the first "@", if any.
[1] https://github.com/rspamd/rspamd/blob/master/rules/misc.lua#L517
func (Addr) RFC5322AddrSpec ¶
RFC 5322 addr-spec = local-part "@" domain
Because the local-part might be quoted, we let golang do the work
func (*Addr) RFC5322NameAddr ¶
RFC 5322 name-addr = [display-name] angle-addr angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
mail.Address.String(): "If the address's name contains non-ASCII characters the name will be rendered according to RFC 2047."
func (*Addr) RFC6068URI ¶
RFC 6068 The 'mailto' URI Scheme
type MTAEnvelope ¶
used for testing
type Message ¶
Replacement for golang's mail.Message. The only difference is that the body is stored as a byte slice.
Just aliasing golang's mail.Message is not feasible because we can't rewind mail.Message.Body.(bufio.Reader), so Copy() had to create two new buffers each time.
func NewMessage ¶
func NewMessage() *Message