mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +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:
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"net/mail"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -408,13 +409,14 @@ func (ss *Session) deliverMessage(recip *policy.Recipient, content []byte) (ok b
|
|||||||
}
|
}
|
||||||
from, err := env.AddressList("From")
|
from, err := env.AddressList("From")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ss.logError("Failed to get From address: %v", err)
|
from = []*mail.Address{{Address: ss.from}}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
to, err := env.AddressList("To")
|
to, err := env.AddressList("To")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ss.logError("Failed to get To addresses: %v", err)
|
to = make([]*mail.Address, len(ss.recipients))
|
||||||
return false
|
for i, torecip := range ss.recipients {
|
||||||
|
to[i] = &torecip.Address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Generate Received header.
|
// Generate Received header.
|
||||||
stamp := time.Now().Format(timeStampFormat)
|
stamp := time.Now().Format(timeStampFormat)
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func TestMailState(t *testing.T) {
|
|||||||
{"MAIL FROM:<john@gmail.com>", 250},
|
{"MAIL FROM:<john@gmail.com>", 250},
|
||||||
{"RCPT TO:<u1@gmail.com>", 250},
|
{"RCPT TO:<u1@gmail.com>", 250},
|
||||||
{"DATA", 354},
|
{"DATA", 354},
|
||||||
{".", 451},
|
{".", 250},
|
||||||
}
|
}
|
||||||
if err := playSession(t, server, script); err != nil {
|
if err := playSession(t, server, script); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -247,7 +247,6 @@ func TestDataState(t *testing.T) {
|
|||||||
pipe := setupSMTPSession(server)
|
pipe := setupSMTPSession(server)
|
||||||
c := textproto.NewConn(pipe)
|
c := textproto.NewConn(pipe)
|
||||||
|
|
||||||
// Get us into DATA state
|
|
||||||
if code, _, err := c.ReadCodeLine(220); err != nil {
|
if code, _, err := c.ReadCodeLine(220); err != nil {
|
||||||
t.Errorf("Expected a 220 greeting, got %v", code)
|
t.Errorf("Expected a 220 greeting, got %v", code)
|
||||||
}
|
}
|
||||||
@@ -274,6 +273,33 @@ Hi!
|
|||||||
t.Errorf("Expected a 250 greeting, got %v", code)
|
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() {
|
if t.Failed() {
|
||||||
// Wait for handler to finish logging
|
// Wait for handler to finish logging
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|||||||
Reference in New Issue
Block a user