mailbox

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 20 Imported by: 2

README

mailbox

Simple Go package for fetching mails from IMAP.

Documentation

Index

Constants

View Source
const IMAPDateFormat = "02-Jan-2006"

IMAPDateFormat is the date format used for IMAP SINCE.

Variables

View Source
var MailboxInfoSpec = conf.SectionSpec{
	{
		Name:        "Host",
		Description: "The hostname of the IMAP mailbox server (including port)",
		Required:    true,
		Type:        conf.StringType,
	},
	{
		Name:        "TLS",
		Description: "Whether or not TLS should be used.",
		Default:     "yes",
		Type:        conf.BoolType,
	},
	{
		Name:        "InsecureSkipVerify",
		Description: "Insecurely skip certificate validation",
		Default:     "no",
		Type:        conf.BoolType,
	},
	{
		Name:        "User",
		Description: "The username of the mailbox",
		Type:        conf.StringType,
	},
	{
		Name:        "Password",
		Description: "The password for the mailbox",
		Type:        conf.StringType,
	},
	{
		Name:        "Folder",
		Description: "The mailbox folder",
		Type:        conf.StringType,
		Default:     "INBOX",
	},
	{
		Name:        "ReadOnly",
		Description: "Whether or not the mailbox should be opened readonly",
		Type:        conf.BoolType,
		Default:     "yes",
	},
}

MailboxInfoSpec describes the settings used to configure a IMAP mailbox.

Functions

This section is empty.

Types

type Client

type Client struct {
	// IMAP holds the actual IMAP client
	IMAP *imap.Client
}

Client is a mailbox client.

func Connect

func Connect(info Config) (*Client, error)

Connect returns a new IMAP client for the mailbox configured in info.

func (*Client) FetchUIDs

func (cli *Client) FetchUIDs(ctx context.Context, seq *imap.SeqSet) (chan Response, error)

FetchUIDs fetches all mail UIDs specified in the sequence set seq.

func (*Client) SearchUIDs

func (cli *Client) SearchUIDs(search string, since time.Time) ([]uint32, error)

SearchUIDs performs an IMAP UIDSearch on cli and supports searching mails that arrived since a given time. If since is the zero time value it will be ignored.

type Config

type Config struct {
	Host               string
	TLS                bool
	InsecureSkipVerify bool
	User               string
	Password           string
	Folder             string
	ReadOnly           bool
}

Config holds configuration values to connect to a IMAP mailbox.

type EMail

type EMail struct {
	MultiPart
	// Raw provides raw access to the mail headers and the
	// body reader.
	Raw *mail.Message `json:"-"`
	// From holds the parsed FROM envelop.
	From *mail.Address `json:"from"`
	// To holds a parsed address list of the receipients.
	To []*mail.Address `json:"to"`
	// InternalDate is the date at which the email was received
	// by the mailbox.
	InternalDate time.Time `json:"internalDate"`
	// Precedence holds the precedence header value.
	Precedence string `json:"precedence"`
	// Subject holds the decoded subject of the mail.
	Subject string `json:"subject"`
	// UID is the mailbox specific UID value that identifies
	// this mail. Note that UID is only valid as long as the
	// mailbox UIDVALIDITY has changed.
	UID uint32 `json:"uid"`
}

EMail represents a parsed E-Mail fetched from a mailbox.

func MailFromFields

func MailFromFields(ctx context.Context, fields imap.FieldMap) (*EMail, error)

MailFromFields creates a EMail from a set of IMAP fields. It expects RFC822.HEADER, BODY[], INTERNALDATE and UID fields to be set.

type MultiPart

type MultiPart struct {
	// MimeType is the parsed mime-type of this message part.
	MimeType string `json:"mimeType,omitempty"`
	// FileName is the name of the file as advertised by the
	// Content-Disposition header.
	FileName string `json:"filename,omitempty"`
	// Inline is set to true if this multi-part is sent as
	// inline in the Content-Disposition header. If false,
	// the Content-Disposition header has been set to "attachment".
	Inline bool `json:"inline,omitempty"`
	// Children holds all nested multipart message parts.
	// Only set if MimeType starts with multipart/.
	// Mutally exclusive with Body.
	Children []*MultiPart `json:"children,omitempty"`
	// Body is the actual body of the multipart message. Only set
	// if this part is not a multipart message by itself.
	Body []byte `json:"body,omitempty"`
}

MultiPart is a multi-part email.

func ParseMIMEBody

func ParseMIMEBody(ctx context.Context, partHeader textproto.MIMEHeader, rawBody io.Reader) (*MultiPart, error)

ParseMIMEBody parses the MIME payload from rawBody and partHeader. It supports parsing nested multipart MIME payloads.

func (*MultiPart) FindByFilename

func (mp *MultiPart) FindByFilename(name string) []*MultiPart

FindByFilename returns all multipart parts that have the filename name advertised in the Content-Disposition MIME header.

func (*MultiPart) FindByFilenameRegex

func (mp *MultiPart) FindByFilenameRegex(re *regexp.Regexp) []*MultiPart

FindByFilenameRegex is like FindByFilename but accepts a regular expression instead of a fixed name.

func (*MultiPart) FindByMIME

func (mp *MultiPart) FindByMIME(mimeType string) []*MultiPart

FindByMIME searches for the body parts that matches mimeType. The mimeType may search for wildcard by using "*" for one or both parts of the mimetype. For example, "image/*" searches for all images while "*/*" returns everything.

func (*MultiPart) IsMultiPart

func (mp *MultiPart) IsMultiPart() bool

IsMultiPart returns true if mp is a multipart message and may contain nested children.

type Response

type Response struct {
	*EMail `json:",omitempty"`
	Err    error `json:"error,omitempty"`
}

Response is streamed by FetchUIDs for each mail or error encountered.

Jump to

Keyboard shortcuts

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