mail

Imports

Imports #

"bufio"
"errors"
"fmt"
"io"
"log"
"mime"
"net"
"net/textproto"
"strings"
"sync"
"time"
"unicode/utf8"

Constants & Variables

ErrHeaderNotPresent var #

var ErrHeaderNotPresent = *ast.CallExpr

dateLayouts var #

Layouts suitable for passing to time.Parse. These are tried in order.

var dateLayouts []string

dateLayoutsBuildOnce var #

Layouts suitable for passing to time.Parse. These are tried in order.

var dateLayoutsBuildOnce sync.Once

debug var #

var debug = *ast.CallExpr

rfc2047Decoder var #

var rfc2047Decoder = mime.WordDecoder{...}

Type Aliases

charsetError type #

type charsetError string

debugT type #

type debugT bool

Structs

Address struct #

Address represents a single mail address. An address such as "Barry Gibbs " is represented as Address{Name: "Barry Gibbs", Address: "bg@example.com"}.

type Address struct {
Name string
Address string
}

AddressParser struct #

An AddressParser is an RFC 5322 address parser.

type AddressParser struct {
WordDecoder *mime.WordDecoder
}

Message struct #

A Message represents a parsed mail message.

type Message struct {
Header Header
Body io.Reader
}

addrParser struct #

type addrParser struct {
s string
dec *mime.WordDecoder
}

Functions

AddressList method #

AddressList parses the named header field as a list of addresses.

func (h Header) AddressList(key string) ([]*Address, error)

Date method #

Date parses the Date header field.

func (h Header) Date() (time.Time, error)

Error method #

func (e charsetError) Error() string

Get method #

Get gets the first value associated with the given key. It is case insensitive; CanonicalMIMEHeaderKey is used to canonicalize the provided key. If there are no values associated with the key, Get returns "". To access multiple values of a key, or to use non-canonical keys, access the map directly.

func (h Header) Get(key string) string

Parse method #

Parse parses a single RFC 5322 address of the form "Gogh Fir " or "foo@example.com".

func (p *AddressParser) Parse(address string) (*Address, error)

ParseAddress function #

ParseAddress parses a single RFC 5322 address, e.g. "Barry Gibbs "

func ParseAddress(address string) (*Address, error)

ParseAddressList function #

ParseAddressList parses the given string as a list of addresses.

func ParseAddressList(list string) ([]*Address, error)

ParseDate function #

ParseDate parses an RFC 5322 date string.

func ParseDate(date string) (time.Time, error)

ParseList method #

ParseList parses the given string as a list of comma-separated addresses of the form "Gogh Fir " or "foo@example.com".

func (p *AddressParser) ParseList(list string) ([]*Address, error)

Printf method #

func (d debugT) Printf(format string, args ...any)

ReadMessage function #

ReadMessage reads a message from r. The headers are parsed, and the body of the message will be available for reading from msg.Body.

func ReadMessage(r io.Reader) (msg *Message, err error)

String method #

String formats the address as a valid RFC 5322 address. If the address's name contains non-ASCII characters the name will be rendered according to RFC 2047.

func (a *Address) String() string

buildDateLayouts function #

func buildDateLayouts()

consume method #

func (p *addrParser) consume(c byte) bool

consumeAddrSpec method #

consumeAddrSpec parses a single RFC 5322 addr-spec at the start of p.

func (p *addrParser) consumeAddrSpec() (spec string, err error)

consumeAtom method #

consumeAtom parses an RFC 5322 atom at the start of p. If dot is true, consumeAtom parses an RFC 5322 dot-atom instead. If permissive is true, consumeAtom will not fail on: - leading/trailing/double dots in the atom (see golang.org/issue/4938)

func (p *addrParser) consumeAtom(dot bool, permissive bool) (atom string, err error)

consumeComment method #

func (p *addrParser) consumeComment() (string, bool)

consumeDisplayNameComment method #

func (p *addrParser) consumeDisplayNameComment() (string, error)

consumeDomainLiteral method #

consumeDomainLiteral parses an RFC 5322 domain-literal at the start of p.

func (p *addrParser) consumeDomainLiteral() (string, error)

consumeGroupList method #

func (p *addrParser) consumeGroupList() ([]*Address, error)

consumePhrase method #

consumePhrase parses the RFC 5322 phrase at the start of p.

func (p *addrParser) consumePhrase() (phrase string, err error)

consumeQuotedString method #

consumeQuotedString parses the quoted string at the start of p.

func (p *addrParser) consumeQuotedString() (qs string, err error)

decodeRFC2047Word method #

func (p *addrParser) decodeRFC2047Word(s string) (word string, isEncoded bool, err error)

empty method #

func (p *addrParser) empty() bool

isAtext function #

isAtext reports whether r is an RFC 5322 atext character. If dot is true, period is included.

func isAtext(r rune, dot bool) bool

isDtext function #

isDtext reports whether r is an RFC 5322 dtext character.

func isDtext(r rune) bool

isMultibyte function #

isMultibyte reports whether r is a multi-byte UTF-8 character as supported by RFC 6532.

func isMultibyte(r rune) bool

isQtext function #

isQtext reports whether r is an RFC 5322 qtext character.

func isQtext(r rune) bool

isVchar function #

isVchar reports whether r is an RFC 5322 VCHAR character.

func isVchar(r rune) bool

isWSP function #

isWSP reports whether r is a WSP (white space). WSP is a space or horizontal tab (RFC 5234 Appendix B).

func isWSP(r rune) bool

len method #

func (p *addrParser) len() int

parseAddress method #

parseAddress parses a single RFC 5322 address at the start of p.

func (p *addrParser) parseAddress(handleGroup bool) ([]*Address, error)

parseAddressList method #

func (p *addrParser) parseAddressList() ([]*Address, error)

parseSingleAddress method #

func (p *addrParser) parseSingleAddress() (*Address, error)

peek method #

func (p *addrParser) peek() byte

quoteString function #

quoteString renders a string as an RFC 5322 quoted-string.

func quoteString(s string) string

readHeader function #

readHeader reads the message headers from r. This is like textproto.ReadMIMEHeader, but doesn't validate. The fix for issue #53188 tightened up net/textproto to enforce restrictions of RFC 7230. This package implements RFC 5322, which does not have those restrictions. This function copies the relevant code from net/textproto, simplified for RFC 5322.

func readHeader(r *textproto.Reader) (map[string][]string, error)

skipCFWS method #

skipCFWS skips CFWS as defined in RFC5322.

func (p *addrParser) skipCFWS() bool

skipSpace method #

skipSpace skips the leading space and tab characters.

func (p *addrParser) skipSpace()

Generated with Arrow