1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-01-28 05:55:56 +00:00

SMTP server is running with new config engine

Web still not working
This commit is contained in:
James Hillyerd
2012-10-20 21:36:57 -07:00
parent ce9289140a
commit 81fea97a90
6 changed files with 153 additions and 56 deletions

View File

@@ -87,7 +87,7 @@ func (ss *Session) String() string {
* 5. Goto 2
*/
func (s *Server) startSession(id int, conn net.Conn) {
s.info("Connection from %v, starting session <%v>", conn.RemoteAddr(), id)
inbucket.Info("Connection from %v, starting session <%v>", conn.RemoteAddr(), id)
defer conn.Close()
ss := NewSession(s, id, conn)
@@ -476,17 +476,17 @@ func (ss *Session) ooSeq(cmd string) {
// Session specific logging methods
func (ss *Session) trace(msg string, args ...interface{}) {
ss.server.trace("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
inbucket.Trace("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
}
func (ss *Session) info(msg string, args ...interface{}) {
ss.server.info("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
inbucket.Info("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
}
func (ss *Session) warn(msg string, args ...interface{}) {
ss.server.warn("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
inbucket.Warn("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
}
func (ss *Session) error(msg string, args ...interface{}) {
ss.server.error("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
inbucket.Error("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
}

View File

@@ -3,14 +3,12 @@ package smtpd
import (
"fmt"
"github.com/jhillyerd/inbucket"
"github.com/robfig/revel"
"net"
)
// Real server code starts here
type Server struct {
domain string
port int
maxRecips int
maxIdleSeconds int
maxMessageBytes int
@@ -18,39 +16,36 @@ type Server struct {
}
// Init a new Server object
func New(domain string, port int) *Server {
func New() *Server {
ds := inbucket.NewDataStore()
return &Server{domain: domain, port: port, maxRecips: 100, maxIdleSeconds: 300,
// TODO Make more of these configurable
return &Server{domain: inbucket.GetSmtpConfig().Domain, maxRecips: 100, maxIdleSeconds: 300,
dataStore: ds, maxMessageBytes: 2048000}
}
// Loggers
func (s *Server) trace(msg string, args ...interface{}) {
rev.TRACE.Printf(msg, args...)
}
func (s *Server) info(msg string, args ...interface{}) {
rev.INFO.Printf(msg, args...)
}
func (s *Server) warn(msg string, args ...interface{}) {
rev.WARN.Printf(msg, args...)
}
func (s *Server) error(msg string, args ...interface{}) {
rev.ERROR.Printf(msg, args...)
}
// Main listener loop
func (s *Server) Start() {
s.trace("Server Start() called")
ln, err := net.Listen("tcp", fmt.Sprintf(":%v", s.port))
cfg := inbucket.GetSmtpConfig()
addr, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%v:%v",
cfg.Ip4address, cfg.Ip4port))
if err != nil {
inbucket.Error("Failed to build tcp4 address: %v", err)
// TODO More graceful early-shutdown procedure
panic(err)
}
inbucket.Info("Listening on TCP4 %v", addr)
ln, err := net.ListenTCP("tcp4", addr)
if err != nil {
inbucket.Error("Failed to start tcp4 listener: %v", err)
// TODO More graceful early-shutdown procedure
panic(err)
}
for sid := 1; ; sid++ {
if conn, err := ln.Accept(); err != nil {
// TODO Implement a max error counter before shutdown?
// or maybe attempt to restart smtpd
panic(err)
} else {
go s.startSession(sid, conn)