mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
cmd, pkg: add line breaks to several go source files
This commit is contained in:
@@ -71,6 +71,7 @@ func main() {
|
|||||||
config.Usage()
|
config.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process configuration.
|
// Process configuration.
|
||||||
config.Version = version
|
config.Version = version
|
||||||
config.BuildDate = date
|
config.BuildDate = date
|
||||||
@@ -83,6 +84,7 @@ func main() {
|
|||||||
conf.POP3.Debug = true
|
conf.POP3.Debug = true
|
||||||
conf.SMTP.Debug = true
|
conf.SMTP.Debug = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger setup.
|
// Logger setup.
|
||||||
closeLog, err := openLog(conf.LogLevel, *logfile, *logjson)
|
closeLog, err := openLog(conf.LogLevel, *logfile, *logjson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,12 +92,15 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
startupLog := log.With().Str("phase", "startup").Logger()
|
startupLog := log.With().Str("phase", "startup").Logger()
|
||||||
|
|
||||||
// Setup signal handler.
|
// Setup signal handler.
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
|
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
|
||||||
|
|
||||||
// Initialize logging.
|
// Initialize logging.
|
||||||
startupLog.Info().Str("version", config.Version).Str("buildDate", config.BuildDate).
|
startupLog.Info().Str("version", config.Version).Str("buildDate", config.BuildDate).
|
||||||
Msg("Inbucket starting")
|
Msg("Inbucket starting")
|
||||||
|
|
||||||
// Write pidfile if requested.
|
// Write pidfile if requested.
|
||||||
if *pidfile != "" {
|
if *pidfile != "" {
|
||||||
pidf, err := os.Create(*pidfile)
|
pidf, err := os.Create(*pidfile)
|
||||||
@@ -107,6 +112,7 @@ func main() {
|
|||||||
startupLog.Fatal().Err(err).Str("path", *pidfile).Msg("Failed to close pidfile")
|
startupLog.Fatal().Err(err).Str("path", *pidfile).Msg("Failed to close pidfile")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure internal services.
|
// Configure internal services.
|
||||||
rootCtx, rootCancel := context.WithCancel(context.Background())
|
rootCtx, rootCancel := context.WithCancel(context.Background())
|
||||||
shutdownChan := make(chan bool)
|
shutdownChan := make(chan bool)
|
||||||
@@ -118,20 +124,25 @@ func main() {
|
|||||||
msgHub := msghub.New(rootCtx, conf.Web.MonitorHistory)
|
msgHub := msghub.New(rootCtx, conf.Web.MonitorHistory)
|
||||||
addrPolicy := &policy.Addressing{Config: conf}
|
addrPolicy := &policy.Addressing{Config: conf}
|
||||||
mmanager := &message.StoreManager{AddrPolicy: addrPolicy, Store: store, Hub: msgHub}
|
mmanager := &message.StoreManager{AddrPolicy: addrPolicy, Store: store, Hub: msgHub}
|
||||||
|
|
||||||
// Start Retention scanner.
|
// Start Retention scanner.
|
||||||
retentionScanner := storage.NewRetentionScanner(conf.Storage, store, shutdownChan)
|
retentionScanner := storage.NewRetentionScanner(conf.Storage, store, shutdownChan)
|
||||||
retentionScanner.Start()
|
retentionScanner.Start()
|
||||||
|
|
||||||
// Start HTTP server.
|
// Start HTTP server.
|
||||||
webui.SetupRoutes(web.Router.PathPrefix("/serve/").Subrouter())
|
webui.SetupRoutes(web.Router.PathPrefix("/serve/").Subrouter())
|
||||||
rest.SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
rest.SetupRoutes(web.Router.PathPrefix("/api/").Subrouter())
|
||||||
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
||||||
go web.Start(rootCtx)
|
go web.Start(rootCtx)
|
||||||
|
|
||||||
// Start POP3 server.
|
// Start POP3 server.
|
||||||
pop3Server := pop3.New(conf.POP3, shutdownChan, store)
|
pop3Server := pop3.New(conf.POP3, shutdownChan, store)
|
||||||
go pop3Server.Start(rootCtx)
|
go pop3Server.Start(rootCtx)
|
||||||
|
|
||||||
// Start SMTP server.
|
// Start SMTP server.
|
||||||
smtpServer := smtp.NewServer(conf.SMTP, shutdownChan, mmanager, addrPolicy)
|
smtpServer := smtp.NewServer(conf.SMTP, shutdownChan, mmanager, addrPolicy)
|
||||||
go smtpServer.Start(rootCtx)
|
go smtpServer.Start(rootCtx)
|
||||||
|
|
||||||
// Loop forever waiting for signals or shutdown channel.
|
// Loop forever waiting for signals or shutdown channel.
|
||||||
signalLoop:
|
signalLoop:
|
||||||
for {
|
for {
|
||||||
@@ -154,6 +165,7 @@ signalLoop:
|
|||||||
break signalLoop
|
break signalLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for active connections to finish.
|
// Wait for active connections to finish.
|
||||||
go timedExit(*pidfile)
|
go timedExit(*pidfile)
|
||||||
smtpServer.Drain()
|
smtpServer.Drain()
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ func (s *Server) startSession(id int, conn net.Conn) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// not an EOF
|
// not an EOF
|
||||||
ssn.logger.Warn().Msgf("Connection error: %v", err)
|
ssn.logger.Warn().Msgf("Connection error: %v", err)
|
||||||
if netErr, ok := err.(net.Error); ok {
|
if netErr, ok := err.(net.Error); ok {
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ func (s *Session) readyHandler(cmd string, arg string) {
|
|||||||
if from == "" {
|
if from == "" {
|
||||||
from = "unspecified"
|
from = "unspecified"
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is where the client may put BODY=8BITMIME, but we already
|
// This is where the client may put BODY=8BITMIME, but we already
|
||||||
// read the DATA as bytes, so it does not effect our processing.
|
// read the DATA as bytes, so it does not effect our processing.
|
||||||
if m[2] != "" {
|
if m[2] != "" {
|
||||||
@@ -436,6 +437,7 @@ func (s *Session) dataHandler() {
|
|||||||
prefix := fmt.Sprintf("Received: from %s ([%s]) by %s\r\n for <%s>; %s\r\n",
|
prefix := fmt.Sprintf("Received: from %s ([%s]) by %s\r\n for <%s>; %s\r\n",
|
||||||
s.remoteDomain, s.remoteHost, s.config.Domain, recip.Address.Address,
|
s.remoteDomain, s.remoteHost, s.config.Domain, recip.Address.Address,
|
||||||
tstamp)
|
tstamp)
|
||||||
|
|
||||||
// Deliver message.
|
// Deliver message.
|
||||||
_, err := s.manager.Deliver(
|
_, err := s.manager.Deliver(
|
||||||
recip, s.from, s.recipients, prefix, mailData.Bytes())
|
recip, s.from, s.recipients, prefix, mailData.Bytes())
|
||||||
@@ -530,12 +532,14 @@ func (s *Session) parseCmd(line string) (cmd string, arg string, ok bool) {
|
|||||||
s.logger.Warn().Msgf("Mangled command: %q", line)
|
s.logger.Warn().Msgf("Mangled command: %q", line)
|
||||||
return "", "", false
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we made it here, command is long enough to have args
|
// If we made it here, command is long enough to have args
|
||||||
if line[4] != ' ' {
|
if line[4] != ' ' {
|
||||||
// There wasn't a space after the command?
|
// There wasn't a space after the command?
|
||||||
s.logger.Warn().Msgf("Mangled command: %q", line)
|
s.logger.Warn().Msgf("Mangled command: %q", line)
|
||||||
return "", "", false
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// I'm not sure if we should trim the args or not, but we will for now
|
// I'm not sure if we should trim the args or not, but we will for now
|
||||||
return strings.ToUpper(line[0:4]), strings.Trim(line[5:], " "), true
|
return strings.ToUpper(line[0:4]), strings.Trim(line[5:], " "), true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user