mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-30 17:54:03 +00:00
Fix #3
This commit is contained in:
parent
22e033df0f
commit
0193e32f1e
1 changed files with 26 additions and 13 deletions
|
@ -4,13 +4,14 @@ package smtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/config"
|
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/data"
|
|
||||||
"github.com/ian-kent/Go-MailHog/mailhog/storage"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ian-kent/Go-MailHog/mailhog/config"
|
||||||
|
"github.com/ian-kent/Go-MailHog/mailhog/data"
|
||||||
|
"github.com/ian-kent/Go-MailHog/mailhog/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
@ -137,8 +138,8 @@ func (c *Session) Process(line string) {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case command == "RSET":
|
case command == "RSET":
|
||||||
c.log("Got RSET command, switching to ESTABLISH state")
|
c.log("Got RSET command, switching to MAIL state")
|
||||||
c.state = ESTABLISH
|
c.state = MAIL
|
||||||
c.message = &data.SMTPMessage{}
|
c.message = &data.SMTPMessage{}
|
||||||
c.Write("250", "Ok")
|
c.Write("250", "Ok")
|
||||||
case command == "NOOP":
|
case command == "NOOP":
|
||||||
|
@ -154,15 +155,9 @@ func (c *Session) Process(line string) {
|
||||||
case c.state == ESTABLISH:
|
case c.state == ESTABLISH:
|
||||||
switch command {
|
switch command {
|
||||||
case "HELO":
|
case "HELO":
|
||||||
c.log("Got HELO command, switching to MAIL state")
|
c.DoHELO(args)
|
||||||
c.state = MAIL
|
|
||||||
c.message.Helo = args
|
|
||||||
c.Write("250", "Hello "+args)
|
|
||||||
case "EHLO":
|
case "EHLO":
|
||||||
c.log("Got EHLO command, switching to MAIL state")
|
c.DoEHLO(args)
|
||||||
c.state = MAIL
|
|
||||||
c.message.Helo = args
|
|
||||||
c.Write("250", "Hello "+args, "PIPELINING", "AUTH EXTERNAL CRAM-MD5 LOGIN PLAIN")
|
|
||||||
default:
|
default:
|
||||||
c.log("Got unknown command for ESTABLISH state: '%s'", command)
|
c.log("Got unknown command for ESTABLISH state: '%s'", command)
|
||||||
c.Write("500", "Unrecognised command")
|
c.Write("500", "Unrecognised command")
|
||||||
|
@ -211,6 +206,10 @@ func (c *Session) Process(line string) {
|
||||||
c.message.From = from
|
c.message.From = from
|
||||||
c.state = RCPT
|
c.state = RCPT
|
||||||
c.Write("250", "Sender "+from+" ok")
|
c.Write("250", "Sender "+from+" ok")
|
||||||
|
case "HELO":
|
||||||
|
c.DoHELO(args)
|
||||||
|
case "EHLO":
|
||||||
|
c.DoEHLO(args)
|
||||||
default:
|
default:
|
||||||
c.log("Got unknown command for MAIL state: '%s'", command)
|
c.log("Got unknown command for MAIL state: '%s'", command)
|
||||||
c.Write("500", "Unrecognised command")
|
c.Write("500", "Unrecognised command")
|
||||||
|
@ -238,6 +237,20 @@ func (c *Session) Process(line string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Session) DoHELO(args string) {
|
||||||
|
c.log("Got HELO command, switching to MAIL state")
|
||||||
|
c.state = MAIL
|
||||||
|
c.message.Helo = args
|
||||||
|
c.Write("250", "Hello "+args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Session) DoEHLO(args string) {
|
||||||
|
c.log("Got EHLO command, switching to MAIL state")
|
||||||
|
c.state = MAIL
|
||||||
|
c.message.Helo = args
|
||||||
|
c.Write("250", "Hello "+args, "PIPELINING", "AUTH EXTERNAL CRAM-MD5 LOGIN PLAIN")
|
||||||
|
}
|
||||||
|
|
||||||
func ParseMAIL(mail string) (string, error) {
|
func ParseMAIL(mail string) (string, error) {
|
||||||
r := regexp.MustCompile("(?i:From):<([^>]+)>")
|
r := regexp.MustCompile("(?i:From):<([^>]+)>")
|
||||||
match := r.FindStringSubmatch(mail)
|
match := r.FindStringSubmatch(mail)
|
||||||
|
|
Loading…
Reference in a new issue