r,_:=regexp.Compile("250 Ok: queued as ([0-9a-f]+)\n")
match:=r.FindStringSubmatch(string(buf[0:n]))
assert.NotNil(t,match)
// Send QUIT
_,err=conn.Write([]byte("QUIT\r\n"))
assert.Nil(t,err)
// Read the response
n,err=conn.Read(buf)
assert.Nil(t,err)
assert.Equal(t,string(buf[0:n]),"221 Bye\n")
s:=storage.CreateMongoDB(mailhog.DefaultConfig())
message,err:=s.Load(match[1])
assert.Nil(t,err)
assert.NotNil(t,message)
assert.Equal(t,message.From.Domain,"mailhog.example","sender domain is mailhog.example")
assert.Equal(t,message.From.Mailbox,"nobody","sender mailbox is nobody")
assert.Equal(t,message.From.Params,"","sender params is empty")
assert.Equal(t,len(message.From.Relays),0,"sender has no relays")
assert.Equal(t,len(message.To),1,"message has 1 recipient")
assert.Equal(t,message.To[0].Domain,"mailhog.example","recipient domain is mailhog.example")
assert.Equal(t,message.To[0].Mailbox,"someone","recipient mailbox is someone")
assert.Equal(t,message.To[0].Params,"","recipient params is empty")
assert.Equal(t,len(message.To[0].Relays),0,"recipient has no relays")
assert.Equal(t,len(message.Content.Headers),9,"message has 7 headers")
assert.Equal(t,message.Content.Headers["Content-Type"],[]string{"multipart/alternative; boundary=\"--mailhog-test-boundary\""},"Content-Type header is multipart/alternative; boundary=\"--mailhog-test-boundary\"")
assert.Equal(t,message.Content.Headers["Subject"],[]string{"Example message"},"Subject header is Example message")
assert.Equal(t,message.Content.Headers["Content-Length"],[]string{"220"},"Content-Length is 220")
assert.Equal(t,message.Content.Headers["To"],[]string{"Someone <someone@mailhog.example>"},"To is Someone <someone@mailhog.example>")
assert.Equal(t,message.Content.Headers["From"],[]string{"Nobody <nobody@mailhog.example>"},"From is Nobody <nobody@mailhog.example>")
assert.True(t,strings.HasPrefix(message.Content.Headers["Received"][0],"from localhost by mailhog.example (Go-MailHog)\r\n id "+match[1]+"@mailhog.example; "),"Received header is correct")
assert.Equal(t,message.Content.Headers["Return-Path"],[]string{"<nobody@mailhog.example>"},"Return-Path is <nobody@mailhog.example>")
assert.Equal(t,message.Content.Headers["Message-ID"],[]string{match[1]+"@mailhog.example"},"Message-ID is "+match[1]+"@mailhog.example")