mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-12-17 18:07:16 +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{
|
||||
"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{
|
||||
"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{}},
|
||||
|
@ -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{}},
|
||||
"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
|
||||
|
|
@ -1,13 +1,43 @@
|
|||
package smtp
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||
|
||||
// Reply is a struct representing an SMTP reply (status code + lines)
|
||||
type Reply struct {
|
||||
status int
|
||||
Status int
|
||||
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
|
||||
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
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package smtp
|
||||
package server
|
||||
|
||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||
|
||||
|
@ -6,18 +6,18 @@ import (
|
|||
"errors"
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ian-kent/Go-MailHog/mailhog/config"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Session represents a SMTP session using net.TCPConn
|
||||
type Session struct {
|
||||
conn *net.TCPConn
|
||||
proto *Protocol
|
||||
proto *protocol.Protocol
|
||||
conf *config.Config
|
||||
isTLS bool
|
||||
line string
|
||||
|
@ -25,7 +25,7 @@ type Session struct {
|
|||
|
||||
// Accept starts a new SMTP session using net.TCPConn
|
||||
func Accept(conn *net.TCPConn, conf *config.Config) {
|
||||
proto := NewProtocol()
|
||||
proto := protocol.NewProtocol()
|
||||
session := &Session{conn, proto, conf, false, ""}
|
||||
proto.LogHandler = session.logf
|
||||
proto.MessageReceivedHandler = session.acceptMessageHandler
|
||||
|
@ -84,7 +84,7 @@ func (c *Session) Read() bool {
|
|||
|
||||
if reply != nil {
|
||||
c.Write(reply)
|
||||
if reply.status == 221 {
|
||||
if reply.Status == 221 {
|
||||
c.conn.Close()
|
||||
}
|
||||
}
|
||||
|
@ -93,19 +93,9 @@ func (c *Session) Read() bool {
|
|||
}
|
||||
|
||||
// Write writes a reply to the underlying net.TCPConn
|
||||
func (c *Session) Write(reply *Reply) {
|
||||
if len(reply.lines) == 0 {
|
||||
l := strconv.Itoa(reply.status)
|
||||
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"
|
||||
}
|
||||
func (c *Session) Write(reply *protocol.Reply) {
|
||||
lines := reply.Lines()
|
||||
for _, l := range lines {
|
||||
logText := strings.Replace(l, "\n", "\\n", -1)
|
||||
logText = strings.Replace(logText, "\r", "\\r", -1)
|
||||
c.logf("Sent %d bytes: '%s'", len(l), logText)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package smtp
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMAILParsing(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue