Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-kent committed Oct 29, 2014
1 parent 22e033d commit 0193e32
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions mailhog/smtp/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package smtp

import (
"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"
"net"
"regexp"
"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 {
Expand Down Expand Up @@ -137,8 +138,8 @@ func (c *Session) Process(line string) {

switch {
case command == "RSET":
c.log("Got RSET command, switching to ESTABLISH state")
c.state = ESTABLISH
c.log("Got RSET command, switching to MAIL state")
c.state = MAIL
c.message = &data.SMTPMessage{}
c.Write("250", "Ok")
case command == "NOOP":
Expand All @@ -154,15 +155,9 @@ func (c *Session) Process(line string) {
case c.state == ESTABLISH:
switch command {
case "HELO":
c.log("Got HELO command, switching to MAIL state")
c.state = MAIL
c.message.Helo = args
c.Write("250", "Hello "+args)
c.DoHELO(args)
case "EHLO":
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")
c.DoEHLO(args)
default:
c.log("Got unknown command for ESTABLISH state: '%s'", command)
c.Write("500", "Unrecognised command")
Expand Down Expand Up @@ -211,6 +206,10 @@ func (c *Session) Process(line string) {
c.message.From = from
c.state = RCPT
c.Write("250", "Sender "+from+" ok")
case "HELO":
c.DoHELO(args)
case "EHLO":
c.DoEHLO(args)
default:
c.log("Got unknown command for MAIL state: '%s'", command)
c.Write("500", "Unrecognised command")
Expand Down Expand Up @@ -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) {
r := regexp.MustCompile("(?i:From):<([^>]+)>")
match := r.FindStringSubmatch(mail)
Expand Down

0 comments on commit 0193e32

Please sign in to comment.