From 84cad4797dd15ba66763a32463c5580c0506a605 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 11 Dec 2016 23:35:56 -0500 Subject: [PATCH] Simple accept/listen loop for the SMTP server. --- mailpopbox.go | 4 ++++ smtp.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ smtp/conn.go | 11 +++++++++++ smtp/server.go | 6 ++++++ 4 files changed, 69 insertions(+) create mode 100644 smtp.go create mode 100644 smtp/conn.go create mode 100644 smtp/server.go diff --git a/mailpopbox.go b/mailpopbox.go index 984acb3..2765ce9 100644 --- a/mailpopbox.go +++ b/mailpopbox.go @@ -24,4 +24,8 @@ func main() { os.Exit(3) } configFile.Close() + + smtp := runSMTPServer(config) + err = <-smtp + fmt.Println(err) } diff --git a/smtp.go b/smtp.go new file mode 100644 index 0000000..b7131d5 --- /dev/null +++ b/smtp.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "net" + + "src.bluestatic.org/mailpopbox/smtp" +) + +func runSMTPServer(config Config) <-chan error { + server := smtpServer{ + config: config, + rc: make(chan error), + } + go server.run() + return server.rc +} + +type smtpServer struct { + config Config + rc chan error +} + +func (server *smtpServer) run() { + l, err := net.Listen("tcp", fmt.Sprintf(":%d", server.config.SMTPPort)) + if err != nil { + server.rc <- err + return + } + + for { + conn, err := l.Accept() + if err != nil { + server.rc <- err + return + } + + go smtp.AcceptConnection(conn, server) + } +} + +func (server *smtpServer) OnEHLO() error { + return nil +} + +func (server *smtpServer) OnMessageDelivered() error { + return nil +} diff --git a/smtp/conn.go b/smtp/conn.go new file mode 100644 index 0000000..e4734ae --- /dev/null +++ b/smtp/conn.go @@ -0,0 +1,11 @@ +package smtp + +import ( + "io" + "net" +) + +func AcceptConnection(conn net.Conn, server Server) error { + conn.Close() + return nil +} diff --git a/smtp/server.go b/smtp/server.go new file mode 100644 index 0000000..e9539e8 --- /dev/null +++ b/smtp/server.go @@ -0,0 +1,6 @@ +package smtp + +type Server interface { + OnEHLO() error + OnMessageDelivered() error +} -- 2.43.5