1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

smtp: Don't require MIME headers for metadata

This was a regression, will again fall back to MAIL FROM/RCPT TO data.
This commit is contained in:
James Hillyerd
2018-03-17 14:41:03 -07:00
parent e84b1f8952
commit dc4db59211
2 changed files with 34 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net"
"net/mail"
"regexp"
"strconv"
"strings"
@@ -408,13 +409,14 @@ func (ss *Session) deliverMessage(recip *policy.Recipient, content []byte) (ok b
}
from, err := env.AddressList("From")
if err != nil {
ss.logError("Failed to get From address: %v", err)
return false
from = []*mail.Address{{Address: ss.from}}
}
to, err := env.AddressList("To")
if err != nil {
ss.logError("Failed to get To addresses: %v", err)
return false
to = make([]*mail.Address, len(ss.recipients))
for i, torecip := range ss.recipients {
to[i] = &torecip.Address
}
}
// Generate Received header.
stamp := time.Now().Format(timeStampFormat)

View File

@@ -200,7 +200,7 @@ func TestMailState(t *testing.T) {
{"MAIL FROM:<john@gmail.com>", 250},
{"RCPT TO:<u1@gmail.com>", 250},
{"DATA", 354},
{".", 451},
{".", 250},
}
if err := playSession(t, server, script); err != nil {
t.Error(err)
@@ -247,7 +247,6 @@ func TestDataState(t *testing.T) {
pipe := setupSMTPSession(server)
c := textproto.NewConn(pipe)
// Get us into DATA state
if code, _, err := c.ReadCodeLine(220); err != nil {
t.Errorf("Expected a 220 greeting, got %v", code)
}
@@ -274,6 +273,33 @@ Hi!
t.Errorf("Expected a 250 greeting, got %v", code)
}
// Test with no useful headers.
pipe = setupSMTPSession(server)
c = textproto.NewConn(pipe)
if code, _, err := c.ReadCodeLine(220); err != nil {
t.Errorf("Expected a 220 greeting, got %v", code)
}
script = []scriptStep{
{"HELO localhost", 250},
{"MAIL FROM:<john@gmail.com>", 250},
{"RCPT TO:<u1@gmail.com>", 250},
{"DATA", 354},
}
if err := playScriptAgainst(t, c, script); err != nil {
t.Error(err)
}
// Send a message
body = `X-Useless-Header: true
Hi! Can you still deliver this?
`
dw = c.DotWriter()
_, _ = io.WriteString(dw, body)
_ = dw.Close()
if code, _, err := c.ReadCodeLine(250); err != nil {
t.Errorf("Expected a 250 greeting, got %v", code)
}
if t.Failed() {
// Wait for handler to finish logging
time.Sleep(2 * time.Second)