api

package
v0.0.0-...-a92c5f4 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CredentialsDirName   = ".credentials"
	ClientSecretFileName = "client_secret.json"

	// Just use the user that we have credentials for
	DefaultUser = "me"
)
View Source
const (
	MaxBatchModifySize = 500
)

Variables

View Source
var FiltersScope = &ScopeProfile{
	Scopes:   []string{gmail.GmailMetadataScope, gmail.GmailSettingsBasicScope},
	CredFile: "gmailcli_filters.json",
}
View Source
var InboxLabel = NewLabelWithId("INBOX")

Constant Labels

View Source
var LabelsScope = &ScopeProfile{
	Scopes:   []string{gmail.GmailReadonlyScope, gmail.GmailMetadataScope},
	CredFile: "gmailcli_labels.json",
}
View Source
var MaxConcurrentRequests = 80

Determined heuristically from testing We should avoid making more than this many rquests in parallel, else the gmail service will yield errors. The API does not publicly say what the limit is at the moment.

View Source
var ModifyScope = &ScopeProfile{
	Scopes:   []string{gmail.GmailModifyScope},
	CredFile: "gmailcli_modify.json",
}
View Source
var ReadScope = &ScopeProfile{
	Scopes:   []string{gmail.GmailReadonlyScope},
	CredFile: "gmailcli_read.json",
}

Scope docs: https://godoc.org/google.golang.org/api/gmail/v1 If modifying these scopes, delete your previously saved credentials at ~/.credentials/...

View Source
var SpecialLabelNames = []string{
	"UNREAD",
	"CATEGORY_PERSONAL",
	"CATEGORY_SOCIAL",
	"CATEGORY_PROMOTIONS",
	"CATEGORY_UPDATES",
	"CATEGORY_FORUMS",
	"IMPORTANT",
	"INBOX",
}
View Source
var TrashLabel = NewLabelWithId("TRASH")

Functions

func DeleteCachedScopeToken

func DeleteCachedScopeToken(scope *ScopeProfile)

func GetMessageBody

func GetMessageBody(msg *gm.Message) []string

Decodes the messages' body text, putting each part as a separate entry in the returned slice. Will be at least size 1

func MessageHasBody

func MessageHasBody(msg *gm.Message) bool

func MessageIdsByThread

func MessageIdsByThread(msgs []*gm.Message) map[string][]*MessageId

func MessageMeetsDetailLevel

func MessageMeetsDetailLevel(msg *gm.Message, detail MessageDetailLevel) bool

func MessagesByThread

func MessagesByThread(msgs []*gm.Message) map[string][]*gm.Message

func MessagesLatestFirst

func MessagesLatestFirst(msgs []*gm.Message) []*gm.Message

func NewGmailClient

func NewGmailClient(scope *ScopeProfile) *gmail.Service

Types

type AccountHelper

type AccountHelper struct {
	User string
	// contains filtered or unexported fields
}

func NewAccountHelper

func NewAccountHelper(user string, srv *gm.Service) *AccountHelper

func (*AccountHelper) GetEmailAddress

func (h *AccountHelper) GetEmailAddress() (string, error)

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(useFile bool) *Cache

func (*Cache) Clear

func (c *Cache) Clear()

func (*Cache) Close

func (c *Cache) Close() error

Implements io.Closer interface

func (*Cache) LoadMsgs

func (c *Cache) LoadMsgs()

func (*Cache) Msg

func (c *Cache) Msg(id string) (*gm.Message, bool)

func (*Cache) UpdateMsg

func (c *Cache) UpdateMsg(msg *gm.Message)

func (*Cache) UpdateMsgs

func (c *Cache) UpdateMsgs(msgs []*gm.Message)

func (*Cache) Write

func (c *Cache) Write()

type EmailAddress

type EmailAddress struct {
	Address string
	Name    string
}

func GetEmailsInField

func GetEmailsInField(fromHeaderVal string) []EmailAddress

type Headers

type Headers struct {
	Subject string
	From    EmailAddress
	To      []EmailAddress
	Cc      []EmailAddress
}

func GetMsgHeaders

func GetMsgHeaders(msg *gm.Message) (*Headers, error)

type Label

type Label struct {
	// contains filtered or unexported fields
}

func LabelsFromLabelNames

func LabelsFromLabelNames(labelNames []string) []Label

func NewLabelWithId

func NewLabelWithId(id string) Label

func NewLabelWithName

func NewLabelWithName(name string) Label

func (Label) String

func (l Label) String() string

type MessageDetailLevel

type MessageDetailLevel int
const (
	IdsOnly MessageDetailLevel = iota
	LabelsOnly
	LabelsAndPayload
)

func MoreDetailedLevel

func MoreDetailedLevel(a, b MessageDetailLevel) MessageDetailLevel

func (MessageDetailLevel) Format

func (dl MessageDetailLevel) Format() MessageFormat

type MessageFormat

type MessageFormat string
const (

	// Only the Raw. Payload will be nil
	MessageFormatRaw MessageFormat = "raw"
)

Format values

func (MessageFormat) ToString

func (f MessageFormat) ToString() string

type MessageId

type MessageId struct {
	Id string
}

A wrapper for a message Id that can be passed by reference. This helps save a little space, and reduces confusion about what contents a message contains when returned from certain functions.

type MsgHelper

type MsgHelper struct {
	User string
	// contains filtered or unexported fields
}

func NewMsgHelper

func NewMsgHelper(user string, srv *gm.Service, useCacheFile bool) *MsgHelper

func (*MsgHelper) ApplyLabels

func (h *MsgHelper) ApplyLabels(
	msgs []*gm.Message, labelsToAdd []Label, labelsToRemove []Label) error

func (*MsgHelper) ApplyLabelsToThreads

func (h *MsgHelper) ApplyLabelsToThreads(threads []*gm.Thread, labelNames []string) error

func (*MsgHelper) BatchModifyMessages

func (h *MsgHelper) BatchModifyMessages(msgs []*gm.Message,
	modReq *gm.BatchModifyMessagesRequest) error

func (*MsgHelper) GetMessage

func (h *MsgHelper) GetMessage(id string, detail MessageDetailLevel,
) (*gm.Message, error)

func (*MsgHelper) GetThread

func (h *MsgHelper) GetThread(id string, detail MessageDetailLevel,
) (*gm.Thread, error)

Loads the thread and caches its messages

func (*MsgHelper) LabelIdForLabel

func (h *MsgHelper) LabelIdForLabel(l *Label) string

func (*MsgHelper) LabelIdFromName

func (h *MsgHelper) LabelIdFromName(label string) string

func (*MsgHelper) LabelIdsForLabels

func (h *MsgHelper) LabelIdsForLabels(labels []Label) []string

If labels is nil or empty, returns nil

func (*MsgHelper) LabelName

func (h *MsgHelper) LabelName(lblId string) string

func (*MsgHelper) LabelNames

func (h *MsgHelper) LabelNames(ids []string) []string

func (*MsgHelper) LoadMessages

func (h *MsgHelper) LoadMessages(msgs []*gm.Message, detail MessageDetailLevel) (
	[]*gm.Message, error)

func (*MsgHelper) MessageLabelNames

func (h *MsgHelper) MessageLabelNames(m *gm.Message) []string

func (*MsgHelper) QueryMessages

func (h *MsgHelper) QueryMessages(
	query string, inboxOnly bool, unreadOnly bool, maxMsgs int64,
	detailLevel MessageDetailLevel) ([]*gm.Message, error)

Query the server for messages. * maxMsgs: a value greater than 0 to apply a max

func (*MsgHelper) QueryThreads

func (h *MsgHelper) QueryThreads(
	query string, inboxOnly bool, unreadOnly bool, maxEntries int64,
	detailLevel MessageDetailLevel) ([]*gm.Thread, error)

func (*MsgHelper) ThreadIsLoaded

func (h *MsgHelper) ThreadIsLoaded(id string) bool

func (*MsgHelper) ThreadLabelNames

func (h *MsgHelper) ThreadLabelNames(threadId string) ([]string, error)

type ScopeProfile

type ScopeProfile struct {
	Scopes   []string
	CredFile string
}

func (*ScopeProfile) ScopesString

func (s *ScopeProfile) ScopesString() string

Jump to

Keyboard shortcuts

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