diff --git a/config.go b/config.go index b93a3026..9f244663 100644 --- a/config.go +++ b/config.go @@ -45,6 +45,9 @@ type ServerConfig struct { // Hostname will also be used to fill the 'Host' property when the "RCPT TO" address is // addressed to just Hostname string `json:"host_name"` + // GreetingType sets the greeting message which will be sent to clients. + // Currently, the options are "guerrilla" and "postfix". Defaults to "postfix". + GreetingType string `json:"greeting_type"` // Listen interface specified in : - defaults to 127.0.0.1:2525 ListenInterface string `json:"listen_interface"` // MaxSize is the maximum size of an email that will be accepted for delivery. @@ -155,6 +158,7 @@ const defaultMaxClients = 100 const defaultTimeout = 30 const defaultInterface = "127.0.0.1:2525" const defaultMaxSize = int64(10 << 20) // 10 Mebibytes +const defaultGreetingType = "postfix" // Unmarshalls json data into AppConfig struct and any other initialization of the struct // also does validation, returns error if validation failed or something went wrong @@ -288,6 +292,7 @@ func (c *AppConfig) setDefaults() error { sc.MaxClients = defaultMaxClients sc.Timeout = defaultTimeout sc.MaxSize = defaultMaxSize + sc.GreetingType = defaultGreetingType c.Servers = append(c.Servers, sc) } else { // make sure each server has defaults correctly configured @@ -310,6 +315,9 @@ func (c *AppConfig) setDefaults() error { if c.Servers[i].LogFile == "" { c.Servers[i].LogFile = c.LogFile } + if c.Servers[i].GreetingType == "" { + c.Servers[i].GreetingType = defaultGreetingType + } // validate the server config err = c.Servers[i].Validate() if err != nil { @@ -451,6 +459,11 @@ func (sc *ServerConfig) Validate() error { errs = append(errs, fmt.Errorf("cannot use TLS config for [%s], %v", sc.ListenInterface, err)) } } + + if sc.GreetingType != "postfix" && sc.GreetingType != "guerrilla" { + errs = append(errs, errors.New("Unrecognised greeting_type. Valid options are 'postfix' and 'guerrilla'.")) + } + if len(errs) > 0 { return errs } diff --git a/goguerrilla.conf.sample b/goguerrilla.conf.sample index ee3d8d87..2122ec19 100644 --- a/goguerrilla.conf.sample +++ b/goguerrilla.conf.sample @@ -21,6 +21,7 @@ { "is_enabled" : true, "host_name":"mail.test.com", + "greeting_type": "postfix", "max_size": 1000000, "timeout":180, "listen_interface":"127.0.0.1:25", @@ -40,6 +41,7 @@ { "is_enabled" : false, "host_name":"mail.test.com", + "greeting_type": "postfix", "max_size":1000000, "timeout":180, "listen_interface":"127.0.0.1:465", diff --git a/server.go b/server.go index 1ab96b5b..6098a211 100644 --- a/server.go +++ b/server.go @@ -367,9 +367,13 @@ func (s *server) handleClient(client *client) { s.log().Infof("Handle client [%s], id: %d", client.RemoteIP, client.ID) // Initial greeting - greeting := fmt.Sprintf("220 %s SMTP Guerrilla(%s) #%d (%d) %s", - sc.Hostname, Version, client.ID, - s.clientPool.GetActiveClientsCount(), time.Now().Format(time.RFC3339)) + // GreetingType == "postfix" by default + greeting := fmt.Sprintf("220 %s ESMTP Postfix", sc.Hostname) + if sc.GreetingType == "guerrilla" { + greeting = fmt.Sprintf("220 %s SMTP Guerrilla(%s) #%d (%d) %s", + sc.Hostname, Version, client.ID, + s.clientPool.GetActiveClientsCount(), time.Now().Format(time.RFC3339)) + } helo := fmt.Sprintf("250 %s Hello", sc.Hostname) // ehlo is a multi-line reply and need additional \r\n at the end diff --git a/tests/guerrilla_test.go b/tests/guerrilla_test.go index d6ba5b77..f15f5aa4 100644 --- a/tests/guerrilla_test.go +++ b/tests/guerrilla_test.go @@ -88,6 +88,7 @@ var configJson = ` { "is_enabled" : true, "host_name":"mail.guerrillamail.com", + "greeting_type": "postfix", "max_size": 100017, "timeout":160, "listen_interface":"127.0.0.1:2526", @@ -104,6 +105,7 @@ var configJson = ` { "is_enabled" : true, "host_name":"mail.guerrillamail.com", + "greeting_type": "guerrilla", "max_size":1000001, "timeout":180, "listen_interface":"127.0.0.1:4654", @@ -242,7 +244,7 @@ func TestGreeting(t *testing.T) { } defer cleanTestArtifacts(t) if startErrors := app.Start(); startErrors == nil { - // 1. plaintext connection + // 1. plaintext connection, postfix conn, err := net.Dial("tcp", config.Servers[0].ListenInterface) if err != nil { // handle error @@ -256,14 +258,14 @@ func TestGreeting(t *testing.T) { t.Error(err) t.FailNow() } else { - expected := "220 mail.guerrillamail.com SMTP Guerrilla" + expected := "220 mail.guerrillamail.com ESMTP Postfix" if strings.Index(greeting, expected) != 0 { t.Error("Server[1] did not have the expected greeting prefix", expected) } } _ = conn.Close() - // 2. tls connection + // 2. tls connection, guerrilla // roots, err := x509.SystemCertPool() conn, err = tls.Dial("tcp", config.Servers[1].ListenInterface, &tls.Config{