classify

package
v0.110.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package classify says what kind of email infrastructure an address or domain is: a free consumer mailbox, a private mailbox, an alias service, a throwaway inbox, a school, a government, or not known yet. It answers from intelligence Outflare maintains (data/), plus DNS when asked.

The data is global: the same for every workspace. Workspace input (overrides, feedback, results from a workspace's paid verifier) never changes it.

Confidence is null until it is calibrated against a reviewed set of domains; ConfidenceStatus says what the answer rests on instead.

Index

Constants

View Source
const (
	AnalysisComplete   = "complete"   // nothing more to find out
	AnalysisNotQueued  = "not_queued" // research could help, but none was asked for
	AnalysisQueued     = "queued"     // research is running; ask again shortly
	AnalysisResearched = "researched" // the workspace's own research answered
)

Analysis statuses: where the answer is in its life.

View Source
const (
	SourceOutflare   = "outflare"                 // data/providers.yaml, reviewed by Outflare
	SourceDisposable = "disposable-email-domains" // CC0
	SourceFakeFilter = "fakefilter"               // BSD 3-Clause
	SourceDNS        = "dns"
	SourceSuffix     = "public_suffix"
)

Sources, as they appear in evidence.

View Source
const (
	SiteOffersTemporaryAddresses = "site_offers_temporary_addresses"
	SiteOffersFreeMailboxes      = "site_offers_free_mailboxes"
	SiteOffersPaidMailboxes      = "site_offers_paid_mailboxes"
	SiteOffersForwarding         = "site_offers_forwarding"
	SiteIsOrganisation           = "site_is_organisation"
	SiteIsSchoolOrGovernment     = "site_is_school_or_government"
	SiteIsParked                 = "site_is_parked"
	SiteSaysNothingAboutEmail    = "site_says_nothing_about_email"
	SiteCouldNotBeRead           = "site_could_not_be_read"
)

Signals a verdict may carry. The model picks from this list, so the signals stay comparable across workspaces and carry nothing personal.

View Source
const (
	Business               = "business"
	FreePersonal           = "free_personal"
	PrivateMailbox         = "private_mailbox"
	Disposable             = "disposable"
	RelayAlias             = "relay_alias"
	Education              = "education"
	Government             = "government"
	NonprofitInstitutional = "nonprofit_institutional"
	PersonalCustom         = "personal_custom"
	ManagedOther           = "managed_other"
	Unknown                = "unknown"
)

Categories: what an email domain is.

View Source
const (
	ShortLivedMailbox        = "short_lived_mailbox"
	ThrowawayPersistent      = "throwaway_persistent"
	SharedPublicInbox        = "shared_public_inbox"
	TemporaryForwarder       = "temporary_forwarder"
	RotatingDomainProvider   = "rotating_domain_provider"
	AnonymousAlias           = "anonymous_alias"
	PermanentAlias           = "permanent_alias"
	UnknownDisposableSubtype = "unknown_disposable_subtype"
)

Subcategories of disposable and relay_alias.

View Source
const (
	Verified             = "verified"              // a provider Outflare reviewed
	Corroborated         = "corroborated"          // two or more independent sources agree
	Inferred             = "inferred"              // one source or one indicator, such as a .edu suffix
	InsufficientEvidence = "insufficient_evidence" // nothing to go on yet
	Conflicted           = "conflicted"            // sources disagree and none outranks the others
)

Confidence statuses: what an answer rests on.

View Source
const (
	Allow  = "allow"
	Verify = "verify"
	Review = "review"
	Block  = "block"
)

Recommended actions.

View Source
const DataVersion = "2026-10-26.1"

DataVersion names the snapshot of data/ built into this binary. Bump it whenever a file in data/ changes.

View Source
const ResearchTask = "classify_domain"

ResearchTask names the model task, so a workspace can give research a cheaper model than its missions use.

View Source
const SourceResearch = "research"

SourceResearch marks evidence a workspace's own research produced.

View Source
const TaxonomyVersion = "1.0"

TaxonomyVersion versions the category and attribute codes below. Codes are added, never renamed; a deprecated code maps to its replacement.

Variables

View Source
var (
	ErrInvalidEmail  = errors.New("email must be a valid email address, such as name@example.com")
	ErrInvalidDomain = errors.New("domain must be a valid domain name, such as example.com")
	ErrPublicSuffix  = errors.New("domain must be a domain someone can register, not a public suffix such as co.uk")
)

Errors from parsing. Their text starts with the field name, so the API can pass it on as a field error.

View Source
var Builtin = sync.OnceValue(func() *Intel {
	in, err := load(providersYAML, disposableList, fakeFilterList)
	if err != nil {
		panic("classify: embedded data: " + err.Error())
	}
	return in
})

Builtin returns the intelligence embedded in this binary.

Categories lists every category code.

View Source
var ErrInput = errors.New("email or domain is required, but not both")

ErrInput is returned when Input has both or neither.

View Source
var ErrVerdict = errors.New("the model's answer did not fit the taxonomy")

ErrVerdict means the model's answer could not be used.

ResearchSignals lists every signal, in the order the prompt gives them.

Subcategories lists every subcategory code.

Functions

func ResearchPrompt

func ResearchPrompt(res Result, p Page) string

ResearchPrompt is the question for the model about one domain: what the lists and DNS found, and the words on the domain's own homepage.

func ResearchSystem

func ResearchSystem() string

ResearchSystem is the instruction that goes with ResearchPrompt.

func RoleLocal

func RoleLocal(local string) bool

RoleLocal reports whether a local part is a role or shared inbox, such as info@ or support@, ignoring a +tag.

func VerdictSchema

func VerdictSchema() map[string]any

VerdictSchema is the JSON shape the model must answer in.

Types

type Address

type Address struct {
	Local  string
	Domain Domain
}

Address is a parsed email address. Local is kept as given: the classifier never rewrites dots or +tags into a different identity.

func ParseEmail

func ParseEmail(s string) (Address, error)

ParseEmail splits and checks an address. The domain is canonicalised; the local part is checked but kept as given.

type Analysis

type Analysis struct {
	Status      string `json:"status"`
	Provisional bool   `json:"provisional"`
}

Analysis says whether the answer is final or waiting on more research.

type Assessment

type Assessment struct {
	Category    string  `json:"category"`
	Subcategory *string `json:"subcategory"`
	// Confidence is a calibrated probability the category is right. It is
	// null until calibration exists; ConfidenceStatus says what the
	// category rests on.
	Confidence       *float64   `json:"confidence"`
	ConfidenceStatus string     `json:"confidence_status"`
	Provider         *Ref       `json:"provider"`
	Attributes       Attributes `json:"attributes"`
	Risk             Risk       `json:"risk"`
	Evidence         []Evidence `json:"evidence"`
	// LastCheckedAt is when DNS was last asked, or null.
	LastCheckedAt *time.Time `json:"last_checked_at"`
}

Assessment is the global classification of the domain.

type Attributes

type Attributes struct {
	IsDisposable              Tri     `json:"is_disposable"`
	IsPublicInbox             Tri     `json:"is_public_inbox"`
	IsForwarder               Tri     `json:"is_forwarder"`
	IsAliasService            Tri     `json:"is_alias_service"`
	IsPrivacyProvider         Tri     `json:"is_privacy_provider"`
	IsFreeProvider            Tri     `json:"is_free_provider"`
	IsRoleAddress             *Tri    `json:"is_role_address,omitempty"`
	IsCatchAllDomain          Tri     `json:"is_catch_all_domain"`
	IsNewDomain               Tri     `json:"is_new_domain"`
	HasMX                     Tri     `json:"has_mx"`
	HasMailReceivingPath      Tri     `json:"has_mail_receiving_path"`
	HasValidSyntax            Tri     `json:"has_valid_syntax"`
	IsInternationalizedDomain Tri     `json:"is_internationalized_domain"`
	MXProviderID              *string `json:"mx_provider_id"`
}

Attributes are independent of the category. Address-only ones are left out for a domain lookup.

type Classifier

type Classifier struct {
	Intel *Intel // nil uses Builtin()
	// Resolver checks mail servers; nil leaves the mail attributes unknown.
	Resolver Resolver
	Timeout  time.Duration // per DNS lookup; 0 means 3 seconds
	// contains filtered or unexported fields
}

Classifier answers what kind of email infrastructure an address or domain is. The zero value uses the built-in data and no DNS.

func (*Classifier) Classify

func (c *Classifier) Classify(ctx context.Context, in Input) (Result, error)

Classify answers for one address or domain.

type Domain

type Domain struct {
	Name        string // mail.example.co.uk
	Registrable string // example.co.uk
	Suffix      string // co.uk
	// ICANN is true when Suffix is an ICANN suffix rather than a private
	// one (github.io) or the catch-all for unknown TLDs.
	ICANN bool
}

Domain is a canonical domain: lowercase ASCII (punycode for internationalised names), no trailing dot.

func ParseDomain

func ParseDomain(s string) (Domain, error)

ParseDomain canonicalises a domain name.

func (Domain) IDN

func (d Domain) IDN() bool

IDN reports whether any label is internationalised.

type Effective

type Effective struct {
	Category        string  `json:"category"`
	Subcategory     *string `json:"subcategory"`
	OverrideApplied bool    `json:"override_applied"`
	OverrideID      *string `json:"override_id"`
	Action          string  `json:"action"` // allow, verify, review or block
	MatchedPolicyID string  `json:"matched_policy_id"`
}

Effective is the workspace's view: the global category after its overrides, and the action its rules recommend. Until workspaces have overrides and rules, it is the global category and Outflare's default rules.

type Evidence

type Evidence struct {
	Source string `json:"source"`
	Signal string `json:"signal"`
	// Detail is a fixed, non-personal note, such as the list entry matched.
	Detail string `json:"detail,omitempty"`
}

Evidence is one fact behind the answer.

type Input

type Input struct {
	Email  string
	Domain string
}

Input is an email address or a domain, never both. A domain alone keeps the person's address out of the request.

type Intel

type Intel struct {
	Version string
	// contains filtered or unexported fields
}

Intel is the global intelligence: reviewed providers and open lists, keyed by canonical domain.

func (*Intel) Count

func (in *Intel) Count(source string) int

Count reports how many domains a source lists.

func (*Intel) MailboxProvider added in v0.14.0

func (in *Intel) MailboxProvider(domain string) bool

MailboxProvider reports whether domain belongs to a mailbox or alias service (Gmail, iCloud, a relay, a disposable domain) rather than to the company its people work at, so two people on it never share a company.

type Page

type Page struct {
	// URL is where the fetch ended up, Status the site's HTTP answer.
	URL    string
	Status int
	HTML   string
	// Fetched is false when there was no page to read: the fetch failed,
	// or the site answered with an error.
	Fetched bool
}

Page is a domain's homepage, as the workspace's fetcher read it.

func (Page) Text

func (p Page) Text() string

Text is the page's visible words: scripts, styles and markup out, runs of space collapsed, cut to maxPageRunes.

type PageFetcher

type PageFetcher interface {
	// FetchHomepage reads https://<domain>/, following the site's
	// redirects. It returns a Page with Fetched false, and no error, when
	// the site simply has no readable homepage.
	FetchHomepage(ctx context.Context, domain string) (Page, error)
}

PageFetcher reads a domain's homepage through the workspace's own connection. The classifier never fetches pages itself: a workspace's research goes out on the workspace's own account.

type Provider

type Provider struct {
	ID          string   `yaml:"id"`
	Name        string   `yaml:"name"`
	Category    string   `yaml:"category"`
	Subcategory string   `yaml:"subcategory"`
	Domains     []string `yaml:"domains"`
	// Subdomains: addresses live on subdomains too (alias@you.example.com).
	Subdomains bool `yaml:"subdomains"`
}

Provider is a mailbox or alias service Outflare has reviewed.

type Ref

type Ref struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Ref names a provider.

type Research

type Research struct {
	Category         string     `json:"category"`
	Subcategory      *string    `json:"subcategory"`
	ConfidenceStatus string     `json:"confidence_status"`
	Signals          []string   `json:"signals"`
	Evidence         []Evidence `json:"evidence"`
	Note             string     `json:"note,omitempty"`
	Model            string     `json:"model"`
	ResearchedAt     time.Time  `json:"researched_at"`
}

Research is what a workspace's own research made of a domain. It sits beside the global assessment, which research never changes.

type Resolver

type Resolver interface {
	LookupMX(ctx context.Context, name string) ([]*net.MX, error)
	LookupHost(ctx context.Context, host string) ([]string, error)
}

Resolver looks up mail servers. *net.Resolver satisfies it.

type Result

type Result struct {
	Scope               string     `json:"scope"` // email or domain
	NormalizedDomain    string     `json:"normalized_domain"`
	RegistrableDomain   string     `json:"registrable_domain"`
	TaxonomyVersion     string     `json:"taxonomy_version"`
	IntelligenceVersion string     `json:"intelligence_version"`
	Global              Assessment `json:"global"`
	// Research is what this workspace's own research made of the domain,
	// when it has researched it. It is absent for every other workspace.
	Research  *Research `json:"research,omitempty"`
	Effective Effective `json:"effective"`
	Analysis  Analysis  `json:"analysis"`
}

Result is the answer. Global is the same for every workspace; Effective is what this workspace's rules make of it.

func (*Result) ApplyResearch

func (res *Result) ApplyResearch(v Verdict, model string, at time.Time)

ApplyResearch puts a workspace's own research onto a result: it fills the research block, and the effective category and action follow it. The global assessment is left exactly as it was.

type Risk

type Risk struct {
	Status  string   `json:"status"` // assessed or not_assessed
	Score   *int     `json:"score"`
	Level   string   `json:"level"` // low, medium, high or unknown
	Signals []string `json:"signals"`
}

Risk is how much a domain should concern a sign-up flow, separate from what it is. Scores are rule-based until calibrated: 0 to 100, higher is more concern, never a probability that a person is fraudulent.

type Tri

type Tri int8

Tri is an attribute that is true, false or not known. Absence of evidence is Unknown, never false.

const (
	TriUnknown Tri = iota
	TriFalse
	TriTrue
)

func Of

func Of(b bool) Tri

Of turns a bool into a known Tri.

func (Tri) MarshalJSON

func (t Tri) MarshalJSON() ([]byte, error)

MarshalJSON writes true, false or "unknown".

func (Tri) String

func (t Tri) String() string

String writes a Tri the way the API does: true, false or unknown.

func (*Tri) UnmarshalJSON

func (t *Tri) UnmarshalJSON(b []byte) error

UnmarshalJSON reads true, false or "unknown".

type Verdict

type Verdict struct {
	Category    string
	Subcategory string
	Signals     []string
	// Attributes the page settles. Anything the page does not say stays
	// TriUnknown: research never guesses an attribute into place.
	IsDisposable      Tri
	IsPublicInbox     Tri
	IsFreeProvider    Tri
	IsForwarder       Tri
	IsAliasService    Tri
	IsPrivacyProvider Tri
	// Note is the model's own one-line reason, kept for a person reading
	// the record. It never goes into an event.
	Note string
}

Verdict is what the model made of the evidence.

func ParseVerdict

func ParseVerdict(raw []byte) (Verdict, error)

ParseVerdict reads the model's answer, keeping only codes the taxonomy has. A model that invents a category gets ErrVerdict; one that invents a signal or an attribute value loses that field, not the answer.

Jump to

Keyboard shortcuts

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