contentcheck

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package contentcheck finds deliverability problems in an email's content: size against Gmail's 102 KB clipping limit, images without alt text, the image-to-text ratio, links on URI blocklists, URL shorteners and broken links, a missing unsubscribe link or postal address, Liquid errors, spam heuristics in the subject, and the plain-text part.

The composer runs the fast checks inline as people edit; Send Readiness runs the full set (including link probing) before a send.

Index

Constants

View Source
const (
	Block = "block"
	Warn  = "warn"
	Info  = "info"
	Pass  = "pass"
)

Severities, in the order checks are listed.

View Source
const ClipBytes = 102 * 1024

ClipBytes is the size at which Gmail clips a message (102 KB).

View Source
const NearClipBytes = 85 * 1024

NearClipBytes is where the size warning starts.

Variables

View Source
var ErrBlockedAddress = errors.New("the link points at an internal address")

ErrBlockedAddress is returned when a link resolves to an internal address.

Functions

func Minify

func Minify(src string) string

Minify shrinks email HTML without changing how it renders: whitespace between tags and inside style attributes, and comments other than Outlook's conditional comments.

func PlainText

func PlainText(src string) string

PlainText turns email HTML into the text/plain part: one block per line, headings in capitals, buttons and standalone links as "Label: URL", the footer after a "--" separator, hidden preview text and comments dropped.

func PublicOnly

func PublicOnly(_, address string, _ syscall.RawConn) error

PublicOnly is a net.Dialer Control function that refuses non-public IPs.

func RegistrableDomain

func RegistrableDomain(host string) string

RegistrableDomain returns the domain someone registers ("acme.io" for "news.acme.io").

func SectionContainer

func SectionContainer(doc *html.Node) *html.Node

SectionContainer returns the element whose children are the email's top-level sections in MJML output (body > div > div…), or nil.

func SubjectHeuristics

func SubjectHeuristics(subject string) []string

SubjectHeuristics returns the spam heuristics a subject trips: "all caps", "repeated punctuation", "urgency", "money words".

func SuggestSubject

func SuggestSubject(subject string) string

SuggestSubject rewrites a shouty subject so that it trips none of the heuristics: sentence case, repeated punctuation collapsed and urgency softened ("FLASH SALE!!! 48 HOURS ONLY" → "48-hour flash sale"). It returns "" when no such rewrite exists.

Types

type Blocklist

type Blocklist interface {
	// Listings returns, for each listed domain, the lists it is on. Clean
	// and unknown domains are absent.
	Listings(ctx context.Context, domains []string) (map[string][]string, error)
}

Blocklist answers which URI blocklists list a domain.

type Checker

type Checker struct {
	Blocklist Blocklist
	Prober    Prober
	Now       func() time.Time
}

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, in Input) (ContentCheckReport, error)

Check runs every check on the content.

type ContentCheckFix

type ContentCheckFix struct {
	Kind  string `json:"kind" enum:"replace_link,edit_link,insert_footer,set_alt,minify,remove_section,use_subject"`
	Label string `json:"label"`
	Value string `json:"value,omitempty"`
	Path  []int  `json:"path,omitempty"`
}

ContentCheckFix is a one-click fix offered with an issue. The composer applies it to the canvas (Path points at the component) or to the campaign settings.

type ContentCheckIssue

type ContentCheckIssue struct {
	ID       string `json:"id" example:"links.blocklist"`
	Severity string `json:"severity" enum:"block,warn,info,pass"`
	Group    string `json:"group" enum:"Content,Links,Compliance,Subject,Personalization"`
	Title    string `json:"title"`
	Detail   string `json:"detail,omitempty"`
	// Tag is the short label shown on the canvas next to the element.
	Tag string `json:"tag,omitempty"`
	// Path locates the element from mj-body (element indices, comments
	// excluded); empty when the issue concerns the whole email.
	Path []int `json:"path"`
	// Section is the top-level section index, -1 for the whole email.
	Section int               `json:"section"`
	Fixes   []ContentCheckFix `json:"fixes"`
	// URL is the link a link issue is about (to find it inside text).
	URL string `json:"url,omitempty"`
}

ContentCheckIssue is one finding.

type ContentCheckLink struct {
	URL  string `json:"url"`
	Host string `json:"host"`
	Text string `json:"text"`
	Kind string `json:"kind" enum:"button,link,image,nav,social"`
	Path []int  `json:"path"`
	// Probed is true when the link was requested; Status, Broken, Millis
	// and Final (the address after redirects) describe the response.
	Probed bool   `json:"probed"`
	Status int    `json:"status,omitempty"`
	Broken bool   `json:"broken,omitempty"`
	Millis int    `json:"millis,omitempty"`
	Final  string `json:"final,omitempty"`
}

ContentCheckLink is one link of the email.

type ContentCheckReport

type ContentCheckReport struct {
	Verdict          string `json:"verdict" enum:"ready,warnings,blocked"`
	Blocks           int    `json:"blocks"`
	Warnings         int    `json:"warnings"`
	SizeBytes        int    `json:"sizeBytes"`
	ClipBytes        int    `json:"clipBytes"`
	Images           int    `json:"images"`
	ImagesMissingAlt int    `json:"imagesMissingAlt"`
	Links            int    `json:"links"`
	LinksBlocklisted int    `json:"linksBlocklisted"`
	LinksBroken      int    `json:"linksBroken"`
	// SubjectHeuristics names the spam heuristics the subject trips.
	SubjectHeuristics []string              `json:"subjectHeuristics"`
	Issues            []ContentCheckIssue   `json:"issues"`
	Sections          []ContentCheckSection `json:"sections"`
	PlainText         string                `json:"plainText"`
	CheckedAt         time.Time             `json:"checkedAt"`
	// ImageShare is the estimated share of the email's area covered by
	// images (0 to 1; 0 without images). Words counts the plain text.
	ImageShare float64 `json:"imageShare"`
	Words      int     `json:"words"`
	// LinkList is every link with its text and, when links were probed, the
	// response (Send Readiness shows the slowest and the link domains).
	LinkList []ContentCheckLink `json:"linkList"`
}

ContentCheckReport is the outcome of a check run.

type ContentCheckSection

type ContentCheckSection struct {
	Index         int    `json:"index"`
	Label         string `json:"label"`
	Images        int    `json:"images"`
	ImagesWithAlt int    `json:"imagesWithAlt"`
	Links         int    `json:"links"`
	LinksOK       int    `json:"linksOk"`
	Issues        int    `json:"issues"`
}

ContentCheckSection is what the inspector shows for the selected section.

type HTTPProber

type HTTPProber struct {
	Client *http.Client
	// MaxLinks caps how many links one run requests.
	MaxLinks int
	// Concurrency is how many requests run at once.
	Concurrency int
	// contains filtered or unexported fields
}

HTTPProber requests links with HEAD (GET when HEAD isn't allowed), with short timeouts and an SSRF guard: it never connects to loopback, private, link-local or otherwise internal addresses, also after redirects.

func NewHTTPProber

func NewHTTPProber() *HTTPProber

NewHTTPProber returns a prober with the SSRF guard on its dialer.

func (*HTTPProber) Probe

func (p *HTTPProber) Probe(ctx context.Context, urls []string) map[string]ProbeResult

Probe implements Prober. Results are cached for ten minutes.

type Input

type Input struct {
	Subject   string
	Preheader string
	MJML      string
	HTML      string
	// OwnDomains are the workspace's sending domains ("news.acme.io"); fixes
	// for blocklisted links point at their registrable domain.
	OwnDomains []string
	// Address is the postal address from the workspace's branding, if set.
	Address string
	// Fields are the personalization tokens that exist (liquid.Catalog keys).
	Fields []string
	// ProbeLinks requests each link (Send Readiness); the composer skips it.
	ProbeLinks bool
}

Input is the content to check.

type ProbeResult

type ProbeResult struct {
	Status int    `json:"status"`
	Broken bool   `json:"broken"`
	Error  string `json:"error,omitempty"`
	// Millis is how long the response took; Final is the address after
	// redirects (empty when the link didn't redirect).
	Millis int    `json:"millis,omitempty"`
	Final  string `json:"final,omitempty"`
}

ProbeResult is the outcome of requesting one link.

type Prober

type Prober interface {
	Probe(ctx context.Context, urls []string) map[string]ProbeResult
}

Prober requests links to find broken ones.

type StaticBlocklist

type StaticBlocklist map[string][]string

StaticBlocklist is a fixed map, for tests and installs without lookups.

func (StaticBlocklist) Listings

func (b StaticBlocklist) Listings(_ context.Context, domains []string) (map[string][]string, error)

Listings implements Blocklist.

type StoreBlocklist

type StoreBlocklist struct {
	Q store.Querier
}

StoreBlocklist reads URI blocklist results cached in link_domain_listings. Deliverability lookups (DNS, HostRepute) write that table; content checks only read it, so they stay fast.

func (StoreBlocklist) Listings

func (b StoreBlocklist) Listings(ctx context.Context, domains []string) (map[string][]string, error)

Listings implements Blocklist.

Jump to

Keyboard shortcuts

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