email

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmailTypeInbox represents an inbox email
	EmailTypeInbox = "inbox"
	// EmailTypeInbox represents a sent email
	EmailTypeSent = "sent"
	// EmailTypeInbox represents a draft email
	EmailTypeDraft = "draft"

	// TODO: refactor
	// EmailTypeThread represents a thread, which is a group of emails
	EmailTypeThread = "thread"
)

The constants representing email types

View Source
const (
	ShowTrashExclude = "exclude"
	ShowTrashInclude = "include"
	ShowTrashOnly    = "only"
)
View Source
const (
	ActionRead   = "read"
	ActionUnread = "unread"
)
View Source
const (
	DefaultPageSize = 100
)

Variables

View Source
var (
	ErrInvalidInputToUnmarshal = errors.New("invalid input to unmarshal")
	ErrInvalidInputToDecode    = errors.New("invalid input to decode")
)

Functions

func Delete

func Delete(ctx context.Context, client api.DeleteItemAPI, messageID string) error

Delete deletes an trashed email from DynamoDB and S3. This action won't be successful if it's not trashed.

func GetContent added in v1.4.0

func GetContent(ctx context.Context, client api.GetItemContentAPI, messageID, disposition, contentID string) (*storage.GetEmailContentResult, error)

Get returns the email

func Read added in v1.4.0

func Read(ctx context.Context, client api.UpdateItemAPI, messageID, action string) error

Read marks an email as read or unread

func Reparse added in v1.8.1

func Reparse(ctx context.Context, client api.ReparseEmailAPI, messageID string) error

Reparse re-parse an email from S3 and update the DynamoDB record

func Trash

func Trash(ctx context.Context, client api.UpdateItemAPI, messageID string) error

Trash marks an email as trashed

func UnmarshalGSI added in v1.6.0

func UnmarshalGSI(item map[string]types.AttributeValue) (emailType, emailTime string, err error)

func Untrash

func Untrash(ctx context.Context, client api.UpdateItemAPI, messageID string) error

Untrash marks an trashed email as not trashed

Types

type CreateInput

type CreateInput struct {
	Input
	GenerateText string `json:"generateText"` // on, off, or auto (default)
	Send         bool   `json:"send"`         // send email immediately
	ReplyEmailID string `json:"replyEmailID"` // reply to an email, empty if not reply
}

CreateInput represents the input of create method

type CreateResult

type CreateResult struct {
	TimeIndex
	Subject  string   `json:"subject"`
	From     []string `json:"from"`
	To       []string `json:"to"`
	Cc       []string `json:"cc"`
	Bcc      []string `json:"bcc"`
	ReplyTo  []string `json:"replyTo"`
	Text     string   `json:"text"`
	HTML     string   `json:"html"`
	ThreadID string   `json:"threadID,omitempty"`
}

CreateResult represents the result of create method

func Create

func Create(ctx context.Context, client api.CreateAndSendEmailAPI, input CreateInput) (*CreateResult, error)

Create adds an email as draft in DynamoDB

TODO: refactor this function

type Cursor added in v1.1.0

type Cursor struct {
	QueryInfo        QueryInfo        `json:"queryInfo"`
	LastEvaluatedKey LastEvaluatedKey `json:"lastEvaluatedKey"`
}

func (*Cursor) Bind added in v1.1.0

func (c *Cursor) Bind(data []byte) error

func (*Cursor) BindString added in v1.1.0

func (c *Cursor) BindString(data string) error

func (Cursor) MarshalJSON added in v1.1.0

func (c Cursor) MarshalJSON() ([]byte, error)

func (*Cursor) UnmarshalJSON added in v1.1.0

func (c *Cursor) UnmarshalJSON(data []byte) error

type GSIIndex

type GSIIndex struct {
	MessageID     string `dynamodbav:"MessageID"`
	TypeYearMonth string `dynamodbav:"TypeYearMonth"`
	DateTime      string `dynamodbav:"DateTime"`
}

GSIIndex represents Global Secondary Index of an email

func (GSIIndex) ToTimeIndex

func (gsi GSIIndex) ToTimeIndex() (*TimeIndex, error)

ToTimeIndex returns TimeIndex

type GetResult

type GetResult struct {
	MessageID         string   `json:"messageID"`
	OriginalMessageID string   `json:"originalMessageID"`
	Type              string   `json:"type"`
	Subject           string   `json:"subject"`
	From              []string `json:"from"`
	To                []string `json:"to"`
	Text              string   `json:"text"`
	HTML              string   `json:"html"`
	ReplyTo           []string `json:"replyTo"`
	InReplyTo         string   `json:"inReplyTo"`
	References        string   `json:"references"` // space separated string
	ThreadID          string   `json:"threadID,omitempty"`
	IsThreadLatest    bool     `json:"isThreadLatest,omitempty"`

	// Inbox email attributes
	TimeReceived string   `json:"timeReceived,omitempty"`
	DateSent     string   `json:"dateSent,omitempty"`
	Source       string   `json:"source,omitempty"`
	Destination  []string `json:"destination,omitempty"`
	ReturnPath   string   `json:"returnPath,omitempty"`
	Verdict      *Verdict `json:"verdict,omitempty"`
	Unread       *bool    `json:"unread,omitempty"`

	// Draft email attributes
	TimeUpdated string   `json:"timeUpdated,omitempty"`
	Cc          []string `json:"cc,omitempty"`
	Bcc         []string `json:"bcc,omitempty"`

	// Sent email attributes
	TimeSent string `json:"timeSent,omitempty"`

	// Attachment attributes, currently only support
	Attachments *types.Files `json:"attachments,omitempty"`
	Inlines     *types.Files `json:"inlines,omitempty"`
	OtherParts  *types.Files `json:"otherParts,omitempty"`
}

GetResult represents the result of get method

func Get

func Get(ctx context.Context, client api.GetItemAPI, messageID string) (*GetResult, error)

get returns the email

func GetAndRead added in v1.6.0

func GetAndRead(ctx context.Context, client api.GetEmailAPI, messageID string) (*GetResult, error)

Get returns the email and marks it as read

func ParseGetResult added in v1.6.0

func ParseGetResult(attributeValues map[string]dynamodbTypes.AttributeValue) (*GetResult, error)

type Input added in v1.10.0

type Input struct {
	MessageID  string   `json:"messageID"`
	Subject    string   `json:"subject"`
	From       []string `json:"from"`
	To         []string `json:"to"`
	Cc         []string `json:"cc"`
	Bcc        []string `json:"bcc"`
	ReplyTo    []string `json:"replyTo"`
	InReplyTo  string
	References string
	Text       string `json:"text"`
	HTML       string `json:"html"`
	ThreadID   string `json:"threadID,omitempty"`
}

func (Input) GenerateAttributes added in v1.10.0

func (e Input) GenerateAttributes(typeYearMonth, dateTime string) map[string]types.AttributeValue

GenerateAttributes generates DynamoDB AttributeValues

type Item added in v1.10.0

type Item struct {
	TimeIndex
	Subject        string   `json:"subject"`
	From           []string `json:"from"`
	To             []string `json:"to"`
	Unread         *bool    `json:"unread,omitempty"`
	ThreadID       string   `json:"threadID,omitempty"`
	IsThreadLatest bool     `json:"isThreadLatest,omitempty"`
}

type LastEvaluatedKey added in v1.1.0

type LastEvaluatedKey map[string]types.AttributeValue

func (*LastEvaluatedKey) Decode added in v1.3.0

func (k *LastEvaluatedKey) Decode(data []byte) error

func (LastEvaluatedKey) Encode added in v1.3.0

func (k LastEvaluatedKey) Encode() ([]byte, error)

type ListInput added in v1.1.0

type ListInput struct {
	Type       string  `json:"type"`
	Year       string  `json:"year"`
	Month      string  `json:"month"`
	Order      string  `json:"order"`     // asc or desc (default)
	ShowTrash  string  `json:"showTrash"` // 'include', 'exclude' or 'only' (default is 'exclude')
	PageSize   int     `json:"pageSize"`  // 0 means no limit, default is 100
	NextCursor *Cursor `json:"nextCursor"`
}

ListInput represents the input of list method

type ListResult

type ListResult struct {
	Count      int     `json:"count"`
	Items      []Item  `json:"items"`
	NextCursor *Cursor `json:"nextCursor"`
	HasMore    bool    `json:"hasMore"`
}

ListResult represents the result of list method

func List

func List(ctx context.Context, client api.QueryAPI, input ListInput) (*ListResult, error)

List lists emails in DynamoDB

TODO: refactor this function

type OriginalMessageIDIndex added in v1.5.0

type OriginalMessageIDIndex struct {
	MessageID         string
	OriginalMessageID string
}

type QueryInfo added in v1.1.0

type QueryInfo struct {
	Type  string `json:"type"`
	Year  string `json:"year"`
	Month string `json:"month"`
	Order string `json:"order"`
}

type RawEmailItem added in v1.3.0

type RawEmailItem struct {
	GSIIndex
	Subject        string
	From           []string `json:"from"`
	To             []string `json:"to"`
	Unread         *bool    `json:"unread,omitempty"`
	ThreadID       string   `json:"threadID,omitempty"`
	IsThreadLatest bool     `json:"isThreadLatest,omitempty"`
}

func (RawEmailItem) ToEmailItem added in v1.3.0

func (raw RawEmailItem) ToEmailItem() (*Item, error)

type SaveInput

type SaveInput struct {
	Input
	GenerateText string `json:"generateText"` // on, off, or auto (default)
	Send         bool   `json:"send"`         // send email immediately
}

SaveInput represents the input of save method

type SaveResult

type SaveResult struct {
	TimeIndex
	Subject  string   `json:"subject"`
	From     []string `json:"from"`
	To       []string `json:"to"`
	Cc       []string `json:"cc"`
	Bcc      []string `json:"bcc"`
	ReplyTo  []string `json:"replyTo"`
	Text     string   `json:"text"`
	HTML     string   `json:"html"`
	ThreadID string   `json:"threadID,omitempty"`
}

SaveResult represents the result of save method

func Save

func Save(ctx context.Context, client api.SaveAndSendEmailAPI, input SaveInput) (*SaveResult, error)

Save puts an email as draft in DynamoDB

TODO: refactor this function

type SendResult added in v1.1.1

type SendResult struct {
	MessageID string
}

func Send

func Send(ctx context.Context, client api.GetAndSendEmailAPI, messageID string) (*SendResult, error)

Send sends a draft email

type ThreadInfo added in v1.5.1

type ThreadInfo struct {
	ThreadID string

	References string // used by email reply

	// used to create a new thread
	CreatingEmailID  string
	CreatingSubject  string
	ReplyToMessageID string // the original message id from the sender, rather than the one generated by SES
}

type TimeIndex

type TimeIndex struct {
	MessageID string `json:"messageID"`
	Type      string `json:"type"`

	// TimeReceived is used by inbox emails
	TimeReceived string `json:"timeReceived,omitempty"`

	// TimeUpdated is used by draft emails
	TimeUpdated string `json:"timeUpdated,omitempty"`

	// TimeSent is used by sent emails
	TimeSent string `json:"timeSent,omitempty"`
}

TimeIndex represents the index attributes of an email

type Verdict added in v1.10.0

type Verdict struct {
	Spam  bool `json:"spam"`
	DKIM  bool `json:"dkim"`
	DMARC bool `json:"dmarc"`
	SPF   bool `json:"spf"`
	Virus bool `json:"virus"`
}

Jump to

Keyboard shortcuts

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