mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37: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:
@@ -17,7 +17,7 @@ type JSONMessageHeaderV1 struct {
|
|||||||
Mailbox string `json:"mailbox"`
|
Mailbox string `json:"mailbox"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To []string `json:"to"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Date time.Time `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
@@ -28,7 +28,7 @@ type JSONMessageV1 struct {
|
|||||||
Mailbox string `json:"mailbox"`
|
Mailbox string `json:"mailbox"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To []string `json:"to"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Date time.Time `json:"date"`
|
Date time.Time `json:"date"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
@@ -112,7 +112,7 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
|
|||||||
Mailbox: name,
|
Mailbox: name,
|
||||||
ID: msg.ID(),
|
ID: msg.ID(),
|
||||||
From: msg.From(),
|
From: msg.From(),
|
||||||
To: msg.To(),
|
To: msg.To(),
|
||||||
Subject: msg.Subject(),
|
Subject: msg.Subject(),
|
||||||
Date: msg.Date(),
|
Date: msg.Date(),
|
||||||
Size: msg.Size(),
|
Size: msg.Size(),
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func TestRestMailboxList(t *testing.T) {
|
|||||||
Mailbox: "good",
|
Mailbox: "good",
|
||||||
ID: "0001",
|
ID: "0001",
|
||||||
From: "from1",
|
From: "from1",
|
||||||
To: "to1",
|
To: []string{"to1"},
|
||||||
Subject: "subject 1",
|
Subject: "subject 1",
|
||||||
Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)),
|
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",
|
Mailbox: "good",
|
||||||
ID: "0002",
|
ID: "0002",
|
||||||
From: "from2",
|
From: "from2",
|
||||||
To: "to1",
|
To: []string{"to1"},
|
||||||
Subject: "subject 2",
|
Subject: "subject 2",
|
||||||
Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)),
|
Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ func (m *MockMessage) From() string {
|
|||||||
return args.String(0)
|
return args.String(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) To() string {
|
func (m *MockMessage) To() []string {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
return args.String(0)
|
return args.Get(0).([]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) Date() time.Time {
|
func (m *MockMessage) Date() time.Time {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
type InputMessageData struct {
|
type InputMessageData struct {
|
||||||
Mailbox, ID, From, Subject string
|
Mailbox, ID, From, Subject string
|
||||||
To string
|
To []string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Size int
|
Size int
|
||||||
Header mail.Header
|
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 {
|
if msg, ok := isJSONStringEqual(fromKey, d.From, m[fromKey]); !ok {
|
||||||
errors = append(errors, msg)
|
errors = append(errors, msg)
|
||||||
}
|
}
|
||||||
if msg, ok := isJSONStringEqual(toKey, d.To, m[toKey]); !ok {
|
for i, inputTo := range d.To {
|
||||||
errors = append(errors, msg)
|
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 {
|
if msg, ok := isJSONStringEqual(subjectKey, d.Subject, m[subjectKey]); !ok {
|
||||||
errors = append(errors, msg)
|
errors = append(errors, msg)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type Mailbox interface {
|
|||||||
type Message interface {
|
type Message interface {
|
||||||
ID() string
|
ID() string
|
||||||
From() string
|
From() string
|
||||||
To() string
|
To() []string
|
||||||
Date() time.Time
|
Date() time.Time
|
||||||
Subject() string
|
Subject() string
|
||||||
RawReader() (reader io.ReadCloser, err error)
|
RawReader() (reader io.ReadCloser, err error)
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ type FileMessage struct {
|
|||||||
Fid string
|
Fid string
|
||||||
Fdate time.Time
|
Fdate time.Time
|
||||||
Ffrom string
|
Ffrom string
|
||||||
Fto string
|
Fto []string
|
||||||
Fsubject string
|
Fsubject string
|
||||||
Fsize int64
|
Fsize int64
|
||||||
// These are for creating new messages only
|
// These are for creating new messages only
|
||||||
@@ -345,7 +345,7 @@ func (m *FileMessage) From() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// From returns the value of the Message To header
|
// From returns the value of the Message To header
|
||||||
func (m *FileMessage) To() string {
|
func (m *FileMessage) To() []string {
|
||||||
return m.Fto
|
return m.Fto
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,11 +490,24 @@ func (m *FileMessage) Close() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only public fields are stored in gob
|
// Only public fields are stored in gob, hence starting with capital F
|
||||||
m.Ffrom = body.GetHeader("From")
|
// Parse From address
|
||||||
m.Fto = body.GetHeader("To")
|
if address, err := mail.ParseAddress(body.GetHeader("From")); err == nil {
|
||||||
|
m.Ffrom = address.String()
|
||||||
|
} else {
|
||||||
|
m.Ffrom = body.GetHeader("From")
|
||||||
|
}
|
||||||
m.Fsubject = body.GetHeader("Subject")
|
m.Fsubject = body.GetHeader("Subject")
|
||||||
|
|
||||||
|
// Turn the To header into a slice
|
||||||
|
if addresses, err := body.AddressList("To"); err == nil {
|
||||||
|
for _, a := range addresses {
|
||||||
|
m.Fto = append(m.Fto, a.String())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m.Fto = []string{body.GetHeader("To")}
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh the index before adding our message
|
// Refresh the index before adding our message
|
||||||
err = m.mailbox.readIndex()
|
err = m.mailbox.readIndex()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -126,9 +126,9 @@ func (m *MockMessage) From() string {
|
|||||||
return args.String(0)
|
return args.String(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) To() string {
|
func (m *MockMessage) To() []string {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
return args.String(0)
|
return args.Get(0).([]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) Date() time.Time {
|
func (m *MockMessage) Date() time.Time {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export SWAKS_OPT_to="$to@inbucket.local"
|
|||||||
swaks $* --h-Subject: "Swaks Plain Text" --body text.txt
|
swaks $* --h-Subject: "Swaks Plain Text" --body text.txt
|
||||||
|
|
||||||
# Multi-recipient test
|
# Multi-recipient test
|
||||||
swaks $* --to="$to@inbucket.local,alternate@inbucket.local" --h-Subject: "Swaks Multi-Recipient" \
|
swaks $* --to="$to@inbucket.local,Alt User <alternate@inbucket.local>" --h-Subject: "Swaks Multi-Recipient" \
|
||||||
--body text.txt
|
--body text.txt
|
||||||
|
|
||||||
# HTML test
|
# HTML test
|
||||||
|
|||||||
@@ -53,7 +53,12 @@
|
|||||||
<dt>From:</dt>
|
<dt>From:</dt>
|
||||||
<dd>{{.message.From}}</dd>
|
<dd>{{.message.From}}</dd>
|
||||||
<dt>To:</dt>
|
<dt>To:</dt>
|
||||||
<dd>{{.message.To}}</dd>
|
<dd>
|
||||||
|
{{range $i, $addr := .message.To}}
|
||||||
|
{{- if $i}},{{end}}
|
||||||
|
{{$addr -}}
|
||||||
|
{{end}}
|
||||||
|
</dd>
|
||||||
<dt>Date:</dt>
|
<dt>Date:</dt>
|
||||||
<dd>{{.message.Date}}</dd>
|
<dd>{{.message.Date}}</dd>
|
||||||
<dt>Subject:</dt>
|
<dt>Subject:</dt>
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ $(document).ready(function() {
|
|||||||
<script type="text/html" id="list-entry-template">
|
<script type="text/html" id="list-entry-template">
|
||||||
<button data-id="id" type="button" class="message-list-entry list-group-item">
|
<button data-id="id" type="button" class="message-list-entry list-group-item">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-4 col-md-12 text-primary" data-content="subject"
|
<div class="col-sm-4 col-md-12 text-primary" data-content-text="subject"
|
||||||
data-format="subject"/>
|
data-format="subject"/>
|
||||||
<div class="col-sm-4 col-md-12 small" data-content="from"/>
|
<div class="col-sm-4 col-md-12 small" data-content-text="from"/>
|
||||||
<div class="col-sm-4 col-md-12 small" data-content="date" data-format="date"/>
|
<div class="col-sm-4 col-md-12 small" data-content="date" data-format="date"/>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
@@ -34,8 +34,8 @@ $(document).ready(function() {
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input id="message-search"
|
<input id="message-search"
|
||||||
type="search"
|
type="search"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder="search"
|
placeholder="search"
|
||||||
data-toggle="tooltip"
|
data-toggle="tooltip"
|
||||||
data-placement="top"
|
data-placement="top"
|
||||||
|
|||||||
@@ -478,9 +478,9 @@ func (m *MockMessage) From() string {
|
|||||||
return args.String(0)
|
return args.String(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) To() string {
|
func (m *MockMessage) To() []string {
|
||||||
args := m.Called()
|
args := m.Called()
|
||||||
return args.String(0)
|
return args.Get(0).([]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMessage) Date() time.Time {
|
func (m *MockMessage) Date() time.Time {
|
||||||
|
|||||||
Reference in New Issue
Block a user