inboxer

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const TokenFile = "gmail-token.json"

Variables

This section is empty.

Functions

func CheckForUnreadByLabel

func CheckForUnreadByLabel(srv *gmail.Service, label string) (int64, error)

CheckForUnreadByLabel checks for unread mail matching the specified label. NOTE: When checking your inbox for unread messages, it's not uncommon for it to return thousands of unread messages that you don't know about. To see them in gmail, query your mail for "label:unread". For CheckForUnreadByLabel to work properly you need to mark all mail as read either through gmail or through the MarkAllAsRead() function found in this library.

func FromBase64

func FromBase64(data string) (string, error)

FromBase64 decodes the email body by converting from URLEncoded base64 to a string.

func GetBody

func GetBody(msg *gmail.Message, mimeType string) (string, error)

GetBody gets, decodes, and returns the body of the email. It returns an error if decoding goes wrong. mimeType is used to indicate whether you want the plain text or html encoding ("text/html", "text/plain").

func GetGmailServiceFromFile

func GetGmailServiceFromFile(credentialsPath string, scope ...string) (*gmail.Service, error)

GetGmailServiceFromFile will use a credentials file and a token file set to build a gmail.Service instance if one of the files are not present, this function will return an error.

func ReceivedTime

func ReceivedTime(datetime int64) (time.Time, error)

ReceivedTime parses and converts a Unix time stamp into a human-readable format ().

func SetupGmailService

func SetupGmailService(credentialsPath string, scope ...string) error

SetupGmailService sets a token file if not already present. This needs human intervention, so it is advised to run the application at /cmd/setup directory before using this lib.

Types

type PartialMetadata

type PartialMetadata struct {
	// Sender is the entity that originally created and sent the message
	Sender string
	// From is the entity that sent the message to you (e.g. googlegroups). Most
	// of the time this information is only relevant to mailing lists.
	From string
	// Subject is the email subject
	Subject string
	// Mailing list contains the name of the mailing list that the email was
	// posted to, if any.
	MailingList string
	// CC is the "carbon copy" list of addresses
	CC []string
	// To is the recipient of the email.
	To []string
	// ThreadTopic contains the topic of the thread (e.g. google groups threads)
	ThreadTopic []string
	// DeliveredTo is who the email was sent to. This can contain multiple
	// addresses if the email was forwarded.
	DeliveredTo []string
}

PartialMetadata stores email metadata. Some fields may sound redundant, but in fact have different contexts. Some are slices of string because the ones that have multiple values are still being sorted from those that don't.

func GetPartialMetadata

func GetPartialMetadata(msg *gmail.Message) *PartialMetadata

GetPartialMetadata gets useful metadata from the headers.

type Service

type Service struct {
	GmailSvc *gmail.Service
}

func NewGmailService

func NewGmailService(credentialsFilePath string, scopes ...string) (*Service, error)

NewGmailService retrieves a service based on the configuration files and permission scopes.

func (*Service) CheckForUnread

func (s *Service) CheckForUnread() (int64, error)

CheckForUnread checks for mail labeled "UNREAD". NOTE: When checking your inbox for unread messages, it's not uncommon for it to return thousands of unread messages that you don't know about. To see them in gmail, query your mail for "label:unread". For CheckForUnread to work properly you need to mark all mail as read either through gmail or through the MarkAllAsRead() function found in this library.

func (*Service) GetAttachment added in v0.2.0

func (s *Service) GetAttachment(msgId, attachmentId string) (*gmail.MessagePartBody, error)

GetAttachment returns and attachment by its ID

func (*Service) GetLabels

func (s *Service) GetLabels() (*gmail.ListLabelsResponse, error)

GetLabels gets a list of the labels used in the users inbox.

func (*Service) GetMessage added in v0.2.0

func (s *Service) GetMessage(msgId string) (*gmail.Message, error)

GetMessage retrieves a message by its ID

func (*Service) GetMessages

func (s *Service) GetMessages(howMany uint) ([]*gmail.Message, error)

GetMessages gets and returns gmail messages

func (*Service) MarkAllAsRead

func (s *Service) MarkAllAsRead() error

MarkAllAsRead removes the UNREAD label from all emails.

func (*Service) MarkAs

func (s *Service) MarkAs(msgId string, req *gmail.ModifyMessageRequest) (*gmail.Message, error)

MarkAs allows you to mark an email with a specific label using the gmail.ModifyMessageRequest struct.

func (*Service) MessagesByID added in v0.2.0

func (s *Service) MessagesByID(msgs *gmail.ListMessagesResponse) ([]*gmail.Message, error)

MessagesByID gets a group of messages by their ids ID. This is necessary because this is how the gmail API is set [0][1] up apparently (but why?). [0] https://developers.google.com/gmail/api/v1/reference/users/messages/get [1] https://stackoverflow.com/questions/36365172/message-payload-is-always-null-for-all-messages-how-do-i-get-this-data

func (*Service) Query

func (s *Service) Query(query string) ([]*gmail.Message, error)

Query queries the inbox for a string following the search style of the gmail online mailbox. example: "in:sent after:2017/01/01 before:2017/01/30"

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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