1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

Switch to storing To addresses as a slice

- Changes on-disk storage format
- Changes JSON API
- To and From values are now parsed/formatted by Go's mail.ParseAddress
  function
- Fixed bug in list-entry-template, was not escaping HTML characters
- Updated tests
This commit is contained in:
James Hillyerd
2016-09-21 22:12:20 -07:00
parent 01ea89e7e2
commit 017a097588
11 changed files with 46 additions and 26 deletions

View File

@@ -17,7 +17,7 @@ type JSONMessageHeaderV1 struct {
Mailbox string `json:"mailbox"`
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
To []string `json:"to"`
Subject string `json:"subject"`
Date time.Time `json:"date"`
Size int64 `json:"size"`
@@ -28,7 +28,7 @@ type JSONMessageV1 struct {
Mailbox string `json:"mailbox"`
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
To []string `json:"to"`
Subject string `json:"subject"`
Date time.Time `json:"date"`
Size int64 `json:"size"`
@@ -112,7 +112,7 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
Mailbox: name,
ID: msg.ID(),
From: msg.From(),
To: msg.To(),
To: msg.To(),
Subject: msg.Subject(),
Date: msg.Date(),
Size: msg.Size(),

View File

@@ -95,7 +95,7 @@ func TestRestMailboxList(t *testing.T) {
Mailbox: "good",
ID: "0001",
From: "from1",
To: "to1",
To: []string{"to1"},
Subject: "subject 1",
Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)),
}
@@ -103,7 +103,7 @@ func TestRestMailboxList(t *testing.T) {
Mailbox: "good",
ID: "0002",
From: "from2",
To: "to1",
To: []string{"to1"},
Subject: "subject 2",
Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)),
}

View File

@@ -70,9 +70,9 @@ func (m *MockMessage) From() string {
return args.String(0)
}
func (m *MockMessage) To() string {
func (m *MockMessage) To() []string {
args := m.Called()
return args.String(0)
return args.Get(0).([]string)
}
func (m *MockMessage) Date() time.Time {

View File

@@ -17,7 +17,7 @@ import (
type InputMessageData struct {
Mailbox, ID, From, Subject string
To string
To []string
Date time.Time
Size int
Header mail.Header
@@ -81,8 +81,10 @@ func (d *InputMessageData) CompareToJSONHeaderMap(json interface{}) (errors []st
if msg, ok := isJSONStringEqual(fromKey, d.From, m[fromKey]); !ok {
errors = append(errors, msg)
}
if msg, ok := isJSONStringEqual(toKey, d.To, m[toKey]); !ok {
errors = append(errors, msg)
for i, inputTo := range d.To {
if msg, ok := isJSONStringEqual(toKey, inputTo, m[toKey].([]interface{})[i]); !ok {
errors = append(errors, msg)
}
}
if msg, ok := isJSONStringEqual(subjectKey, d.Subject, m[subjectKey]); !ok {
errors = append(errors, msg)