Documentation
¶
Overview ¶
Package parser provides the capabilities for parsing an email io.Reader into an email.Email. The parser can receive options of type `Opt` which alter the parsing process.
Index ¶
- type Opt
- func WithCustomAddressFunc(af func(string) (*mail.Address, error)) Opt
- func WithCustomAddressesFunc(af func(list string) ([]*mail.Address, error)) Opt
- func WithCustomDateFunc(df func(string) (time.Time, error)) Opt
- func WithCustomFileFunc(ff func(*email.File) error) Opt
- func WithHeadersOnly() Opt
- func WithSaveFilesToDirectory(dir string) Opt
- func WithSkipContentTypes(skipContentTypes []string) Opt
- func WithVerbose() Opt
- func WithoutAttachments() Opt
- type Parser
- type UnknownContentTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Opt ¶
type Opt func(p *Parser)
Opt is a parser option type provided as a closure to add options to a parser default instance instantiated by NewParser. The options are held in opts.go providing closures returning an Opt such as WithHeadersOnly().
func WithCustomAddressFunc ¶
WithCustomAddressFunc allows for the provision of a custom func for parsing an email name/address combination.
func WithCustomAddressesFunc ¶
WithCustomAddressesFunc allows for the provision of a custom func for parsing lists of email names and addresses from strings.
func WithCustomDateFunc ¶
WithCustomDateFunc allows for the provision of a custom date parsing func.
func WithCustomFileFunc ¶
WithCustomFileFunc allows for the provision of a custom func for reading a file attachment io.Reader. Note that the io.Reader provided by the underlying net/mail package is not concurrent safe. The reader for each file should be drained in turn, otherwise it is likely to be unexpectedly truncated.
Note that all the fields of Parser and email.File are available for custom uses, such as file filtering, file saving or sending files over the network.
func WithHeadersOnly ¶
func WithHeadersOnly() Opt
WithHeadersOnly only parses email headers, which typically provides a substantial speedup in processing.
func WithSaveFilesToDirectory ¶
WithSaveFilesToDirectory is an example WithCustomFileFunc showing how to inject a custom-defined func into the parser to save inline and attached files from an email to the supplied directory.
Note that all the public fields in email.Email are available, as are the fields of email.File. For example the message ID of each email could be used to make a directory, and then each file saved in sequence using its file name suffix (if available).
Caution should be used using the filename provided in internet-provided emails, although some cleaning is done by the parsers module -- see Parser.parseFile.
func WithSkipContentTypes ¶ added in v0.1.1
WithSkipContentTypes allows the user to provide a slice of content types whose email parts will be skipped in processing.
func WithVerbose ¶
func WithVerbose() Opt
WithVerbose is presently a no-op option for testing if options are working as anticipated.
func WithoutAttachments ¶
func WithoutAttachments() Opt
WithoutAttachments skips parsing email attachments, which often provides a speedup in processing.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
type UnknownContentTypeError ¶
type UnknownContentTypeError struct {
// contains filtered or unexported fields
}
UnknownContentTypeError reports an unknown Content Type
func (*UnknownContentTypeError) Error ¶
func (e *UnknownContentTypeError) Error() string