Skip to content

Added greeting_type configuration option (#163) #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <postmaster>
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 <ip>:<port> - 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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions goguerrilla.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/guerrilla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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{

Expand Down