mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Make ident configurable
This commit is contained in:
parent
1a5fd826ec
commit
559c2a5146
2 changed files with 16 additions and 10 deletions
|
@ -21,7 +21,9 @@ type Command struct {
|
||||||
type Protocol struct {
|
type Protocol struct {
|
||||||
state State
|
state State
|
||||||
message *data.SMTPMessage
|
message *data.SMTPMessage
|
||||||
hostname string
|
|
||||||
|
Hostname string
|
||||||
|
Ident string
|
||||||
|
|
||||||
// LogHandler is called for each log message. If nil, log messages will
|
// LogHandler is called for each log message. If nil, log messages will
|
||||||
// be output using log.Printf instead.
|
// be output using log.Printf instead.
|
||||||
|
@ -48,6 +50,8 @@ func NewProtocol() *Protocol {
|
||||||
return &Protocol{
|
return &Protocol{
|
||||||
state: INVALID,
|
state: INVALID,
|
||||||
message: &data.SMTPMessage{},
|
message: &data.SMTPMessage{},
|
||||||
|
Hostname: "",
|
||||||
|
Ident: "ESMTP Go-MailHog",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,10 +68,10 @@ func (proto *Protocol) logf(message string, args ...interface{}) {
|
||||||
|
|
||||||
// Start begins an SMTP conversation with a 220 reply, placing the state
|
// Start begins an SMTP conversation with a 220 reply, placing the state
|
||||||
// machine in ESTABLISH state.
|
// machine in ESTABLISH state.
|
||||||
func (proto *Protocol) Start(hostname string) *Reply {
|
func (proto *Protocol) Start() *Reply {
|
||||||
|
proto.logf("Started session, switching to ESTABLISH state")
|
||||||
proto.state = ESTABLISH
|
proto.state = ESTABLISH
|
||||||
proto.hostname = hostname
|
return ReplyIdent(proto.Hostname + " " + proto.Ident)
|
||||||
return ReplyIdent(hostname + " ESMTP Go-MailHog")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses a line string and returns any remaining line string
|
// Parse parses a line string and returns any remaining line string
|
||||||
|
@ -90,6 +94,7 @@ func (proto *Protocol) Parse(line string) (string, *Reply) {
|
||||||
line = ""
|
line = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO collapse AUTH states into separate processing
|
||||||
if proto.state == DATA {
|
if proto.state == DATA {
|
||||||
reply = proto.ProcessData(parts[0])
|
reply = proto.ProcessData(parts[0])
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,7 +116,7 @@ func (proto *Protocol) ProcessData(line string) (reply *Reply) {
|
||||||
proto.message.Data = strings.TrimSuffix(proto.message.Data, "\r\n.\r\n")
|
proto.message.Data = strings.TrimSuffix(proto.message.Data, "\r\n.\r\n")
|
||||||
proto.state = MAIL
|
proto.state = MAIL
|
||||||
|
|
||||||
msg := proto.message.Parse(proto.hostname)
|
msg := proto.message.Parse(proto.Hostname)
|
||||||
|
|
||||||
if proto.MessageReceivedHandler == nil {
|
if proto.MessageReceivedHandler == nil {
|
||||||
return ReplyStorageFailed("No storage backend")
|
return ReplyStorageFailed("No storage backend")
|
||||||
|
|
|
@ -24,6 +24,7 @@ type Session struct {
|
||||||
// Accept starts a new SMTP session using net.TCPConn
|
// Accept starts a new SMTP session using net.TCPConn
|
||||||
func Accept(conn *net.TCPConn, conf *config.Config) {
|
func Accept(conn *net.TCPConn, conf *config.Config) {
|
||||||
proto := protocol.NewProtocol()
|
proto := protocol.NewProtocol()
|
||||||
|
proto.Hostname = conf.Hostname
|
||||||
session := &Session{conn, proto, conf, false, ""}
|
session := &Session{conn, proto, conf, false, ""}
|
||||||
proto.LogHandler = session.logf
|
proto.LogHandler = session.logf
|
||||||
proto.MessageReceivedHandler = session.acceptMessage
|
proto.MessageReceivedHandler = session.acceptMessage
|
||||||
|
@ -32,7 +33,7 @@ func Accept(conn *net.TCPConn, conf *config.Config) {
|
||||||
proto.ValidateAuthenticationHandler = session.validateAuthentication
|
proto.ValidateAuthenticationHandler = session.validateAuthentication
|
||||||
|
|
||||||
session.logf("Starting session")
|
session.logf("Starting session")
|
||||||
session.Write(proto.Start(conf.Hostname))
|
session.Write(proto.Start())
|
||||||
for session.Read() == true {
|
for session.Read() == true {
|
||||||
}
|
}
|
||||||
session.logf("Session ended")
|
session.logf("Session ended")
|
||||||
|
|
Loading…
Reference in a new issue