1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

chasquid: Make the "Received:" header RFC compliant

The Received header has some predefined structure and valid keywords,
this patch adjust how we create them to be compliant with that
structure.
This commit is contained in:
Alberto Bertogli
2016-10-08 18:38:54 +01:00
parent bc2b3b40a5
commit 3eac221a7f
2 changed files with 18 additions and 9 deletions

View File

@@ -807,19 +807,26 @@ func (c *Conn) DATA(params string) (code int, msg string) {
func (c *Conn) addReceivedHeader() {
var v string
// Format is semi-structured, defined by
// https://tools.ietf.org/html/rfc5321#section-4.4
if c.completedAuth {
v += fmt.Sprintf("from user %s@%s\n", c.authUser, c.authDomain)
v += fmt.Sprintf("from %s (authenticated as %s@%s)\n",
envelope.DomainOf(c.mailFrom), c.authUser, c.authDomain)
} else {
v += fmt.Sprintf("from %s\n", c.netconn.RemoteAddr().String())
v += fmt.Sprintf("from %s (%s)\n",
envelope.DomainOf(c.mailFrom), c.netconn.RemoteAddr().String())
}
v += fmt.Sprintf("by %s (chasquid SMTP) over ", c.hostname)
v += fmt.Sprintf("by %s (chasquid)\n", c.hostname)
v += "(over "
if c.tlsConnState != nil {
v += fmt.Sprintf("%s (%s)\n",
v += fmt.Sprintf("%s-%s)\n",
tlsconst.VersionName(c.tlsConnState.Version),
tlsconst.CipherSuiteName(c.tlsConnState.CipherSuite))
} else {
v += "plain text!\n"
v += "plain text!)\n"
}
// Note we must NOT include c.rcptTo, that would leak BCCs.
@@ -829,7 +836,7 @@ func (c *Conn) addReceivedHeader() {
// The ";" is a mandatory separator. The date format is not standard but
// this one seems to be widely used.
// https://tools.ietf.org/html/rfc5322#section-3.6.7
v += fmt.Sprintf("on ; %s\n", time.Now().Format(time.RFC1123Z))
v += fmt.Sprintf("; %s\n", time.Now().Format(time.RFC1123Z))
c.data = envelope.AddHeader(c.data, "Received", v)
if c.spfResult != "" {
@@ -850,6 +857,7 @@ func checkData(data []byte) error {
// This serves as a basic form of loop prevention. It's not infallible but
// should catch most instances of accidental looping.
// https://tools.ietf.org/html/rfc5321#section-6.3
if len(msg.Header["Received"]) > 50 {
loopsDetected.Add(1)
return fmt.Errorf("email passed through more than 50 MTAs, looping?")