Spf.Tokens (Spfcheck v0.3.0) View Source
Combinators to turn an SPF string or an explain string into a list of token/0
's.
This module provides two combinators:
tokenize_spf/0
, which turns an SPF string into a list of tokenstokenize_exp/0
, which turns an explain string into tokens
which are used by Spf.Parser
for lexical analysis of an input string.
The start_token/6
and token/6
are helper functions for internal use by
Spf.Tokens
that should've been private, but it seems they cannot be.
Link to this section Summary
Types
qualifier = ?+ / ?- / ?~ / ??
range
denotes a token's start..stop
-slice in the input string.
A token represented as a tuple: {type, list, range}
.
The token's type
.
Functions
Token {:exp_str, [token], range}
.
Combinator that creates a list of tokens for the SPF terms found in an input string.
Link to this section Types
Specs
combinator() :: NimbleParsec.t()
Specs
q() :: 43 | 45 | 126 | 63
qualifier = ?+ / ?- / ?~ / ??
Specs
range() :: Range.t()
range
denotes a token's start..stop
-slice in the input string.
Specs
A token represented as a tuple: {type, list, range}
.
Where:
type
is an atom which denotes the tokentype/0
list
may be empty or contain one or more values (including subtokens)range
is thestart..stop
-slice in the input string
Specs
type() :: :a | :all | :exists | :exp | :exp_str | :include | :ip4 | :ip6 | :mx | :ptr | :redirect | :unknown | :unknown_mod | :version | :whitespace | :exp_str | :domspec | :dual_cidr | :qualifier | :expand | :literal | :toplabel
The token's type
.
There are several classes of tokens:
- the version:
:version
, - a mechanism:
:a, :all, :exists, :exp, :include, :ip4, :ip6, :mx, :ptr
- a modifier:
:exp, :redirect
, - an explain string:
exp_str
, - an unknown modifier:
unknown_mod
, - an unknown token:
unknown
- whitespace:
:whitespace
, - a subtoken:
:domspec, :dual_cidr, :qualifier
,:expand, :literal, :toplabel
Subtokens may appear as part of another token's value.
:exp_str
is produced by tokenizing the explain string. After expanding the
domain-spec of modifier exp=domain-spec
into a domain name, that domain's
TXT RR is retrieved and tokenized for later expansion into an explanation
string. This only happens when the SPF verdict is :fail
and the exp
modifier is present and has a valid domain name.
The :whitespace
token will match both spaces and tab characters in order to
be able to warn about multiple spaces and/or tab characters being used. Use
of a tab character is technically a syntax error, but this library only warns
about its use.
The :unknown
token is tried as a last resort and matches any non-space
sequence. When matched, it usually means the SPF string has a syntax error.
Link to this section Functions
Specs
tokenize_exp() :: combinator()
Token {:exp_str, [token], range}
.
Where token
's include: :expand
, :toplabel
, :literal
or :whitespace
.
After expanding the domain spec, of an :exp
-token into a domain name, its
TXT RR is retrieved. That RR's text value is called the explain-string.
This string is the only place where macro-letters c
, r
, or t
are
allowed.
The list of tokens can then be expanded into the final explanation by the parser.
Specs
tokenize_spf() :: combinator()
Combinator that creates a list of tokens for the SPF terms found in an input string.