Documentation ¶
Index ¶
- Constants
- func CloneMessage(src *Service, dst *Service, messageID string, dstLabelIds []string) (*gmail.Message, error)
- func ExecuteWithRetries[T any](f func() (T, error)) (T, error)
- func IsGoogleAPIError(err error) bool
- func IsNotFound(err error) bool
- func IsOAuth2Error(err error) bool
- func IsRateLimitError(err error) bool
- func NewExponentialBackOff() *backoff.ExponentialBackOff
- type ForwardMessage
- type Service
- func (s *Service) BlockMessage(id string, labels *srclabel.CandidateLabels) error
- func (s *Service) CreateLabel(l *gmail.Label) (*gmail.Label, error)
- func (s *Service) ForwardEmail(messageID, to string) (*gmail.Message, error)
- func (s *Service) GetMessage(id string) (*gmail.Message, error)
- func (s *Service) GetOrCreateCandidateLabels() (*srclabel.CandidateLabels, error)
- func (s *Service) GetOrCreateLabel(l *gmail.Label) (*gmail.Label, error)
- func (s *Service) GetOrCreateRecruiterLabels() (*srclabel.RecruiterLabels, error)
- func (s *Service) GetThread(id, format string) (*gmail.Thread, error)
- func (s *Service) IsSenderAllowed(sender string) (bool, error)
- func (s *Service) IsSenderBlocked(sender string) (bool, error)
- func (s *Service) ListLabels() (*gmail.ListLabelsResponse, error)
- func (s *Service) Profile() (*gmail.Profile, error)
Constants ¶
const ( DefaultInitialInterval = 1 * time.Second DefaultRandomizationFactor = 0.5 DefaultMultiplier = 3 DefaultMaxInterval = 2 * time.Minute DefaultMaxElapsedTime = 20 * time.Minute )
Default values for ExponentialBackOff. The defaults should be optimized for - Google usage quota periods and limits - Cloud Functions execution time limits
const (
// FwdMsgDelimiter is the delimiter used to separate the forwarded message from the original message.
FwdMsgDelimiter = "---------- Forwarded message ---------"
)
Variables ¶
This section is empty.
Functions ¶
func CloneMessage ¶
func CloneMessage(src *Service, dst *Service, messageID string, dstLabelIds []string) (*gmail.Message, error)
CloneMessage is a convenience function to cloning a message from one inbox to another. On success, it will return the new destination message. Cloning differs from forwarding because it preserves the original message sender, recipient, and all other headers. TODO: Support recipient anonymization (i.e. randomize 'To' header, strings.Replace first and last name).
func ExecuteWithRetries ¶
ExecuteWithRetries executes a function and automatically retries with an exponential back-off if the function rate turns a googleapi rate limit error (IsRateLimitError).
func IsGoogleAPIError ¶
IsGoogleAPIError checks if the error is a googleapi.Error
https://developers.google.com/gmail/api/guides/handle-errors
func IsNotFound ¶
IsNotFound checks for a status not found (404) response from a Google API
func IsOAuth2Error ¶
IsOAuth2Error checks if the error is an oauth2.RetrieveError. This is useful for detecting expired or revoked access tokens.
func IsRateLimitError ¶
IsRateLimitError checks for - a status too many requests (429) - a usage limit (403) response - or a temporary 500 response from the Google API
func NewExponentialBackOff ¶
func NewExponentialBackOff() *backoff.ExponentialBackOff
NewExponentialBackOff creates an instance of ExponentialBackOff using default values.
Types ¶
type ForwardMessage ¶
ForwardMessage represents a message to be forwarded.
func (ForwardMessage) Create ¶
func (m ForwardMessage) Create() *gmail.Message
Create a send-able gmail message from a forwarded message
func (ForwardMessage) GetParentHeader ¶
func (m ForwardMessage) GetParentHeader(name string) string
GetParentHeader returns the value of the header with the given name from the parent message. It ignores casing when looking at headers.
func (ForwardMessage) InReplyTo ¶
func (m ForwardMessage) InReplyTo() string
InReplyTo returns the contents of the "In-Reply-To:" field of the message to which this one is a reply (the "parent message"). It follows the spec described in https://tools.ietf.org/html/rfc2822#section-3.6.4
The "In-Reply-To:" field will contain the contents of the "Message-ID:" field of the message to which this one is a reply (the "parent message"). If there is more than one parent message, then the "In-Reply-To:" field will contain the contents of all of the parents' "Message-ID:" fields. If there is no "Message-ID:" field in any of the parent messages, then the new message will have no "In-Reply-To:" field.
func (ForwardMessage) ParentBody ¶
func (m ForwardMessage) ParentBody() string
ParentBody returns the body of the parent message. Note: We always convert to text/plain. It's simpler to do deal with and is sufficient for our purposes.
func (ForwardMessage) Raw ¶
func (m ForwardMessage) Raw() string
Raw returns the raw RFC-822 compliant forwarded message.
func (ForwardMessage) References ¶
func (m ForwardMessage) References() string
References returns the contents of the "References:" field of the message to which this one is a reply (the "parent message"). It follows the spec described in https://tools.ietf.org/html/rfc2822#section-3.6.4
The "References:" field will contain the contents of the parent's "References:" field (if any) followed by the contents of the parent's "Message-ID:" field (if any). If the parent message does not contain a "References:" field but does have an "In-Reply-To:" field containing a single message identifier, then the "References:" field will contain the contents of the parent's "In-Reply-To:" field followed by the contents of the parent's "Message-ID:" field (if any). If the parent has none of the "References:", "In-Reply-To:", or "Message-ID:" fields, then the new message will have no "References:" field.
type Service ¶
type Service struct { *gmail.Service UserID string // contains filtered or unexported fields }
Service is a wrapper around the gmail service that adds some convenience methods.
func (*Service) BlockMessage ¶
func (s *Service) BlockMessage(id string, labels *srclabel.CandidateLabels) error
BlockMessage blocks a message by moving moving out of the users inbox and into the block graveyard
func (*Service) CreateLabel ¶
func (*Service) ForwardEmail ¶
ForwardEmail is a good enough implementation of forwarding an email in the same format as the gmail client. It is good enough because it doesn't naively handle HTML mime-type content or when there are multiple parent messages. This is sufficient for our purposes.
func (*Service) GetMessage ¶
GetMessage() fetches a message by ID It is a convenience method that wraps the gmail API call. It opens opportunities for caching and rate-limiting handling
func (*Service) GetOrCreateCandidateLabels ¶
func (s *Service) GetOrCreateCandidateLabels() (*srclabel.CandidateLabels, error)
GetOrCreateCandidateLabels fetches or creates all of the labels managed by SRC Label IDs are unique to each gmail account, so we need to list all labels and match based off names.
func (*Service) GetOrCreateLabel ¶
func (*Service) GetOrCreateRecruiterLabels ¶
func (s *Service) GetOrCreateRecruiterLabels() (*srclabel.RecruiterLabels, error)
GetOrCreateRecruiterLabels fetches or creates all of the labels managed by SRC Label IDs are unique to each gmail account, so we need to list all labels and match based off names.
func (*Service) GetThread ¶
GetThread() fetches a thread by ID with messages in the given format See https://developers.google.com/gmail/api/reference/rest/v1/users.threads/get#Format for format values
It is a convenience method that wraps the gmail API call It opens opportunities for caching and rate-limiting handling
func (*Service) IsSenderAllowed ¶
IsSenderAllowed checks if message is on the user's allow list
func (*Service) IsSenderBlocked ¶
IsSenderBlocked checks if message is on the user's block list