}
func (conn *connection) getReceivedInfo(envelope Envelope) []byte {
- rhost, _, err := net.SplitHostPort(conn.remoteAddr.String())
- if err != nil {
- rhost = conn.remoteAddr.String()
- }
-
- rhosts, err := net.LookupAddr(rhost)
- if err == nil {
- rhost = fmt.Sprintf("%s [%s]", rhosts[0], rhost)
- }
-
- base := fmt.Sprintf("Received: from %s (%s)\r\n ", conn.ehlo, rhost)
+ base := fmt.Sprintf("Received: from %s (%s)\r\n ", conn.ehlo, lookupRemoteHost(conn.remoteAddr))
with := "SMTP"
if conn.esmtp {
fmt.Fprintf(sw, "Original-Envelope-ID: %s\n", env.ID)
fmt.Fprintf(sw, "Reporting-UA: %s\n", env.EHLO)
if env.RemoteAddr != nil {
- rhosts, err := net.LookupAddr(env.RemoteAddr.String())
- if err == nil {
- fmt.Fprintf(sw, "Reporting-MTA: %s\n", rhosts[0])
- }
- fmt.Fprintf(sw, "X-Remote-Address: %s\n", env.RemoteAddr)
+ fmt.Fprintf(sw, "Reporting-MTA: dns; %s\n", lookupRemoteHost(env.RemoteAddr))
}
fmt.Fprintf(sw, "Date: %s\n", env.Received.Format(time.RFC1123Z))
t.Errorf("Missing %q in %q", expected, contentStr)
}
- expected = "Reporting-MTA: localhost\n"
- if !strings.Contains(contentStr, expected) {
- t.Errorf("Missing %q in %q", expected, contentStr)
- }
-
- expected = "X-Remote-Address: 127.0.0.1\n"
+ expected = "Reporting-MTA: dns; localhost [127.0.0.1]\n"
if !strings.Contains(contentStr, expected) {
t.Errorf("Missing %q in %q", expected, contentStr)
}
return fmt.Sprintf("%s.%d.%x", prefix, t.UnixNano(), idBytes)
}
+// lookupRemoteHost attempts to reverse look-up the provided IP address. On
+// success, it returns the hostname and the IP as formatted for a receive
+// trace. If the lookup fails, it just returns the original IP.
+func lookupRemoteHost(addr net.Addr) string {
+ rhost, _, err := net.SplitHostPort(addr.String())
+ if err != nil {
+ rhost = addr.String()
+ }
+
+ rhosts, err := net.LookupAddr(rhost)
+ if err == nil {
+ rhost = fmt.Sprintf("%s [%s]", rhosts[0], rhost)
+ }
+
+ return rhost
+}
+
type Server interface {
Name() string
TLSConfig() *tls.Config