author | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-11 20:44:36 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-21 21:13:39 UTC |
parent | 008cd98e398ae4b8ddbd489c3b05ee3744435ecd |
chasquid.go | +18 | -2 |
test/t-05-null_address/expected_dsr | +1 | -1 |
test/t-05-null_address/sendmail | +1 | -1 |
diff --git a/chasquid.go b/chasquid.go index e7bb41f..179ad8f 100644 --- a/chasquid.go +++ b/chasquid.go @@ -422,6 +422,9 @@ type Conn struct { // TLS configuration. tlsConfig *tls.Config + // Address given at HELO/EHLO, used for tracing purposes. + ehloAddress string + // Envelope. mailFrom string rcptTo []string @@ -565,6 +568,11 @@ loop: } func (c *Conn) HELO(params string) (code int, msg string) { + if len(strings.TrimSpace(params)) == 0 { + return 501, "Invisible customers are not welcome!" + } + c.ehloAddress = strings.Fields(params)[0] + types := []string{ "general store", "used armor dealership", "second-hand bookstore", "liquor emporium", "antique weapons outlet", "delicatessen", @@ -577,6 +585,11 @@ func (c *Conn) HELO(params string) (code int, msg string) { } func (c *Conn) EHLO(params string) (code int, msg string) { + if len(strings.TrimSpace(params)) == 0 { + return 501, "Invisible customers are not welcome!" + } + c.ehloAddress = strings.Fields(params)[0] + buf := bytes.NewBuffer(nil) fmt.Fprintf(buf, c.hostname+" - Your hour of destiny has come.\n") fmt.Fprintf(buf, "8BITMIME\n") @@ -767,6 +780,9 @@ func (c *Conn) RCPT(params string) (code int, msg string) { } func (c *Conn) DATA(params string) (code int, msg string) { + if c.ehloAddress == "" { + return 503, "Invisible customers are not welcome!" + } if c.mailFrom == "" { return 503, "sender not yet given" } @@ -832,10 +848,10 @@ func (c *Conn) addReceivedHeader() { if c.completedAuth { v += fmt.Sprintf("from %s (authenticated as %s@%s)\n", - envelope.DomainOf(c.mailFrom), c.authUser, c.authDomain) + c.ehloAddress, c.authUser, c.authDomain) } else { v += fmt.Sprintf("from %s (%s)\n", - envelope.DomainOf(c.mailFrom), c.netconn.RemoteAddr().String()) + c.ehloAddress, c.netconn.RemoteAddr().String()) } v += fmt.Sprintf("by %s (chasquid)\n", c.hostname) diff --git a/test/t-05-null_address/expected_dsr b/test/t-05-null_address/expected_dsr index 080ac89..2f2a1c2 100644 --- a/test/t-05-null_address/expected_dsr +++ b/test/t-05-null_address/expected_dsr @@ -20,7 +20,7 @@ Delivery to the following recipient(s) failed permanently: ----- Original message ----- -Received: from testserver (authenticated as user@testserver) +Received: from localhost (authenticated as user@testserver) by testserver (chasquid) (over * (envelope from "user@testserver") diff --git a/test/t-05-null_address/sendmail b/test/t-05-null_address/sendmail index 4b7c677..c743d92 100644 --- a/test/t-05-null_address/sendmail +++ b/test/t-05-null_address/sendmail @@ -1,4 +1,4 @@ -EHLO +EHLO localhost MAIL FROM: <> RCPT TO: user@testserver DATA