mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 12:24:38 +03:00
more strict junk checks for some first-time senders: when TLS isn't used and when recipient address isn't in To/Cc header
both cases are quite typical for spammers, and not for legitimate senders. this doesn't apply to known senders. and it only requires that the content look more like ham instead of spam. so legitimate mail can still get through with these properties.
This commit is contained in:
@ -17,7 +17,7 @@ import (
|
||||
// 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(log *mlog.Log, strict bool, r io.ReaderAt) (raddr smtp.Address, header textproto.MIMEHeader, rerr error) {
|
||||
func From(log *mlog.Log, strict bool, r io.ReaderAt) (raddr smtp.Address, envelope *Envelope, header textproto.MIMEHeader, rerr error) {
|
||||
// ../rfc/7489:1243
|
||||
|
||||
// todo: only allow utf8 if enabled in session/message?
|
||||
@ -25,20 +25,20 @@ func From(log *mlog.Log, strict bool, r io.ReaderAt) (raddr smtp.Address, header
|
||||
p, err := Parse(log, strict, r)
|
||||
if err != nil {
|
||||
// todo: should we continue with p, perhaps headers can be parsed?
|
||||
return raddr, nil, fmt.Errorf("parsing message: %v", err)
|
||||
return raddr, nil, nil, fmt.Errorf("parsing message: %v", err)
|
||||
}
|
||||
header, err = p.Header()
|
||||
if err != nil {
|
||||
return raddr, nil, fmt.Errorf("parsing message header: %v", err)
|
||||
return raddr, nil, nil, fmt.Errorf("parsing message header: %v", err)
|
||||
}
|
||||
from := p.Envelope.From
|
||||
if len(from) != 1 {
|
||||
return raddr, nil, fmt.Errorf("from header has %d addresses, need exactly 1 address", len(from))
|
||||
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, fmt.Errorf("bad domain in from address: %v", err)
|
||||
return raddr, nil, nil, fmt.Errorf("bad domain in from address: %v", err)
|
||||
}
|
||||
addr := smtp.Address{Localpart: smtp.Localpart(from[0].User), Domain: d}
|
||||
return addr, textproto.MIMEHeader(header), nil
|
||||
return addr, p.Envelope, textproto.MIMEHeader(header), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user