1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

More config cleanups for #86

This commit is contained in:
James Hillyerd
2018-03-22 20:02:34 -07:00
parent 845cbedc0d
commit f0a94f4848
7 changed files with 23 additions and 23 deletions

View File

@@ -49,18 +49,18 @@ func init() {
func main() { func main() {
// Command line flags. // Command line flags.
help := flag.Bool("help", false, "Displays this help") help := flag.Bool("help", false, "Displays help on flags and env variables.")
pidfile := flag.String("pidfile", "", "Write our PID into the specified file") pidfile := flag.String("pidfile", "", "Write our PID into the specified file.")
logfile := flag.String("logfile", "stderr", "Write out log into the specified file") logfile := flag.String("logfile", "stderr", "Write out log into the specified file.")
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage: inbucket [options]") fmt.Fprintln(os.Stderr, "Usage: inbucket [options]")
flag.PrintDefaults() flag.PrintDefaults()
fmt.Fprintln(os.Stderr, "")
config.Usage()
} }
flag.Parse() flag.Parse()
if *help { if *help {
flag.Usage() flag.Usage()
fmt.Fprintln(os.Stderr, "")
config.Usage()
return return
} }
// Process configuration. // Process configuration.

View File

@@ -11,11 +11,11 @@ import (
const ( const (
prefix = "inbucket" prefix = "inbucket"
tableFormat = `Inbucket is configured via the environment. The following environment tableFormat = `Inbucket is configured via the environment. The following environment variables
variables can be used: can be used:
KEY DEFAULT REQUIRED DESCRIPTION KEY DEFAULT DESCRIPTION
{{range .}}{{usage_key .}} {{usage_default .}} {{usage_required .}} {{usage_description .}} {{range .}}{{usage_key .}} {{usage_default .}} {{usage_description .}}
{{end}}` {{end}}`
) )
@@ -42,16 +42,16 @@ type SMTP struct {
Domain string `required:"true" default:"inbucket" desc:"HELO domain"` Domain string `required:"true" default:"inbucket" desc:"HELO domain"`
DomainNoStore string `desc:"Load testing domain"` DomainNoStore string `desc:"Load testing domain"`
MaxRecipients int `required:"true" default:"200" desc:"Maximum RCPT TO per message"` MaxRecipients int `required:"true" default:"200" desc:"Maximum RCPT TO per message"`
MaxIdle time.Duration `required:"true" default:"300s" desc:"Idle network timeout"`
MaxMessageBytes int `required:"true" default:"2048000" desc:"Maximum message size"` MaxMessageBytes int `required:"true" default:"2048000" desc:"Maximum message size"`
StoreMessages bool `required:"true" default:"true" desc:"Store incoming mail?"` StoreMessages bool `required:"true" default:"true" desc:"Store incoming mail?"`
Timeout time.Duration `required:"true" default:"300s" desc:"Idle network timeout"`
} }
// POP3 contains the POP3 server configuration. // POP3 contains the POP3 server configuration.
type POP3 struct { type POP3 struct {
Addr string `required:"true" default:"0.0.0.0:1100" desc:"POP3 server IP4 host:port"` Addr string `required:"true" default:"0.0.0.0:1100" desc:"POP3 server IP4 host:port"`
Domain string `required:"true" default:"inbucket" desc:"HELLO domain"` Domain string `required:"true" default:"inbucket" desc:"HELLO domain"`
MaxIdle time.Duration `required:"true" default:"600s" desc:"Idle network timeout"` Timeout time.Duration `required:"true" default:"600s" desc:"Idle network timeout"`
} }
// Web contains the HTTP server configuration. // Web contains the HTTP server configuration.

View File

@@ -496,7 +496,7 @@ func (ses *Session) sendMessageTop(msg storage.Message, lineCount int) {
// Load the users mailbox // Load the users mailbox
func (ses *Session) loadMailbox() { func (ses *Session) loadMailbox() {
m, err := ses.server.dataStore.GetMessages(ses.user) m, err := ses.server.store.GetMessages(ses.user)
if err != nil { if err != nil {
ses.logError("Failed to load messages for %v: %v", ses.user, err) ses.logError("Failed to load messages for %v: %v", ses.user, err)
} }
@@ -522,7 +522,7 @@ func (ses *Session) processDeletes() {
for i, msg := range ses.messages { for i, msg := range ses.messages {
if !ses.retain[i] { if !ses.retain[i] {
ses.logTrace("Deleting %v", msg) ses.logTrace("Deleting %v", msg)
if err := ses.server.dataStore.RemoveMessage(ses.user, msg.ID()); err != nil { if err := ses.server.store.RemoveMessage(ses.user, msg.ID()); err != nil {
ses.logWarn("Error deleting %v: %v", msg, err) ses.logWarn("Error deleting %v: %v", msg, err)
} }
} }
@@ -536,7 +536,7 @@ func (ses *Session) enterState(state State) {
// Calculate the next read or write deadline based on maxIdleSeconds // Calculate the next read or write deadline based on maxIdleSeconds
func (ses *Session) nextDeadline() time.Time { func (ses *Session) nextDeadline() time.Time {
return time.Now().Add(ses.server.maxIdle) return time.Now().Add(ses.server.timeout)
} }
// Send requested message, store errors in Session.sendError // Send requested message, store errors in Session.sendError

View File

@@ -15,20 +15,20 @@ import (
type Server struct { type Server struct {
host string host string
domain string domain string
maxIdle time.Duration timeout time.Duration
dataStore storage.Store store storage.Store
listener net.Listener listener net.Listener
globalShutdown chan bool globalShutdown chan bool
waitgroup *sync.WaitGroup waitgroup *sync.WaitGroup
} }
// New creates a new Server struct // New creates a new Server struct
func New(cfg config.POP3, shutdownChan chan bool, ds storage.Store) *Server { func New(cfg config.POP3, shutdownChan chan bool, store storage.Store) *Server {
return &Server{ return &Server{
host: cfg.Addr, host: cfg.Addr,
domain: cfg.Domain, domain: cfg.Domain,
dataStore: ds, store: store,
maxIdle: cfg.MaxIdle, timeout: cfg.Timeout,
globalShutdown: shutdownChan, globalShutdown: shutdownChan,
waitgroup: new(sync.WaitGroup), waitgroup: new(sync.WaitGroup),
} }

View File

@@ -414,7 +414,7 @@ func (ss *Session) greet() {
// Calculate the next read or write deadline based on maxIdle // Calculate the next read or write deadline based on maxIdle
func (ss *Session) nextDeadline() time.Time { func (ss *Session) nextDeadline() time.Time {
return time.Now().Add(ss.server.maxIdle) return time.Now().Add(ss.server.timeout)
} }
// Send requested message, store errors in Session.sendError // Send requested message, store errors in Session.sendError

View File

@@ -366,7 +366,7 @@ func setupSMTPServer(ds storage.Store) (s *Server, buf *bytes.Buffer, teardown f
Domain: "inbucket.local", Domain: "inbucket.local",
DomainNoStore: "bitbucket.local", DomainNoStore: "bitbucket.local",
MaxRecipients: 5, MaxRecipients: 5,
MaxIdle: 5, Timeout: 5,
MaxMessageBytes: 5000, MaxMessageBytes: 5000,
StoreMessages: true, StoreMessages: true,
} }

View File

@@ -42,9 +42,9 @@ type Server struct {
domain string domain string
domainNoStore string domainNoStore string
maxRecips int maxRecips int
maxIdle time.Duration
maxMessageBytes int maxMessageBytes int
storeMessages bool storeMessages bool
timeout time.Duration
// Dependencies // Dependencies
apolicy *policy.Addressing // Address policy. apolicy *policy.Addressing // Address policy.
@@ -89,7 +89,7 @@ func NewServer(
domain: cfg.Domain, domain: cfg.Domain,
domainNoStore: strings.ToLower(cfg.DomainNoStore), domainNoStore: strings.ToLower(cfg.DomainNoStore),
maxRecips: cfg.MaxRecipients, maxRecips: cfg.MaxRecipients,
maxIdle: cfg.MaxIdle, timeout: cfg.Timeout,
maxMessageBytes: cfg.MaxMessageBytes, maxMessageBytes: cfg.MaxMessageBytes,
storeMessages: cfg.StoreMessages, storeMessages: cfg.StoreMessages,
globalShutdown: globalShutdown, globalShutdown: globalShutdown,