func TestReadyState(t *testing.T) {
	ds := test.NewStore()
	server, logbuf, teardown := setupSMTPServer(ds)
	defer teardown()
	script := []scriptStep{
		{"HELO localhost", 250},
		{"FOOB", 500},
		{"HELO", 503},
		{"DATA", 503},
		{"MAIL", 501},
		{"MAIL FROM john@gmail.com", 501},
		{"MAIL FROM:john@gmail.com", 501},
		{"MAIL FROM:<john@gmail.com> SIZE=147KB", 501},
		{"MAIL FROM: <john@gmail.com> SIZE147", 501},
		{"MAIL FROM:<first@last@gmail.com>", 501},
		{"MAIL FROM:<first last@gmail.com>", 501},
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	script = []scriptStep{
		{"HELO localhost", 250},
		{"MAIL FROM:<john@gmail.com>", 250},
		{"RSET", 250},
		{"MAIL FROM: <john@gmail.com>", 250},
		{"RSET", 250},
		{"MAIL FROM: <john@gmail.com> BODY=8BITMIME", 250},
		{"RSET", 250},
		{"MAIL FROM:<john@gmail.com> SIZE=1024", 250},
		{"RSET", 250},
		{"MAIL FROM:<host!host!user/data@foo.com>", 250},
		{"RSET", 250},
		{"MAIL FROM:<\"first last\"@space.com>", 250},
		{"RSET", 250},
		{"MAIL FROM:<user\\@internal@external.com>", 250},
		{"RSET", 250},
		{"MAIL FROM:<user\\>name@host.com>", 250},
		{"RSET", 250},
		{"MAIL FROM:<\"user>name\"@host.com>", 250},
		{"RSET", 250},
		{"MAIL FROM:<\"user@internal\"@external.com>", 250},
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	script = []scriptStep{
		{"HELO localhost", 250},
		{"STARTTLS", 454},  
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	if t.Failed() {
		time.Sleep(2 * time.Second)
		_, _ = io.Copy(os.Stderr, logbuf)
	}
}
Test commands in READY state
package smtp
import (
	"bytes"
	"fmt"
	"io"
	"log"
	"net"
	"net/textproto"
	"os"
	"testing"
	"time"
	"github.com/inbucket/inbucket/pkg/config"
	"github.com/inbucket/inbucket/pkg/message"
	"github.com/inbucket/inbucket/pkg/policy"
	"github.com/inbucket/inbucket/pkg/storage"
	"github.com/inbucket/inbucket/pkg/test"
)
type scriptStep struct {
	send   string
	expect int
}
func TestGreetState(t *testing.T) {
	ds := test.NewStore()
	server, logbuf, teardown := setupSMTPServer(ds)
	defer teardown()
	script := []scriptStep{
		{"HELO", 501},
		{"EHLO", 501},
		{"HELLO", 500},
		{"HELL", 500},
		{"hello", 500},
		{"Outlook", 500},
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"HELO mydomain", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"HELO mydom.com", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"HelO mydom.com", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"helo 127.0.0.1", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"HELO ABC", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"EHLO mydomain", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"EHLO mydom.com", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"EhlO mydom.com", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"ehlo 127.0.0.1", 250}}); err != nil {
		t.Error(err)
	}
	if err := playSession(t, server, []scriptStep{{"EHLO a", 250}}); err != nil {
		t.Error(err)
	}
	if t.Failed() {
		time.Sleep(2 * time.Second)
		_, _ = io.Copy(os.Stderr, logbuf)
	}
}
func TestEmptyEnvelope(t *testing.T) {
	ds := test.NewStore()
	server, logbuf, teardown := setupSMTPServer(ds)
	defer teardown()
	script := []scriptStep{
		{"HELO localhost", 250},
		{"MAIL FROM:<>", 250},
	}
	if err := playSession(t, server, script); err != nil {
		_, _ = io.Copy(os.Stderr, logbuf)
		t.Error(err)
	}
	script = []scriptStep{
		{"HELO localhost", 250},
		{"MAIL FROM: <>", 250},
	}
	if err := playSession(t, server, script); err != nil {
		_, _ = io.Copy(os.Stderr, logbuf)
		t.Error(err)
	}
}
func TestAuth(t *testing.T) {
	ds := test.NewStore()
	server, logbuf, teardown := setupSMTPServer(ds)
	defer teardown()
	script := []scriptStep{
		{"EHLO localhost", 250},
		{"AUTH PLAIN aW5idWNrZXQ6cGFzc3dvcmQK", 235},
		{"RSET", 250},
		{"AUTH GSSAPI aW5idWNrZXQ6cGFzc3dvcmQK", 500},
		{"RSET", 250},
		{"AUTH PLAIN", 500},
		{"RSET", 250},
		{"AUTH PLAIN aW5idWNrZXQ6cG Fzc3dvcmQK", 500},
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	script = []scriptStep{
		{"EHLO localhost", 250},
		{"AUTH LOGIN", 334},  
		{"username", 334},
		{"password", 235},
		{"RSET", 250},
		{"AUTH LOGIN", 334},  
		{"", 334},
		{"", 235},
	}
	if err := playSession(t, server, script); err != nil {
		t.Error(err)
	}
	if t.Failed() {
		time.Sleep(2 * time.Second)
		_, _ = io.Copy(os.Stderr, logbuf)
	}
}