mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Clean up
This commit is contained in:
parent
cdf5577715
commit
6db4e904be
6 changed files with 49 additions and 28 deletions
|
@ -1593,10 +1593,6 @@ type _bintree_t struct {
|
||||||
|
|
||||||
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"assets": &_bintree_t{nil, map[string]*_bintree_t{
|
"assets": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"templates": &_bintree_t{nil, map[string]*_bintree_t{
|
|
||||||
"index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}},
|
|
||||||
"layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}},
|
|
||||||
}},
|
|
||||||
"images": &_bintree_t{nil, map[string]*_bintree_t{
|
"images": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, map[string]*_bintree_t{}},
|
"ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, map[string]*_bintree_t{}},
|
||||||
"github.png": &_bintree_t{assets_images_github_png, map[string]*_bintree_t{}},
|
"github.png": &_bintree_t{assets_images_github_png, map[string]*_bintree_t{}},
|
||||||
|
@ -1606,5 +1602,9 @@ var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"controllers.js": &_bintree_t{assets_js_controllers_js, map[string]*_bintree_t{}},
|
"controllers.js": &_bintree_t{assets_js_controllers_js, map[string]*_bintree_t{}},
|
||||||
"strutil.js": &_bintree_t{assets_js_strutil_js, map[string]*_bintree_t{}},
|
"strutil.js": &_bintree_t{assets_js_strutil_js, map[string]*_bintree_t{}},
|
||||||
}},
|
}},
|
||||||
|
"templates": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}},
|
||||||
|
"layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}},
|
||||||
|
}},
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package smtp
|
package protocol
|
||||||
|
|
||||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||||
|
|
|
@ -1,13 +1,43 @@
|
||||||
package smtp
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||||
|
|
||||||
// Reply is a struct representing an SMTP reply (status code + lines)
|
// Reply is a struct representing an SMTP reply (status code + lines)
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
status int
|
Status int
|
||||||
lines []string
|
lines []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lines returns the formatted SMTP reply
|
||||||
|
func (r Reply) Lines() []string {
|
||||||
|
var lines []string
|
||||||
|
|
||||||
|
if len(r.lines) == 0 {
|
||||||
|
l := strconv.Itoa(r.Status)
|
||||||
|
lines = append(lines, l)
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, line := range r.lines {
|
||||||
|
l := ""
|
||||||
|
if i == len(r.lines)-1 {
|
||||||
|
l = strconv.Itoa(r.Status) + " " + line + "\n"
|
||||||
|
} else {
|
||||||
|
l = strconv.Itoa(r.Status) + "-" + line + "\n"
|
||||||
|
}
|
||||||
|
logText := strings.Replace(l, "\n", "\\n", -1)
|
||||||
|
logText = strings.Replace(logText, "\r", "\\r", -1)
|
||||||
|
lines = append(lines, l)
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
|
||||||
// ReplyIdent creates a 220 welcome reply
|
// ReplyIdent creates a 220 welcome reply
|
||||||
func ReplyIdent(ident string) *Reply { return &Reply{220, []string{ident}} }
|
func ReplyIdent(ident string) *Reply { return &Reply{220, []string{ident}} }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package smtp
|
package protocol
|
||||||
|
|
||||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package smtp
|
package server
|
||||||
|
|
||||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||||
|
|
||||||
|
@ -6,18 +6,18 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/config"
|
"github.com/ian-kent/Go-MailHog/mailhog/config"
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/data"
|
"github.com/ian-kent/Go-MailHog/mailhog/data"
|
||||||
|
"github.com/ian-kent/Go-MailHog/mailhog/smtp/protocol"
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/storage"
|
"github.com/ian-kent/Go-MailHog/mailhog/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Session represents a SMTP session using net.TCPConn
|
// Session represents a SMTP session using net.TCPConn
|
||||||
type Session struct {
|
type Session struct {
|
||||||
conn *net.TCPConn
|
conn *net.TCPConn
|
||||||
proto *Protocol
|
proto *protocol.Protocol
|
||||||
conf *config.Config
|
conf *config.Config
|
||||||
isTLS bool
|
isTLS bool
|
||||||
line string
|
line string
|
||||||
|
@ -25,7 +25,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 := NewProtocol()
|
proto := protocol.NewProtocol()
|
||||||
session := &Session{conn, proto, conf, false, ""}
|
session := &Session{conn, proto, conf, false, ""}
|
||||||
proto.LogHandler = session.logf
|
proto.LogHandler = session.logf
|
||||||
proto.MessageReceivedHandler = session.acceptMessageHandler
|
proto.MessageReceivedHandler = session.acceptMessageHandler
|
||||||
|
@ -84,7 +84,7 @@ func (c *Session) Read() bool {
|
||||||
|
|
||||||
if reply != nil {
|
if reply != nil {
|
||||||
c.Write(reply)
|
c.Write(reply)
|
||||||
if reply.status == 221 {
|
if reply.Status == 221 {
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,19 +93,9 @@ func (c *Session) Read() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write writes a reply to the underlying net.TCPConn
|
// Write writes a reply to the underlying net.TCPConn
|
||||||
func (c *Session) Write(reply *Reply) {
|
func (c *Session) Write(reply *protocol.Reply) {
|
||||||
if len(reply.lines) == 0 {
|
lines := reply.Lines()
|
||||||
l := strconv.Itoa(reply.status)
|
for _, l := range lines {
|
||||||
c.logf("Sent %d bytes: '%s'", len(l), l)
|
|
||||||
c.conn.Write([]byte(l))
|
|
||||||
}
|
|
||||||
for i, line := range reply.lines {
|
|
||||||
l := ""
|
|
||||||
if i == len(reply.lines)-1 {
|
|
||||||
l = strconv.Itoa(reply.status) + " " + line + "\n"
|
|
||||||
} else {
|
|
||||||
l = strconv.Itoa(reply.status) + "-" + line + "\n"
|
|
||||||
}
|
|
||||||
logText := strings.Replace(l, "\n", "\\n", -1)
|
logText := strings.Replace(l, "\n", "\\n", -1)
|
||||||
logText = strings.Replace(logText, "\r", "\\r", -1)
|
logText = strings.Replace(logText, "\r", "\\r", -1)
|
||||||
c.logf("Sent %d bytes: '%s'", len(l), logText)
|
c.logf("Sent %d bytes: '%s'", len(l), logText)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package smtp
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMAILParsing(t *testing.T) {
|
func TestMAILParsing(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue