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]>
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package tlsrpt_test
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"log/slog"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
"github.com/hanzoai/mail/tlsrpt"
|
|
)
|
|
|
|
func ExampleLookup() {
|
|
ctx := context.Background()
|
|
resolver := dns.StrictResolver{}
|
|
domain, err := dns.ParseDomain("domain.example")
|
|
if err != nil {
|
|
log.Fatalf("parsing domain: %v", err)
|
|
}
|
|
|
|
// Lookup TLSRPT record in DNS, and parse it.
|
|
record, txt, err := tlsrpt.Lookup(ctx, slog.Default(), resolver, domain)
|
|
if err != nil {
|
|
log.Fatalf("looking up tlsrpt record: %v", err)
|
|
}
|
|
|
|
log.Printf("TLSRPT record: %s", txt)
|
|
log.Printf("Parsed: %v", record)
|
|
}
|
|
|
|
func ExampleParseMessage() {
|
|
// Message, as received over SMTP.
|
|
msg := `From: <[email protected]>
|
|
To: <[email protected]>
|
|
Subject: Report Domain: example.net
|
|
Report-ID: <[email protected]>
|
|
TLS-Report-Domain: example.net
|
|
TLS-Report-Submitter: mail.sender.example.com
|
|
MIME-Version: 1.0
|
|
Content-Type: application/tlsrpt+gzip
|
|
Content-Transfer-Encoding: base64
|
|
Content-Disposition: attachment;
|
|
filename="mail.sender.example!example.com!1013662812!1013749130.json.gz"
|
|
|
|
H4sIAPZreGUAA51UbW/aMBD+DL/Cyr5NdeokJIVI0za1aPswdRWgiXWqImMbai2JI9tBMMR/n52Y
|
|
lwkx2KQocXx3vud57s6bbscTcoFL/gtrLkpY4oJ5KfDuRVHhcg2n3o1xoVgzKHG5sLZNt9PxlMZS
|
|
Q7uveRsRoiCBqAdRMEEobZ5nG9zxWEnPeYZRGg/M8+x1O1ubiYhSY6IhL+fC+iqtoGSVkJqXiw/E
|
|
oVr5bIWLKmcNutYOObUBMUriXnhHYBjRCPbuCIazhCE46CUMI9YnvVkbVYmcE86UCfphUFpWbnPt
|
|
SO7/oV5XzKFpKB0sSksDzJ1h95dMKiNkCsaT8TJw3h2vEJSlQDNleRx2Vyl46xeY5/6O2vqYWuuE
|
|
VxlemOh+0kPIa3Zf/kRBhTmjtAjPHWNSwVeh9BHSs4nbDPa9bYI9VRcFlkeyaKFxDlVNCFNqXpul
|
|
+dr2IaIubY44CpObY9+5SVVLduIYoego0c6LMm1Wag924yBLpupc78tBmGmLOSe2O9mq4pLRvWrK
|
|
dJ2RGhYaQ161bYeClM76KZ4RarozCNP0UCDJCOPLJqJVajcJxSq4VCELm9ETbgFCjUNL7hyJZpJ0
|
|
rmAptJG0sr38bzyiK3mEl3gcYneZIh/5QRD5cXKJrEG188CUcnuZmLLbMZZFc7XYA1+1rlR6e9tO
|
|
rPJP5tlZMhsH3gNOwTvgJhoQAEEYARq9AWOn2aPQ451iwLtC7CXOOW1vOtdrfxE6GPT9OPBNGf0k
|
|
vEak/jVVgDNMftbVf/ZUdGy3oyIZVo2dNudPYzTIvmXD0Sh7Gn2dfs+ePk4+Z1+Gj5/MZzi9Hw4f
|
|
hg9Oqa4bc7N46W67vwF2Eq+hDAYAAA==
|
|
`
|
|
msg = strings.ReplaceAll(msg, "\n", "\r\n")
|
|
|
|
// Parse the email message, and the TLSRPT report within.
|
|
reportJSON, err := tlsrpt.ParseMessage(slog.Default(), strings.NewReader(msg))
|
|
if err != nil {
|
|
log.Fatalf("parsing tlsrpt report in message: %v", err)
|
|
}
|
|
|
|
log.Printf("report: %#v", reportJSON)
|
|
}
|