Documentation ¶
Index ¶
- Constants
- func CheckForUnreadByLabel(srv *gmail.Service, label string) (int64, error)
- func FromBase64(data string) (string, error)
- func GetBody(msg *gmail.Message, mimeType string) (string, error)
- func GetGmailServiceFromFile(credentialsPath string, scope ...string) (*gmail.Service, error)
- func ReceivedTime(datetime int64) (time.Time, error)
- func SetupGmailService(credentialsPath string, scope ...string) error
- type PartialMetadata
- type Service
- func (s *Service) CheckForUnread() (int64, error)
- func (s *Service) GetAttachment(msgId, attachmentId string) (*gmail.MessagePartBody, error)
- func (s *Service) GetLabels() (*gmail.ListLabelsResponse, error)
- func (s *Service) GetMessage(msgId string) (*gmail.Message, error)
- func (s *Service) GetMessages(howMany uint) ([]*gmail.Message, error)
- func (s *Service) MarkAllAsRead() error
- func (s *Service) MarkAs(msgId string, req *gmail.ModifyMessageRequest) (*gmail.Message, error)
- func (s *Service) MessagesByID(msgs *gmail.ListMessagesResponse) ([]*gmail.Message, error)
- func (s *Service) Query(query string) ([]*gmail.Message, error)
Constants ¶
const TokenFile = "gmail-token.json"
Variables ¶
This section is empty.
Functions ¶
func CheckForUnreadByLabel ¶
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 ¶
FromBase64 decodes the email body by converting from URLEncoded base64 to a string.
func GetBody ¶
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 ¶
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 ¶
ReceivedTime parses and converts a Unix time stamp into a human-readable format ().
func SetupGmailService ¶
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 ¶
NewGmailService retrieves a service based on the configuration files and permission scopes.
func (*Service) CheckForUnread ¶
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
GetAttachment returns and attachment by its ID
func (*Service) GetMessage ¶ added in v0.2.0
GetMessage retrieves a message by its ID
func (*Service) GetMessages ¶
GetMessages gets and returns gmail messages
func (*Service) MarkAllAsRead ¶
MarkAllAsRead removes the UNREAD label from all emails.
func (*Service) MarkAs ¶
MarkAs allows you to mark an email with a specific label using the gmail.ModifyMessageRequest struct.
func (*Service) MessagesByID ¶ added in v0.2.0
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