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
- Variables
- func Minify(src string) string
- func PlainText(src string) string
- func PublicOnly(_, address string, _ syscall.RawConn) error
- func RegistrableDomain(host string) string
- func SectionContainer(doc *html.Node) *html.Node
- func SubjectHeuristics(subject string) []string
- func SuggestSubject(subject string) string
- type Blocklist
- type Checker
- type ContentCheckFix
- type ContentCheckIssue
- type ContentCheckLink
- type ContentCheckReport
- type ContentCheckSection
- type HTTPProber
- type Input
- type ProbeResult
- type Prober
- type StaticBlocklist
- type StoreBlocklist
Constants ¶
const ( Block = "block" Warn = "warn" Info = "info" Pass = "pass" )
Severities, in the order checks are listed.
const ClipBytes = 102 * 1024
ClipBytes is the size at which Gmail clips a message (102 KB).
const NearClipBytes = 85 * 1024
NearClipBytes is where the size warning starts.
Variables ¶
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 ¶
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 ¶
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 ¶
PublicOnly is a net.Dialer Control function that refuses non-public IPs.
func RegistrableDomain ¶
RegistrableDomain returns the domain someone registers ("acme.io" for "news.acme.io").
func SectionContainer ¶
SectionContainer returns the element whose children are the email's top-level sections in MJML output (body > div > div…), or nil.
func SubjectHeuristics ¶
SubjectHeuristics returns the spam heuristics a subject trips: "all caps", "repeated punctuation", "urgency", "money words".
func SuggestSubject ¶
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 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 ¶
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.
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 ¶
StaticBlocklist is a fixed map, for tests and installs without lookups.
type StoreBlocklist ¶
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.