spf

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: MIT Imports: 6 Imported by: 12

README

blitiri.com.ar/go/spf

GoDoc Build Status Go Report Card Coverage Status

spf is an open source implementation of the Sender Policy Framework (SPF) in Go.

It is used by the chasquid and maddy SMTP servers.

Example

The API is quite simple: it has only one main function to perform the SPF check, similar to the one suggested in the RFC.

// Check if `sender` is authorized to send from the given `ip`. The `domain`
// is used if the sender doesn't have one.
result, err := spf.CheckHostWithSender(ip, domain, sender)
if result == spf.Fail {
	// Not authorized to use the domain.
}

See the package documentation for more details.

Status

The API should be considered stable. Major version changes will be announced to the mailing list (details below).

Contact

If you have any questions, comments or patches please send them to the mailing list, [email protected].

To subscribe, send an email to [email protected].

You can also browse the archives.

Documentation

Overview

Package spf implements SPF (Sender Policy Framework) lookup and validation.

Sender Policy Framework (SPF) is a simple email-validation system designed to detect email spoofing by providing a mechanism to allow receiving mail exchangers to check that incoming mail from a domain comes from a host authorized by that domain's administrators [Wikipedia].

This package is intended to be used by SMTP servers to implement SPF validation.

All mechanisms and modifiers are supported:

all
include
a
mx
ptr
ip4
ip6
exists
redirect
exp (ignored)
Macros

References:

https://tools.ietf.org/html/rfc7208
https://en.wikipedia.org/wiki/Sender_Policy_Framework

Index

Constants

This section is empty.

Variables

View Source
var (
	// https://tools.ietf.org/html/rfc7208#section-8.1
	// Not able to reach any conclusion.
	None = Result("none")

	// https://tools.ietf.org/html/rfc7208#section-8.2
	// No definite assertion (positive or negative).
	Neutral = Result("neutral")

	// https://tools.ietf.org/html/rfc7208#section-8.3
	// Client is authorized to inject mail.
	Pass = Result("pass")

	// https://tools.ietf.org/html/rfc7208#section-8.4
	// Client is *not* authorized to use the domain
	Fail = Result("fail")

	// https://tools.ietf.org/html/rfc7208#section-8.5
	// Not authorized, but unwilling to make a strong policy statement/
	SoftFail = Result("softfail")

	// https://tools.ietf.org/html/rfc7208#section-8.6
	// Transient error while performing the check.
	TempError = Result("temperror")

	// https://tools.ietf.org/html/rfc7208#section-8.7
	// Records could not be correctly interpreted.
	PermError = Result("permerror")
)

Valid results.

Functions

This section is empty.

Types

type Result

type Result string

The Result of an SPF check. Note the values have meaning, we use them in headers. https://tools.ietf.org/html/rfc7208#section-8

func CheckHost

func CheckHost(ip net.IP, domain string) (Result, error)

CheckHost fetches SPF records for `domain`, parses them, and evaluates them to determine if `ip` is permitted to send mail for it. Because it doesn't receive enough information to handle macros well, its usage is not recommended, but remains supported for backwards compatibility. Reference: https://tools.ietf.org/html/rfc7208#section-4

func CheckHostWithSender

func CheckHostWithSender(ip net.IP, helo, sender string) (Result, error)

CheckHostWithSender fetches SPF records for `sender`'s domain, parses them, and evaluates them to determine if `ip` is permitted to send mail for it. The `helo` domain is used if the sender has no domain part. Reference: https://tools.ietf.org/html/rfc7208#section-4

Jump to

Keyboard shortcuts

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