Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ tests/pidfilex.pid
tests/testlog*
*.pem
backends/*.logs
backends/test_spf.log
tests/go-guerrilla.pid
35 changes: 17 additions & 18 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
Expand Down Expand Up @@ -180,7 +179,7 @@ func TestSMTPLoadFile(t *testing.T) {
}

`
err := ioutil.WriteFile("goguerrilla.conf.api", []byte(json), 0644)
err := os.WriteFile("goguerrilla.conf.api", []byte(json), 0644)
if err != nil {
t.Error("could not write guerrilla.conf.api", err)
return
Expand All @@ -207,7 +206,7 @@ func TestSMTPLoadFile(t *testing.T) {
t.Error("d.Config.LogFile != tests/go-guerrilla.pid")
}

err := ioutil.WriteFile("goguerrilla.conf.api", []byte(json2), 0644)
err := os.WriteFile("goguerrilla.conf.api", []byte(json2), 0644)
if err != nil {
t.Error("could not write guerrilla.conf.api", err)
return
Expand Down Expand Up @@ -254,7 +253,7 @@ func TestReopenLog(t *testing.T) {
d.Shutdown()
}

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -309,7 +308,7 @@ func TestReopenServerLog(t *testing.T) {
d.Shutdown()
}

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand All @@ -321,7 +320,7 @@ func TestReopenServerLog(t *testing.T) {
t.Error("Main log did not re-opened, expecting \"re-opened main log file\"")
}

b, err = ioutil.ReadFile(testServerLog)
b, err = os.ReadFile(testServerLog)
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -366,7 +365,7 @@ func TestSetConfig(t *testing.T) {
d.Shutdown()
}

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -471,7 +470,7 @@ func TestSetAddProcessor(t *testing.T) {

d.Shutdown()

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -501,39 +500,39 @@ func talkToServer(address string) (err error) {
return
}
in := bufio.NewReader(conn)
str, err := in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
_, err = fmt.Fprint(conn, "HELO maildiranasaurustester\r\n")
if err != nil {
return err
}
str, err = in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
_, err = fmt.Fprint(conn, "MAIL FROM:<test@example.com>r\r\n")
if err != nil {
return err
}
str, err = in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
_, err = fmt.Fprint(conn, "RCPT TO:<test@grr.la>\r\n")
if err != nil {
return err
}
str, err = in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
_, err = fmt.Fprint(conn, "DATA\r\n")
if err != nil {
return err
}
str, err = in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
Expand All @@ -553,11 +552,11 @@ func talkToServer(address string) (err error) {
if err != nil {
return err
}
str, err = in.ReadString('\n')
_, err = in.ReadString('\n')
if err != nil {
return err
}
_ = str

return nil
}

Expand Down Expand Up @@ -636,7 +635,7 @@ func TestPubSubAPI(t *testing.T) {
t.Error(err)
}

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -669,7 +668,7 @@ func TestAPILog(t *testing.T) {
t.Error("log dest is not tests/testlog, it was ", l.GetLogDest())
}

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down Expand Up @@ -760,7 +759,7 @@ func TestCustomBackendResult(t *testing.T) {

d.Shutdown()

b, err := ioutil.ReadFile("tests/testlog")
b, err := os.ReadFile("tests/testlog")
if err != nil {
t.Error("could not read logfile")
return
Expand Down
3 changes: 1 addition & 2 deletions backends/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ func (s *service) shutdown() Errors {
// processor.
func (s *service) AddProcessor(name string, p ProcessorConstructor) {
// wrap in a constructor since we want to defer calling it
var c ProcessorConstructor
c = func() Decorator {
c := func() Decorator {
return p()
}
// add to our processors list
Expand Down
3 changes: 1 addition & 2 deletions backends/gateway_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package backends

import (
"fmt"
"strings"
"testing"
"time"
Expand All @@ -12,7 +11,7 @@ import (

func TestStates(t *testing.T) {
gw := BackendGateway{}
str := fmt.Sprintf("%s", gw.State)
str := gw.State.String()
if strings.Index(str, "NewState") != 0 {
t.Error("Backend should begin in NewState")
}
Expand Down
4 changes: 3 additions & 1 deletion backends/p_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ func (c *DataCompressor) String() string {
}

// clear it, without clearing the pool
/*
func (c *DataCompressor) clear() {
c.ExtraHeaders = []byte{}
c.Data = nil
}

*/
// Compress the email data and delivery header together
func Compressor() Decorator {
return func(p Processor) Processor {
return ProcessWith(func(e *mail.Envelope, task SelectTask) (Result, error) {
Expand Down
9 changes: 7 additions & 2 deletions backends/p_guerrilla_db_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type guerrillaDBAndRedisConfig struct {
// Load the backend config for the backend. It has already been unmarshalled
// from the main config file 'backend' config "backend_config"
// Now we need to convert each type and copy into the guerrillaDBAndRedisConfig struct
// currently unused
/*
func (g *GuerrillaDBAndRedisBackend) loadConfig(backendConfig BackendConfig) (err error) {
configType := BaseConfig(&guerrillaDBAndRedisConfig{})
bcfg, err := Svc.ExtractConfig(backendConfig, configType)
Expand All @@ -80,15 +82,18 @@ func (g *GuerrillaDBAndRedisBackend) loadConfig(backendConfig BackendConfig) (er
g.config = m
return nil
}
*/

// get the number of workers to use for the batcher
// currently unused
/*
func (g *GuerrillaDBAndRedisBackend) getNumberOfWorkers() int {
return g.config.NumberOfWorkers
}

*/
type redisClient struct {
isConnected bool
conn RedisConn
time int
}

// compressedData struct will be compressed using zlib when printed via fmt
Expand Down
7 changes: 3 additions & 4 deletions backends/p_redis_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package backends

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestRedisGeneric(t *testing.T) {
}()
if gateway, ok := g.(*BackendGateway); ok {
r := gateway.Process(e, TaskSaveMail)
if strings.Index(r.String(), "250 2.0.0 OK") == -1 {
if !strings.Contains(r.String(), "250 2.0.0 OK") {
t.Error("redis processor didn't result with expected result, it said", r)
}
}
Expand All @@ -47,11 +46,11 @@ func TestRedisGeneric(t *testing.T) {
t.Error(err)
return
}
if b, err := ioutil.ReadFile("./test_redis.log"); err != nil {
if b, err := os.ReadFile("./test_redis.log"); err != nil {
t.Error(err)
return
} else {
if strings.Index(string(b), "SETEX") == -1 {
if !strings.Contains(string(b), "SETEX") {
t.Error("Log did not contain SETEX, the log was: ", string(b))
}
}
Expand Down
13 changes: 0 additions & 13 deletions backends/p_spf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,4 @@ func TestSpf(t *testing.T) {
t.Error("Log did not contain 'successfully uploaded', the log was: ", string(b))
return
}

return

if err := l.Close(); err != nil {
t.Error(err)
return
}

if err := os.Remove("./test_spf.log"); err != nil {
t.Error(err)
return
}

}
2 changes: 2 additions & 0 deletions backends/redis_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (m *RedisMockConn) Do(commandName string, args ...interface{}) (reply inter
return nil, nil
}

//lint:ignore U1000 Ignore unused function as we might need it later on
type dialOptions struct {
readTimeout time.Duration
writeTimeout time.Duration
Expand All @@ -37,6 +38,7 @@ type dialOptions struct {
}

type RedisDialOption struct {
//lint:ignore U1000 Ignore unused function as we might need it later on
f func(*dialOptions)
}

Expand Down
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type client struct {
bufin *smtpBufferedReader
bufout *bufio.Writer
smtpReader *textproto.Reader
ar *adjustableLimitedReader
//lint:ignore U1000 unused
ar *adjustableLimitedReader
// guards access to conn
connGuard sync.Mutex
log log.Logger
Expand Down Expand Up @@ -241,6 +242,10 @@ func (c *client) parsePath(in []byte, p pathParser) (mail.Address, error) {
return address, err
}

// rcptTo parses the recipient address
// currently unused
/*
func (s *server) rcptTo() (address mail.Address, err error) {
return address, err
}
*/
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (c *AppConfig) Load(jsonBytes []byte) error {
}
// check if any of the currently two tls options are enabled,
// if not, skip
if c.Servers[i].TLS.AlwaysOn == false && c.Servers[i].TLS.StartTLSOn == false {
if !(c.Servers[i].TLS.AlwaysOn || c.Servers[i].TLS.StartTLSOn) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion log/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type LogrusHook struct {
// newLogrusHook creates a new hook. dest can be a file name or one of the following strings:
// "stderr" - log to stderr, lines will be written to os.Stdout
// "stdout" - log to stdout, lines will be written to os.Stdout
// "off" - no log, lines will be written to ioutil.Discard
// "off" - no log, lines will be written to io.Discard
func NewLogrusHook(dest string) (LoggerHook, error) {
hookMu.Lock()
defer hookMu.Unlock()
Expand Down
7 changes: 3 additions & 4 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package log

import (
"io"
"io/ioutil"
"net"
"os"
"sync"
Expand Down Expand Up @@ -131,7 +130,7 @@ func GetLogger(dest string, level string) (Logger, error) {
return l, nil
}
// we'll use the hook to output instead
logrus.Out = ioutil.Discard
logrus.Out = io.Discard
// setup the hook
h, err := NewLogrusHook(dest)
if err != nil {
Expand Down Expand Up @@ -159,11 +158,11 @@ func newLogrus(o OutputOption, level string) (*log.Logger, error) {
} else if o == OutputStdout {
out = os.Stdout
} else if o == OutputOff {
out = ioutil.Discard
out = io.Discard
}
} else {
// we'll use a hook to output instead
out = ioutil.Discard
out = io.Discard
}

logger := &log.Logger{
Expand Down
3 changes: 1 addition & 2 deletions mail/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mail
import (
"fmt"
"io"
"io/ioutil"
"strings"
"testing"
)
Expand Down Expand Up @@ -116,7 +115,7 @@ func TestEnvelope(t *testing.T) {

r := e.NewReader()

data, _ := ioutil.ReadAll(r)
data, _ := io.ReadAll(r)
if len(data) != e.Len() {
t.Error("e.Len() is incorrect, it shown ", e.Len(), " but we wanted ", len(data))
}
Expand Down
Loading