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]>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package message
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log/slog"
|
|
"net/textproto"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
"github.com/hanzoai/mail/mlog"
|
|
"github.com/hanzoai/mail/smtp"
|
|
)
|
|
|
|
// From extracts the address in the From-header.
|
|
//
|
|
// An RFC5322 message must have a From header.
|
|
// In theory, multiple addresses may be present. In practice zero or multiple
|
|
// From headers may be present. From returns an error if there is not exactly
|
|
// one address. This address can be used for evaluating a DMARC policy against
|
|
// SPF and DKIM results.
|
|
func From(elog *slog.Logger, strict bool, r io.ReaderAt, p *Part) (raddr smtp.Address, envelope *Envelope, header textproto.MIMEHeader, rerr error) {
|
|
log := mlog.New("message", elog)
|
|
|
|
// ../rfc/7489:1243
|
|
|
|
// todo: only allow utf8 if enabled in session/message?
|
|
|
|
var err error
|
|
if p == nil {
|
|
var pp Part
|
|
pp, err = Parse(log.Logger, strict, r)
|
|
if err != nil {
|
|
// todo: should we continue with p, perhaps headers can be parsed?
|
|
return raddr, nil, nil, fmt.Errorf("parsing message: %v", err)
|
|
}
|
|
p = &pp
|
|
}
|
|
header, err = p.Header()
|
|
if err != nil {
|
|
return raddr, nil, nil, fmt.Errorf("parsing message header: %v", err)
|
|
}
|
|
from := p.Envelope.From
|
|
if len(from) != 1 {
|
|
return raddr, nil, nil, fmt.Errorf("from header has %d addresses, need exactly 1 address", len(from))
|
|
}
|
|
d, err := dns.ParseDomain(from[0].Host)
|
|
if err != nil {
|
|
return raddr, nil, nil, fmt.Errorf("bad domain in from address: %v", err)
|
|
}
|
|
lp, err := smtp.ParseLocalpart(from[0].User)
|
|
if err != nil {
|
|
return raddr, nil, nil, fmt.Errorf("parsing localpart in from address: %v", err)
|
|
}
|
|
addr := smtp.NewAddress(lp, d)
|
|
return addr, p.Envelope, textproto.MIMEHeader(header), nil
|
|
}
|