SPF flattener
Turn the includes in an SPF record into IP addresses, to get under the limit of 10 DNS lookups. You get a record set ready to publish.
How it works
SPF (a DNS record that lists the servers allowed to send email for your domain) may make at most 10 DNS lookups. Each include:, a, mx and redirect costs one, and includes can contain more includes. Add a few email services and you pass 10. Receivers then return permerror, and SPF fails for all your mail.
Flattening looks up every include, a and mx term once, now, and writes the addresses it finds as ip4: and ip6: terms, which cost no lookups. Neighbouring blocks are merged. If they don't fit in one record, the rest go into _spf1.example.com, _spf2.example.com and so on, chained with includes. Each record stays under 450 bytes, split into strings of at most 255 characters.
The catch: the flattened records are a snapshot. When a provider adds servers, mail from them fails SPF until you flatten again. So re-run this regularly, keep include: for big providers, and flatten only the small ones. Terms that depend on each message (exists, ptr, macros) and includes with their own exceptions stay as they are.
Check that the result works with the SPF IP check, or look at the published records with DNS lookup.