useragent

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package useragent recognizes the user agents of machines that fetch email images and follow links: security scanners, link checkers, HTTP libraries, crawlers and link previews (review AN-9). It matches whole product tokens rather than substrings, so a phone called CUBOT or a browser build with "bot" inside a word is still a person.

The patterns are a list the instance keeps (tracking_user_agents, review AN-2): the built-in ones come with releases, and instance admins add the ones they meet. Words that mark any machine (a word ending in "bot", "crawler", "spider", "slurp", a "preview") are rules, not patterns; a person's device whose word a rule takes for a machine is listed as a person.

Index

Constants

View Source
const (
	Headless = "a headless browser"
	Script   = "a script"
	AnyBot   = "a bot"
	Preview  = "a link preview"
)

Kinds of machines, as Bot names them when it isn't a product.

View Source
const (
	// KindScanner: a mail-security scanner or link checker, by its name.
	KindScanner = "scanner"
	// KindScript: an HTTP library or a script.
	KindScript = "script"
	// KindHeadless: a headless browser.
	KindHeadless = "headless"
	// KindPreview: a chat app's or social network's link preview.
	KindPreview = "preview"
	// KindPerson: a word of a person's device or app that a rule would
	// take for a machine's ("CUBOT" phones end in "bot").
	KindPerson = "person"
)

Kinds of patterns (tracking_user_agents.kind).

Variables

Kinds are the pattern kinds, machines first.

Functions

func Bot

func Bot(ua string) string

Bot returns what kind of machine a user agent is by the built-in list ("Barracuda", "a script", "a bot", "a link preview"), or "" for a browser or mail client.

func TakesPeople

func TakesPeople(text string) bool

TakesPeople reports whether a machine pattern is found in the user agent of a browser or mail client people read email with.

func Word

func Word(text string) bool

Word reports whether a person's pattern is one word, as the rules read a user agent: letters and digits.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List is a user agent list: machines found by their patterns, and the words of people's devices the rules would take for machines.

func NewList

func NewList(ps []Pattern) *List

NewList makes a list of patterns (machines in their order).

func (*List) Bot

func (l *List) Bot(ua string) string

Bot returns what kind of machine a user agent is by the list, or "" for a browser or mail client. A nil list is the built-in one.

type Pattern

type Pattern struct {
	// Text is lower case. A machine's is found anywhere in the user agent;
	// a person's is a whole word of it.
	Text string
	Kind string
	// Name is the product or who runs it ("Barracuda"); a script, headless
	// browser or link preview may have none.
	Name string
}

Pattern is one entry of a user agent list.

func Builtin

func Builtin() []Pattern

Builtin are the patterns that come with ReputeCast.

func (Pattern) What

func (p Pattern) What() string

What is what the pattern's machine is called in a verdict: its name, or its kind ("a script").

Jump to

Keyboard shortcuts

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