1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-03-14 11:59:35 +00:00

Modify smtpd to integrate with Revel.

Add plugin to app.go to start smtpd
This commit is contained in:
James Hillyerd
2012-10-07 19:12:58 -07:00
parent cbba067673
commit 9fa93acf0e
4 changed files with 39 additions and 12 deletions

View File

@@ -56,6 +56,7 @@ type Session struct {
server *Server
id int
conn net.Conn
remoteHost string
sendError error
state State
reader *bufio.Reader
@@ -65,7 +66,8 @@ type Session struct {
func NewSession(server *Server, id int, conn net.Conn) *Session {
reader := bufio.NewReader(conn)
return &Session{server: server, id: id, conn: conn, state: GREET, reader: reader}
host, _, _ := net.SplitHostPort(conn.RemoteAddr().String())
return &Session{server: server, id: id, conn: conn, state: GREET, reader: reader, remoteHost: host}
}
func (ss *Session) String() string {
@@ -80,7 +82,7 @@ func (ss *Session) String() string {
* 5. Goto 2
*/
func (s *Server) startSession(id int, conn net.Conn) {
s.trace("Starting session <%v>", id)
s.info("Connection from %v, starting session <%v>", conn.RemoteAddr(), id)
defer conn.Close()
ss := NewSession(s, id, conn)
@@ -343,17 +345,17 @@ func (ss *Session) ooSeq(cmd string) {
// Session specific logging methods
func (ss *Session) trace(msg string, args ...interface{}) {
ss.server.trace("<%v> %v", ss.id, fmt.Sprintf(msg, args...))
ss.server.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", ss.id, fmt.Sprintf(msg, args...))
ss.server.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", ss.id, fmt.Sprintf(msg, args...))
ss.server.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", ss.id, fmt.Sprintf(msg, args...))
ss.server.error("%v<%v> %v", ss.remoteHost, ss.id, fmt.Sprintf(msg, args...))
}

View File

@@ -3,6 +3,7 @@ package smtpd
import (
"fmt"
"net"
"github.com/robfig/revel"
)
// Real server code starts here
@@ -15,24 +16,24 @@ type Server struct {
// Init a new Server object
func New(domain string, port int) *Server {
return &Server{domain: domain, port: port, maxRecips: 3, maxIdleSeconds: 10}
return &Server{domain: domain, port: port, maxRecips: 100, maxIdleSeconds: 60}
}
// Loggers
func (s *Server) trace(msg string, args ...interface{}) {
fmt.Printf("[trace] %s\n", fmt.Sprintf(msg, args...))
rev.TRACE.Printf(msg, args...)
}
func (s *Server) info(msg string, args ...interface{}) {
fmt.Printf("[info ] %s\n", fmt.Sprintf(msg, args...))
rev.INFO.Printf(msg, args...)
}
func (s *Server) warn(msg string, args ...interface{}) {
fmt.Printf("[warn ] %s\n", fmt.Sprintf(msg, args...))
rev.WARN.Printf(msg, args...)
}
func (s *Server) error(msg string, args ...interface{}) {
fmt.Printf("[error] %s\n", fmt.Sprintf(msg, args...))
rev.ERROR.Printf(msg, args...)
}
// Main listener loop