stickers

package module
v0.0.0-...-d9d2cc5 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: GPL-2.0 Imports: 9 Imported by: 0

README

Actions Status


Stickers is a Gmail label and filtering tool for your Google Workspaces org. It is designed to allow administrators to use filters and labels to classify emails, instead of clunky email message banners and difficult to read subject line headings.

This solution connects throught

Getting Started

To get started, create your service account credentials by following Google's instructions, https://developers.google.com/admin-sdk/directory/v1/guides/delegation#create_the_service_account_and_credentials.

When asked for which scopes, enter the following for a least-permissive approach:

Once your domain is configured, you can then run the script.

Installation

To install, run:

make install

You may also build directly with go using:

go build ./cmd/cli/...

Running Stickers

To run, create a stickers.yaml configuration file. You can use an example, or use the below snippet to bootstrap your configuration. Once ready, you can run the following command, referencing your previously created service account credentials file from Google Cloud Platform.

$ stickers -c service-account.json

Example:

domain: mikemackintosh.com
impersonate: admin@mikemackintosh.com

labels:
  - name: '[External]'
    color:
      backgroundcolor: '#f691b2'
      textcolor: '#994a64'

  - name: '[Retain]'
    color:
      backgroundcolor: '#e07798'
      textcolor: '#ffffff'

filters:
  - label: '[External]'
    query:
      not_from:
        - mikemackintosh.com
        - no-reply@accounts.google.com

Documentation

Index

Constants

View Source
const (
	ScopeGmailLabels   = gmail.GmailLabelsScope
	ScopeGmailSettings = gmail.GmailSettingsBasicScope
)
View Source
const (
	ScopeAdminUserReadOnly = admin.AdminDirectoryUserReadonlyScope
	ScopeAdminUser         = admin.AdminDirectoryUserScope
)

Variables

This section is empty.

Functions

func GetDomain

func GetDomain() string

GetDomain returns a string of the configured domain.

func GetImpersonation

func GetImpersonation() string

GetImpersonation returns a string of the user to impersonate.

func IsSupportedColor

func IsSupportedColor(color string) bool

func LoadConfig

func LoadConfig(b []byte) error

LoadConfig will read the configuration from yaml.

func NewClient

func NewClient(ctx context.Context, scopes []string) (option.ClientOption, error)

NewClient will use FindDefaultCredentials to generate a new client for checking default application credentials or using a configJSON.

func NewClientWithSubject

func NewClientWithSubject(ctx context.Context, subject string, scopes []string) (option.ClientOption, error)

NewClientWithSubject will impersonate a users' email and create a service to query the AdminSDK API.

func NewDefaultCredentialsClient

func NewDefaultCredentialsClient(ctx context.Context, scopes ...string) (option.ClientOption, error)

NewDefaultCredentialsClient will use FindDefaultCredentials to generate a new client for checking default application credentials or using a configJSON.

func NewGmailFilter

func NewGmailFilter() *gmail.Filter

NewGmailFilter creates a new Gmail filter.

func SetServiceAccountFile

func SetServiceAccountFile(f string) error

SetServiceAccountFile sets the service account file.

Types

type AdminService

type AdminService struct {
	Svc *admin.Service
}

AdminService is a wrapper for admin.Service

func NewAdminService

func NewAdminService(ctx context.Context, options ...option.ClientOption) (*AdminService, error)

NewAdminService creates a new AdminService instance.

func (*AdminService) ListUsers

func (s *AdminService) ListUsers() ([]*User, error)

ListUsers will read from the users api.

type Config

type Config struct {
	Labels      Labels        `yaml:"labels"`
	Filters     ConfigFilters `yaml:"filters"`
	Domain      string        `yaml:"domain"`
	Impersonate string        `yaml:"impersonate"`
}

Config is a standard config struct.

func GetConfig

func GetConfig() *Config

GetConfig will return the active config.

type ConfigFilter

type ConfigFilter struct {
	Action string       `yaml:"action"`
	Label  string       `yaml:"label"`
	Query  *FilterQuery `yaml:"query,omitempty"`
}

ConfigFilter represents a gmail filter.

type ConfigFilters

type ConfigFilters []ConfigFilter

LocalFilters is a collection of Filter.

func GetFilters

func GetFilters() ConfigFilters

GetFilters returns a collection of filters to configure.

type ErrFetchingFiltersForUser

type ErrFetchingFiltersForUser struct {
	User string
}

ErrFetchingFiltersForUser

func (ErrFetchingFiltersForUser) Error

Error

type ErrFetchingLabelsForUser

type ErrFetchingLabelsForUser struct {
	User string
}

ErrFetchingLabelsForUser

func (ErrFetchingLabelsForUser) Error

func (e ErrFetchingLabelsForUser) Error() string

Error

type ErrFilterMismatch

type ErrFilterMismatch struct {
	Filter string
}

ErrFilterMismatch

func (ErrFilterMismatch) Error

func (e ErrFilterMismatch) Error() string

ErrLabelMismatch

type ErrFilterNotFound

type ErrFilterNotFound struct {
	Filter string
	User   string
}

ErrFilterNotFound

func (ErrFilterNotFound) Error

func (e ErrFilterNotFound) Error() string

ErrFilterNotFound

type ErrInvalidServiceAccountFile

type ErrInvalidServiceAccountFile struct {
	File string
}

ErrInvalidServiceAccountFile

func (ErrInvalidServiceAccountFile) Error

Error

type ErrLabelMismatch

type ErrLabelMismatch struct {
	Label string
}

ErrLabelMismatch

func (ErrLabelMismatch) Error

func (e ErrLabelMismatch) Error() string

ErrLabelMismatch

type ErrLabelNotFound

type ErrLabelNotFound struct {
	Label string
	User  string
}

ErrLabelNotFound

func (ErrLabelNotFound) Error

func (e ErrLabelNotFound) Error() string

Error

type ErrMissingConfig

type ErrMissingConfig struct{}

ErrMissingConfig is used to

func (ErrMissingConfig) Error

func (e ErrMissingConfig) Error() string

Error

type ErrMissingServiceAccountFile

type ErrMissingServiceAccountFile struct{}

ErrMissingServiceAccountFile

func (ErrMissingServiceAccountFile) Error

Error

type Filter

type Filter gmail.Filter

Filter is a custom gmail.Filter type.

func ToFilter

func ToFilter(f *gmail.Filter) *Filter

ToFilter will take a gmail.Filter and convert to a local Filter.

func (*Filter) ToApi

func (f *Filter) ToApi() *gmail.Filter

ToApi will convert a local label to an API payload.

type FilterQuery

type FilterQuery struct {
	From    *[]string `yaml:"from,omitempty"`
	NotFrom *[]string `yaml:"not_from,omitempty"`
	To      *[]string `yaml:"to,omitempty"`
	NotTo   *[]string `yaml:"not_to,omitempty"`
}

FilterQuery is a query object for filters.

func (*FilterQuery) ToString

func (f *FilterQuery) ToString() string

ToString will convert a query string to a compatible filter.

type GmailService

type GmailService struct {
	Svc         *gmail.Service
	UsersSvc    *gmail.UsersService
	SettingsSvc *gmail.UsersSettingsService
}

func NewGmailService

func NewGmailService(ctx context.Context, options ...option.ClientOption) (*GmailService, error)

NewGmailService creates a new collection of required gmail services.

func (*GmailService) CompareFilters

func (s *GmailService) CompareFilters(upstream, local *Filter, labelId string) error

CompareFilters compares an upstream and local filters.

func (*GmailService) CompareLabels

func (s *GmailService) CompareLabels(upstream, local *Label) error

CompareLabels compares an upstream and local label.

func (*GmailService) CreateFilterForUser

func (s *GmailService) CreateFilterForUser(f *gmail.Filter, user *User) error

CreateFilterForUser creates a filter for the user.

func (*GmailService) CreateLabelForUser

func (s *GmailService) CreateLabelForUser(label *Label, user *User) error

CreateLabelForUser will create a new user label.

func (*GmailService) DeleteFilterForUser

func (s *GmailService) DeleteFilterForUser(f *gmail.Filter, user *User) error

DeleteFilterForUser deletes a filter for the user.

func (*GmailService) GetFilterForUser

func (s *GmailService) GetFilterForUser(filterKey string, user *User) (*Filter, error)

GetLabelForUser gets a specific label for the provided user.

func (GmailService) GetFiltersForUser

func (s GmailService) GetFiltersForUser(user *User) ([]*Filter, error)

GetFiltersForUser will return filters for the user.

func (*GmailService) GetLabelForUser

func (s *GmailService) GetLabelForUser(name string, user *User) (*Label, error)

GetLabelForUser gets a specific label for the provided user.

func (*GmailService) GetLabelsForUser

func (s *GmailService) GetLabelsForUser(user *User) ([]*Label, error)

GetLabelsForUser will return a list of labels for the specified user

func (*GmailService) UpdateLabelForUser

func (s *GmailService) UpdateLabelForUser(label *Label, user *User) error

UpdateLabelForUser will perform a patch label.

type Label

type Label gmail.Label

Label is a custom gmail.Label type.

func ToLabel

func ToLabel(l *gmail.Label) *Label

ToLabel will take a gmail.Label and convert to a local Label.

func (*Label) ToApi

func (l *Label) ToApi() *gmail.Label

ToApi will convert a local label to an API payload.

type Labels

type Labels []*Label

Labels is a collection of Label.

func GetLabels

func GetLabels() Labels

GetLabels returns a collection of labels to configure.

type User

type User admin.User

User is a wrapper for admin.User

func ToUser

func ToUser(u *admin.User) *User

ToUser

func (*User) ToApi

func (u *User) ToApi() *admin.User

ToApi

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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