keyshare

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound = errors.New("could not find specified user")
	ErrDB           = errors.New("database error")

	ErrInvalidEmail       = errors.New("invalid email address")
	ErrInvalidEmailDomain = errors.New("invalid email domain")

	ErrNoNetwork = errors.New("no network connection")
)

Functions

func ParseEmailAddress

func ParseEmailAddress(email string) (*mail.Address, error)

ParseEmailAddress parses a single RFC 5322 address, e.g. "Barry Gibbs <bg@example.com>"

func ParseEmailTemplates

func ParseEmailTemplates(files, subjects map[string]string, defaultLanguage string) (map[string]*template.Template, error)

func VerifyMXRecord

func VerifyMXRecord(email string) error

VerifyMXRecord checks if the given email address has a valid MX record. If none is found, it alternatively looks for a valid A or AAAA record as this is used as fallback by mailservers (implicit MX per RFC 5321 Section 5.1).

It distinguishes a permanent failure (the domain does not exist) from a transient one (no network, DNS timeout, server misbehaving): the former returns ErrInvalidEmailDomain so the address is not retried on every run, while the latter returns ErrNoNetwork so it is retried later.

func WriteError

func WriteError(w http.ResponseWriter, err error)

Types

type DB

type DB struct {
	*sql.DB
}

func (*DB) EmailRevalidation

func (db *DB) EmailRevalidation(ctx context.Context) bool

EmailRevalidation returns whether email address revalidation is enabled.

func (*DB) ExecCountContext

func (db *DB) ExecCountContext(ctx context.Context, query string, args ...any) (int64, error)

func (*DB) ExecUserContext

func (db *DB) ExecUserContext(ctx context.Context, query string, args ...any) error

func (*DB) QueryIterateContext

func (db *DB) QueryIterateContext(ctx context.Context, query string, f func(rows *sql.Rows) error, args ...any) error

func (*DB) QueryScanContext

func (db *DB) QueryScanContext(ctx context.Context, query string, results []any, args ...any) error

func (*DB) QueryUserContext

func (db *DB) QueryUserContext(ctx context.Context, query string, results []any, args ...any) error

type DNSResolver

type DNSResolver interface {
	LookupMX(host string) ([]*net.MX, error)
	LookupIP(host string) ([]net.IP, error)
}

DNSResolver is an interface for DNS lookups, allowing injection of test doubles.

var DefaultDNSResolver DNSResolver = netDNSResolver{}

DefaultDNSResolver is the default DNS resolver used by VerifyMXRecord.

type EmailConfiguration

type EmailConfiguration struct {
	EmailServer     string `json:"email_server" mapstructure:"email_server"`
	EmailHostname   string `json:"email_hostname" mapstructure:"email_hostname"`
	EmailFrom       string `json:"email_from" mapstructure:"email_from"`
	DefaultLanguage string `json:"default_language" mapstructure:"default_language"`
	EmailAuth       smtp.Auth
}

func (EmailConfiguration) SendEmail

func (conf EmailConfiguration) SendEmail(
	templates map[string]*template.Template,
	subjects map[string]string,
	templateData map[string]string,
	to []string,
	lang string,
) error

SendEmail sends a templated email to the supplied email address(es). When multiple recipients are specified, the email is sent as a BCC email.

func (EmailConfiguration) TranslateString

func (conf EmailConfiguration) TranslateString(strings map[string]string, lang string) string

func (EmailConfiguration) VerifyEmailServer

func (conf EmailConfiguration) VerifyEmailServer() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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