mailgroups

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mailgroups defines email audiences: saved rules over platform users plus manual addresses, with a suppression list and signed one-click unsubscribe tokens.

Index

Constants

This section is empty.

Variables

View Source
var Roles = []string{"owner", "admin", "operator", "viewer"}

Roles a rule can select.

Functions

func Mask

func Mask(email string) string

Mask hides most of an address for previews: "s***@example.com".

func Normalize

func Normalize(addr string) string

Normalize lowercases and trims an address.

func SignUnsubscribe

func SignUnsubscribe(key []byte, email string) string

SignUnsubscribe returns a token naming email that only this instance can have produced. It never expires: an unsubscribe link must keep working.

func ValidAddress

func ValidAddress(a string) error

ValidAddress reports an error unless a is one bare email address.

func VerifyUnsubscribe

func VerifyUnsubscribe(key []byte, token string) (string, bool)

VerifyUnsubscribe returns the address a token names when its signature holds.

Types

type Directory

type Directory struct {
	Users []User
	// ProjectTeams maps a project id onto the team that owns it.
	ProjectTeams map[string]string
}

Directory is everything Resolve needs to know about the instance.

type Recipient

type Recipient struct {
	Email       string `json:"email"`
	UserID      string `json:"user_id"`
	DisplayName string `json:"display_name"`
	Role        string `json:"role"`
}

Recipient is one resolved address.

func Resolve

func Resolve(d Directory, r Rules, now time.Time) []Recipient

Resolve returns the deduplicated recipients the rules select, sorted by address. Suppression is applied separately by Split.

func Split

func Split(rcpts []Recipient, suppressed map[string]bool, honor bool) (send, held []Recipient)

Split separates suppressed recipients from deliverable ones. When honor is false (system mail) nobody is suppressed.

type Rules

type Rules struct {
	AllUsers         bool     `json:"all_users"`
	Roles            []string `json:"roles"`
	Teams            []string `json:"teams"`
	Projects         []string `json:"projects"`
	EmailDomains     []string `json:"email_domains"`
	InactiveDays     int      `json:"inactive_days"`
	ExtraAddresses   []string `json:"extra_addresses"`
	ExcludeAddresses []string `json:"exclude_addresses"`
}

Rules selects recipients. A user is included when any selector matches (AllUsers, Roles, Teams, Projects, EmailDomains); InactiveDays then narrows the result, and alone selects every user inactive that long. ExtraAddresses are added as-is; ExcludeAddresses are always removed.

func (Rules) Validate

func (r Rules) Validate() error

Validate checks rules are well formed.

type User

type User struct {
	ID          string
	Email       string
	DisplayName string
	Role        string
	TeamIDs     []string
	LastLoginAt *time.Time
	CreatedAt   time.Time
}

User is the slice of a platform account the rules look at.

Jump to

Keyboard shortcuts

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