mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-21 19:47:03 +00:00
event: Use pointers for InboundMessage addresses (#447)
* event: Use pointers for InboundMessage addresses To ease conversions to/from MessageMetadata Signed-off-by: James Hillyerd <james@hillyerd.com> * message: test StoreManager.MailboxForAddress() Signed-off-by: James Hillyerd <james@hillyerd.com> --------- Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -14,8 +14,8 @@ type AddressParts struct {
|
||||
// InboundMessage contains the basic header and mailbox data for a message being received.
|
||||
type InboundMessage struct {
|
||||
Mailboxes []string
|
||||
From mail.Address
|
||||
To []mail.Address
|
||||
From *mail.Address
|
||||
To []*mail.Address
|
||||
Subject string
|
||||
Size int64
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ func inboundMessageIndex(ls *lua.LState) int {
|
||||
}
|
||||
ls.Push(lt)
|
||||
case "from":
|
||||
ls.Push(wrapMailAddress(ls, &m.From))
|
||||
ls.Push(wrapMailAddress(ls, m.From))
|
||||
case "to":
|
||||
lt := &lua.LTable{}
|
||||
for _, v := range m.To {
|
||||
addr := v
|
||||
lt.Append(wrapMailAddress(ls, &addr))
|
||||
lt.Append(wrapMailAddress(ls, addr))
|
||||
}
|
||||
ls.Push(lt)
|
||||
case "subject":
|
||||
@@ -110,15 +110,15 @@ func inboundMessageNewIndex(ls *lua.LState) int {
|
||||
})
|
||||
m.Mailboxes = mailboxes
|
||||
case "from":
|
||||
m.From = *checkMailAddress(ls, 3)
|
||||
m.From = checkMailAddress(ls, 3)
|
||||
case "to":
|
||||
lt := ls.CheckTable(3)
|
||||
to := make([]mail.Address, 0, 16)
|
||||
to := make([]*mail.Address, 0, 16)
|
||||
lt.ForEach(func(k, lv lua.LValue) {
|
||||
if ud, ok := lv.(*lua.LUserData); ok {
|
||||
// TODO should fail if wrong type + test.
|
||||
if entry, ok := unwrapMailAddress(ud); ok {
|
||||
to = append(to, *entry)
|
||||
to = append(to, entry)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -31,8 +31,8 @@ const LuaInit = `
|
||||
func TestInboundMessageGetters(t *testing.T) {
|
||||
want := &event.InboundMessage{
|
||||
Mailboxes: []string{"mb1", "mb2"},
|
||||
From: mail.Address{Name: "name1", Address: "addr1"},
|
||||
To: []mail.Address{
|
||||
From: &mail.Address{Name: "name1", Address: "addr1"},
|
||||
To: []*mail.Address{
|
||||
{Name: "name2", Address: "addr2"},
|
||||
{Name: "name3", Address: "addr3"},
|
||||
},
|
||||
@@ -66,8 +66,8 @@ func TestInboundMessageGetters(t *testing.T) {
|
||||
func TestInboundMessageSetters(t *testing.T) {
|
||||
want := &event.InboundMessage{
|
||||
Mailboxes: []string{"mb1", "mb2"},
|
||||
From: mail.Address{Name: "name1", Address: "addr1"},
|
||||
To: []mail.Address{
|
||||
From: &mail.Address{Name: "name1", Address: "addr1"},
|
||||
To: []*mail.Address{
|
||||
{Name: "name2", Address: "addr2"},
|
||||
{Name: "name3", Address: "addr3"},
|
||||
},
|
||||
|
||||
@@ -179,8 +179,8 @@ func TestBeforeMessageStored(t *testing.T) {
|
||||
// Event to send.
|
||||
msg := event.InboundMessage{
|
||||
Mailboxes: []string{"one", "two"},
|
||||
From: mail.Address{Name: "From Name", Address: "from@example.com"},
|
||||
To: []mail.Address{
|
||||
From: &mail.Address{Name: "From Name", Address: "from@example.com"},
|
||||
To: []*mail.Address{
|
||||
{Name: "To1 Name", Address: "to1@example.com"},
|
||||
{Name: "To2 Name", Address: "to2@example.com"},
|
||||
},
|
||||
@@ -233,8 +233,8 @@ func TestBeforeMessageStored(t *testing.T) {
|
||||
// Verify response values.
|
||||
want := &event.InboundMessage{
|
||||
Mailboxes: []string{"resone", "restwo"},
|
||||
From: mail.Address{Name: "Res From", Address: "res@example.com"},
|
||||
To: []mail.Address{
|
||||
From: &mail.Address{Name: "Res From", Address: "res@example.com"},
|
||||
To: []*mail.Address{
|
||||
{Name: "To1 Res", Address: "res1@example.com"},
|
||||
{Name: "To2 Res", Address: "res2@example.com"},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user