mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package spf_test
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"log/slog"
|
|
"net"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
"github.com/hanzoai/mail/smtp"
|
|
"github.com/hanzoai/mail/spf"
|
|
)
|
|
|
|
func ExampleVerify() {
|
|
ctx := context.Background()
|
|
resolver := dns.StrictResolver{}
|
|
|
|
args := spf.Args{
|
|
// IP from SMTP session.
|
|
RemoteIP: net.ParseIP("1.2.3.4"),
|
|
|
|
// Based on "MAIL FROM" in SMTP session.
|
|
MailFromLocalpart: smtp.Localpart("user"),
|
|
MailFromDomain: dns.Domain{ASCII: "sendingdomain.example.com"},
|
|
|
|
// From HELO/EHLO in SMTP session.
|
|
HelloDomain: dns.IPDomain{Domain: dns.Domain{ASCII: "mx.example.com"}},
|
|
|
|
// LocalIP and LocalHostname should be set, they may be used when evaluating macro's.
|
|
}
|
|
|
|
// Lookup SPF record and evaluate against IP and domain in args.
|
|
received, domain, explanation, authentic, err := spf.Verify(ctx, slog.Default(), resolver, args)
|
|
|
|
// received.Result is always set, regardless of err.
|
|
switch received.Result {
|
|
case spf.StatusNone:
|
|
log.Printf("no useful spf result, domain probably has no spf record")
|
|
case spf.StatusNeutral:
|
|
log.Printf("spf has no statement on ip, with \"?\" qualifier")
|
|
case spf.StatusPass:
|
|
log.Printf("ip is authorized")
|
|
case spf.StatusFail:
|
|
log.Printf("ip is not authorized, with \"-\" qualifier")
|
|
case spf.StatusSoftfail:
|
|
log.Printf("ip is probably not authorized, with \"~\" qualifier, softfail")
|
|
case spf.StatusTemperror:
|
|
log.Printf("temporary error, possibly dns lookup failure, try again soon")
|
|
case spf.StatusPermerror:
|
|
log.Printf("permanent error, possibly invalid spf records, later attempts likely have the same result")
|
|
}
|
|
if err != nil {
|
|
log.Printf("error: %v", err)
|
|
}
|
|
if explanation != "" {
|
|
log.Printf("explanation from remote about spf result: %s", explanation)
|
|
}
|
|
log.Printf("result is for domain %s", domain) // mailfrom or ehlo/ehlo.
|
|
log.Printf("dns lookups dnssec-protected: %v", authentic)
|
|
}
|