From 124f830478d7861d6ba36eeb4d04aabf93b92a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wojtun=CC=81?= Date: Thu, 1 Sep 2016 15:01:34 +0200 Subject: [PATCH 1/6] Added "To:" header --- rest/apiv1_controller.go | 4 ++++ smtpd/datastore.go | 1 + smtpd/filestore.go | 9 +++++++++ themes/bootstrap/templates/mailbox/_show.html | 2 ++ themes/integral/templates/mailbox/_show.html | 4 ++++ webui/mailbox_controller.go | 3 +++ 6 files changed, 23 insertions(+) diff --git a/rest/apiv1_controller.go b/rest/apiv1_controller.go index 365b838..452600a 100644 --- a/rest/apiv1_controller.go +++ b/rest/apiv1_controller.go @@ -17,6 +17,7 @@ type JSONMessageHeaderV1 struct { Mailbox string `json:"mailbox"` ID string `json:"id"` From string `json:"from"` + To string `json:"to"` Subject string `json:"subject"` Date time.Time `json:"date"` Size int64 `json:"size"` @@ -27,6 +28,7 @@ type JSONMessageV1 struct { Mailbox string `json:"mailbox"` ID string `json:"id"` From string `json:"from"` + To string `json:"to"` Subject string `json:"subject"` Date time.Time `json:"date"` Size int64 `json:"size"` @@ -65,6 +67,7 @@ func MailboxListV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) Mailbox: name, ID: msg.ID(), From: msg.From(), + To: msg.To(), Subject: msg.Subject(), Date: msg.Date(), Size: msg.Size(), @@ -109,6 +112,7 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) Mailbox: name, ID: msg.ID(), From: msg.From(), + To: msg.To(), Subject: msg.Subject(), Date: msg.Date(), Size: msg.Size(), diff --git a/smtpd/datastore.go b/smtpd/datastore.go index ea1256d..a483852 100644 --- a/smtpd/datastore.go +++ b/smtpd/datastore.go @@ -36,6 +36,7 @@ type Mailbox interface { type Message interface { ID() string From() string + To() string Date() time.Time Subject() string RawReader() (reader io.ReadCloser, err error) diff --git a/smtpd/filestore.go b/smtpd/filestore.go index dc46141..a17c5e1 100644 --- a/smtpd/filestore.go +++ b/smtpd/filestore.go @@ -295,6 +295,7 @@ type FileMessage struct { Fid string Fdate time.Time Ffrom string + Fto string Fsubject string Fsize int64 // These are for creating new messages only @@ -343,6 +344,13 @@ func (m *FileMessage) From() string { return m.Ffrom } + +// From returns the value of the Message From header +func (m *FileMessage) To() string { + return m.Fto +} + + // Subject returns the value of the Message Subject header func (m *FileMessage) Subject() string { return m.Fsubject @@ -486,6 +494,7 @@ func (m *FileMessage) Close() error { // Only public fields are stored in gob m.Ffrom = body.GetHeader("From") + m.Fto = body.GetHeader("To") m.Fsubject = body.GetHeader("Subject") // Refresh the index before adding our message diff --git a/themes/bootstrap/templates/mailbox/_show.html b/themes/bootstrap/templates/mailbox/_show.html index 3825e5c..ada6fd8 100644 --- a/themes/bootstrap/templates/mailbox/_show.html +++ b/themes/bootstrap/templates/mailbox/_show.html @@ -52,6 +52,8 @@
From:
{{.message.From}}
+
To:
+
{{.message.To}}
Date:
{{.message.Date}}
Subject:
diff --git a/themes/integral/templates/mailbox/_show.html b/themes/integral/templates/mailbox/_show.html index 6dbaf3d..e5313db 100644 --- a/themes/integral/templates/mailbox/_show.html +++ b/themes/integral/templates/mailbox/_show.html @@ -13,6 +13,10 @@ From: {{.message.From}} + + To: + {{.message.To}} + Date: {{.message.Date}} diff --git a/webui/mailbox_controller.go b/webui/mailbox_controller.go index 523a5c6..6166260 100644 --- a/webui/mailbox_controller.go +++ b/webui/mailbox_controller.go @@ -19,6 +19,7 @@ type JSONMessageHeader struct { Mailbox string ID string `json:"Id"` From string + To string Subject string Date time.Time Size int64 @@ -29,6 +30,7 @@ type JSONMessage struct { Mailbox string ID string `json:"Id"` From string + To string Subject string Date time.Time Size int64 @@ -113,6 +115,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( Mailbox: name, ID: msg.ID(), From: msg.From(), + To: msg.To(), Subject: msg.Subject(), Date: msg.Date(), Size: msg.Size(), From 02eee0a60813a0616204e9b70f300370ffff19ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wojtun=CC=81?= Date: Thu, 1 Sep 2016 17:25:24 +0200 Subject: [PATCH 2/6] corrected tests --- rest/apiv1_controller.go | 2 +- rest/apiv1_controller_test.go | 3 +++ rest/testmocks_test.go | 5 +++++ rest/testutils_test.go | 5 +++++ smtpd/retention_test.go | 5 +++++ webui/rest_test.go | 20 ++++++++++++++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/rest/apiv1_controller.go b/rest/apiv1_controller.go index 452600a..4e1e125 100644 --- a/rest/apiv1_controller.go +++ b/rest/apiv1_controller.go @@ -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(), diff --git a/rest/apiv1_controller_test.go b/rest/apiv1_controller_test.go index 74aaa4e..d7117ea 100644 --- a/rest/apiv1_controller_test.go +++ b/rest/apiv1_controller_test.go @@ -19,6 +19,7 @@ const ( mailboxKey = "mailbox" idKey = "id" fromKey = "from" + toKey = "to" subjectKey = "subject" dateKey = "date" sizeKey = "size" @@ -94,6 +95,7 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0001", From: "from1", + To: "to1", Subject: "subject 1", Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)), } @@ -101,6 +103,7 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0002", From: "from2", + To: "to1", Subject: "subject 2", Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)), } diff --git a/rest/testmocks_test.go b/rest/testmocks_test.go index 0c5c610..a4ce88d 100644 --- a/rest/testmocks_test.go +++ b/rest/testmocks_test.go @@ -70,6 +70,11 @@ func (m *MockMessage) From() string { return args.String(0) } +func (m *MockMessage) To() string { + args := m.Called() + return args.String(0) +} + func (m *MockMessage) Date() time.Time { args := m.Called() return args.Get(0).(time.Time) diff --git a/rest/testutils_test.go b/rest/testutils_test.go index d63e1ce..b4bd701 100644 --- a/rest/testutils_test.go +++ b/rest/testutils_test.go @@ -17,6 +17,7 @@ import ( type InputMessageData struct { Mailbox, ID, From, Subject string + To string Date time.Time Size int Header mail.Header @@ -27,6 +28,7 @@ func (d *InputMessageData) MockMessage() *MockMessage { msg := &MockMessage{} msg.On("ID").Return(d.ID) msg.On("From").Return(d.From) + msg.On("To").Return(d.To) msg.On("Subject").Return(d.Subject) msg.On("Date").Return(d.Date) msg.On("Size").Return(d.Size) @@ -79,6 +81,9 @@ 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) + } if msg, ok := isJSONStringEqual(subjectKey, d.Subject, m[subjectKey]); !ok { errors = append(errors, msg) } diff --git a/smtpd/retention_test.go b/smtpd/retention_test.go index 4c32780..b7eeb16 100644 --- a/smtpd/retention_test.go +++ b/smtpd/retention_test.go @@ -126,6 +126,11 @@ func (m *MockMessage) From() string { return args.String(0) } +func (m *MockMessage) To() string { + args := m.Called() + return args.String(0) +} + func (m *MockMessage) Date() time.Time { args := m.Called() return args.Get(0).(time.Time) diff --git a/webui/rest_test.go b/webui/rest_test.go index 04301b0..d35e097 100644 --- a/webui/rest_test.go +++ b/webui/rest_test.go @@ -25,6 +25,7 @@ type OutputJSONHeader struct { Mailbox string ID string `json:"Id"` From, Subject, Date string + To string Size int } @@ -33,6 +34,7 @@ type OutputJSONMessage struct { Mailbox string ID string `json:"Id"` From, Subject, Date string + To string Size int Header map[string][]string Body struct { @@ -46,6 +48,7 @@ type InputMessageData struct { Mailbox string ID string `json:"Id"` From, Subject string + To string Date time.Time Size int Header mail.Header @@ -57,6 +60,7 @@ func (d *InputMessageData) MockMessage() *MockMessage { msg := &MockMessage{} msg.On("ID").Return(d.ID) msg.On("From").Return(d.From) + msg.On("To").Return(d.To) msg.On("Subject").Return(d.Subject) msg.On("Date").Return(d.Date) msg.On("Size").Return(d.Size) @@ -85,6 +89,10 @@ func (d *InputMessageData) CompareToJSONHeader(j *OutputJSONHeader) (errors []st errors = append(errors, fmt.Sprintf("Expected JSON.From=%q, got %q", d.From, j.From)) } + if d.To != j.To { + errors = append(errors, fmt.Sprintf("Expected JSON.To=%q, got %q", d.To, + j.To)) + } if d.Subject != j.Subject { errors = append(errors, fmt.Sprintf("Expected JSON.Subject=%q, got %q", d.Subject, j.Subject)) @@ -115,6 +123,10 @@ func (d *InputMessageData) CompareToJSONMessage(j *OutputJSONMessage) (errors [] errors = append(errors, fmt.Sprintf("Expected JSON.From=%q, got %q", d.From, j.From)) } + if d.To != j.To { + errors = append(errors, fmt.Sprintf("Expected JSON.To=%q, got %q", d.To, + j.To)) + } if d.Subject != j.Subject { errors = append(errors, fmt.Sprintf("Expected JSON.Subject=%q, got %q", d.Subject, j.Subject)) @@ -225,6 +237,7 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0001", From: "from1", + To: "to1", Subject: "subject 1", Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)), } @@ -232,6 +245,7 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0002", From: "from2", + To: "to2", Subject: "subject 2", Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)), } @@ -345,6 +359,7 @@ func TestRestMessage(t *testing.T) { Mailbox: "good", ID: "0001", From: "from1", + To: "to1", Subject: "subject 1", Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)), Header: mail.Header{ @@ -478,6 +493,11 @@ func (m *MockMessage) From() string { return args.String(0) } +func (m *MockMessage) To() string { + args := m.Called() + return args.String(0) +} + func (m *MockMessage) Date() time.Time { args := m.Called() return args.Get(0).(time.Time) From 8d36aa9750334e825904383e786025d89af14167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wojtun=CC=81?= Date: Tue, 13 Sep 2016 07:43:33 +0200 Subject: [PATCH 3/6] revert webui stuff --- webui/mailbox_controller.go | 3 --- webui/rest_test.go | 20 -------------------- 2 files changed, 23 deletions(-) diff --git a/webui/mailbox_controller.go b/webui/mailbox_controller.go index 6166260..523a5c6 100644 --- a/webui/mailbox_controller.go +++ b/webui/mailbox_controller.go @@ -19,7 +19,6 @@ type JSONMessageHeader struct { Mailbox string ID string `json:"Id"` From string - To string Subject string Date time.Time Size int64 @@ -30,7 +29,6 @@ type JSONMessage struct { Mailbox string ID string `json:"Id"` From string - To string Subject string Date time.Time Size int64 @@ -115,7 +113,6 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( Mailbox: name, ID: msg.ID(), From: msg.From(), - To: msg.To(), Subject: msg.Subject(), Date: msg.Date(), Size: msg.Size(), diff --git a/webui/rest_test.go b/webui/rest_test.go index d35e097..04301b0 100644 --- a/webui/rest_test.go +++ b/webui/rest_test.go @@ -25,7 +25,6 @@ type OutputJSONHeader struct { Mailbox string ID string `json:"Id"` From, Subject, Date string - To string Size int } @@ -34,7 +33,6 @@ type OutputJSONMessage struct { Mailbox string ID string `json:"Id"` From, Subject, Date string - To string Size int Header map[string][]string Body struct { @@ -48,7 +46,6 @@ type InputMessageData struct { Mailbox string ID string `json:"Id"` From, Subject string - To string Date time.Time Size int Header mail.Header @@ -60,7 +57,6 @@ func (d *InputMessageData) MockMessage() *MockMessage { msg := &MockMessage{} msg.On("ID").Return(d.ID) msg.On("From").Return(d.From) - msg.On("To").Return(d.To) msg.On("Subject").Return(d.Subject) msg.On("Date").Return(d.Date) msg.On("Size").Return(d.Size) @@ -89,10 +85,6 @@ func (d *InputMessageData) CompareToJSONHeader(j *OutputJSONHeader) (errors []st errors = append(errors, fmt.Sprintf("Expected JSON.From=%q, got %q", d.From, j.From)) } - if d.To != j.To { - errors = append(errors, fmt.Sprintf("Expected JSON.To=%q, got %q", d.To, - j.To)) - } if d.Subject != j.Subject { errors = append(errors, fmt.Sprintf("Expected JSON.Subject=%q, got %q", d.Subject, j.Subject)) @@ -123,10 +115,6 @@ func (d *InputMessageData) CompareToJSONMessage(j *OutputJSONMessage) (errors [] errors = append(errors, fmt.Sprintf("Expected JSON.From=%q, got %q", d.From, j.From)) } - if d.To != j.To { - errors = append(errors, fmt.Sprintf("Expected JSON.To=%q, got %q", d.To, - j.To)) - } if d.Subject != j.Subject { errors = append(errors, fmt.Sprintf("Expected JSON.Subject=%q, got %q", d.Subject, j.Subject)) @@ -237,7 +225,6 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0001", From: "from1", - To: "to1", Subject: "subject 1", Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)), } @@ -245,7 +232,6 @@ func TestRestMailboxList(t *testing.T) { Mailbox: "good", ID: "0002", From: "from2", - To: "to2", Subject: "subject 2", Date: time.Date(2012, 7, 1, 10, 11, 12, 253, time.FixedZone("PDT", -700)), } @@ -359,7 +345,6 @@ func TestRestMessage(t *testing.T) { Mailbox: "good", ID: "0001", From: "from1", - To: "to1", Subject: "subject 1", Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)), Header: mail.Header{ @@ -493,11 +478,6 @@ func (m *MockMessage) From() string { return args.String(0) } -func (m *MockMessage) To() string { - args := m.Called() - return args.String(0) -} - func (m *MockMessage) Date() time.Time { args := m.Called() return args.Get(0).(time.Time) From 8f14ba8359b8c3b17d1807dc6baca2c271566f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wojtun=CC=81?= Date: Tue, 13 Sep 2016 08:19:56 +0200 Subject: [PATCH 4/6] corrected webui/rest_test.go --- webui/rest_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webui/rest_test.go b/webui/rest_test.go index 04301b0..460567c 100644 --- a/webui/rest_test.go +++ b/webui/rest_test.go @@ -478,6 +478,11 @@ func (m *MockMessage) From() string { return args.String(0) } +func (m *MockMessage) To() string { + args := m.Called() + return args.String(0) +} + func (m *MockMessage) Date() time.Time { args := m.Called() return args.Get(0).(time.Time) From 01ea89e7e2e814514fb75c81554c3a333f72cc39 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 18 Sep 2016 13:03:10 -0700 Subject: [PATCH 5/6] Multi-recipient swaks test - Add a multi-recipient test to run-tests.sh - Removal accidental output of jq binary location when pretty-printing REST JSON - Add To: change to CHANGELOG.md - Fix comment typo --- CHANGELOG.md | 3 +++ etc/rest-apiv1.sh | 2 +- smtpd/filestore.go | 4 +--- swaks-tests/run-tests.sh | 9 ++++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ce2e03..b1c157c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). [Unreleased] ------------ +### Added +- Storage of To: header in messages (likely breaks existing datastores) + ### Fixed - We should no longer run out of file handles when dealing with a large number of recipients on a single message. diff --git a/etc/rest-apiv1.sh b/etc/rest-apiv1.sh index 0a30433..880bb99 100755 --- a/etc/rest-apiv1.sh +++ b/etc/rest-apiv1.sh @@ -103,7 +103,7 @@ main() { esac # Use jq to pretty-print if installed and we are expecting JSON output - if [ $pretty ] && [ $is_json ] && type -P jq; then + if [ $pretty ] && [ $is_json ] && type -P jq >/dev/null; then curl -s $curl_opts -H "Accept: application/json" --noproxy "$API_HOST" -X "$method" "$url" | jq . else curl -s $curl_opts -H "Accept: application/json" --noproxy "$API_HOST" -X "$method" "$url" diff --git a/smtpd/filestore.go b/smtpd/filestore.go index a17c5e1..81e3385 100644 --- a/smtpd/filestore.go +++ b/smtpd/filestore.go @@ -344,13 +344,11 @@ func (m *FileMessage) From() string { return m.Ffrom } - -// From returns the value of the Message From header +// From returns the value of the Message To header func (m *FileMessage) To() string { return m.Fto } - // Subject returns the value of the Message Subject header func (m *FileMessage) Subject() string { return m.Fsubject diff --git a/swaks-tests/run-tests.sh b/swaks-tests/run-tests.sh index 62e6bd3..e747dde 100755 --- a/swaks-tests/run-tests.sh +++ b/swaks-tests/run-tests.sh @@ -3,6 +3,7 @@ # description: Generate test emails for Inbucket set -eo pipefail +[ $TRACE ] && set -x # We need to be in swaks-tests directory cmdpath="$(dirname "$0")" @@ -19,6 +20,7 @@ case "$1" in ;; *) to="$1" + shift ;; esac @@ -28,6 +30,10 @@ export SWAKS_OPT_to="$to@inbucket.local" # Basic test swaks $* --h-Subject: "Swaks Plain Text" --body text.txt +# Multi-recipient test +swaks $* --to="$to@inbucket.local,alternate@inbucket.local" --h-Subject: "Swaks Multi-Recipient" \ + --body text.txt + # HTML test swaks $* --h-Subject: "Swaks HTML" --data mime-html.raw @@ -35,7 +41,8 @@ swaks $* --h-Subject: "Swaks HTML" --data mime-html.raw swaks $* --h-Subject: "Swaks Top Level HTML" --data nonmime-html.raw # Attachment test -swaks $* --h-Subject: "Swaks Attachment" --attach-type image/png --attach favicon.png --body text.txt +swaks $* --h-Subject: "Swaks Attachment" --attach-type image/png --attach favicon.png \ + --body text.txt # Encoded subject line test swaks $* --data utf8-subject.raw From 017a0975880b788e827fe42c773ae489f60f29bd Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Wed, 21 Sep 2016 22:12:20 -0700 Subject: [PATCH 6/6] 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 --- rest/apiv1_controller.go | 6 ++--- rest/apiv1_controller_test.go | 4 ++-- rest/testmocks_test.go | 4 ++-- rest/testutils_test.go | 8 ++++--- smtpd/datastore.go | 2 +- smtpd/filestore.go | 23 +++++++++++++++---- smtpd/retention_test.go | 4 ++-- swaks-tests/run-tests.sh | 2 +- themes/bootstrap/templates/mailbox/_show.html | 7 +++++- themes/bootstrap/templates/mailbox/index.html | 8 +++---- webui/rest_test.go | 4 ++-- 11 files changed, 46 insertions(+), 26 deletions(-) diff --git a/rest/apiv1_controller.go b/rest/apiv1_controller.go index 4e1e125..5e5d543 100644 --- a/rest/apiv1_controller.go +++ b/rest/apiv1_controller.go @@ -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(), diff --git a/rest/apiv1_controller_test.go b/rest/apiv1_controller_test.go index d7117ea..9297f88 100644 --- a/rest/apiv1_controller_test.go +++ b/rest/apiv1_controller_test.go @@ -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)), } diff --git a/rest/testmocks_test.go b/rest/testmocks_test.go index a4ce88d..30a46bf 100644 --- a/rest/testmocks_test.go +++ b/rest/testmocks_test.go @@ -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 { diff --git a/rest/testutils_test.go b/rest/testutils_test.go index b4bd701..3d4f86d 100644 --- a/rest/testutils_test.go +++ b/rest/testutils_test.go @@ -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) diff --git a/smtpd/datastore.go b/smtpd/datastore.go index a483852..746be78 100644 --- a/smtpd/datastore.go +++ b/smtpd/datastore.go @@ -36,7 +36,7 @@ type Mailbox interface { type Message interface { ID() string From() string - To() string + To() []string Date() time.Time Subject() string RawReader() (reader io.ReadCloser, err error) diff --git a/smtpd/filestore.go b/smtpd/filestore.go index 81e3385..b40869f 100644 --- a/smtpd/filestore.go +++ b/smtpd/filestore.go @@ -295,7 +295,7 @@ type FileMessage struct { Fid string Fdate time.Time Ffrom string - Fto string + Fto []string Fsubject string Fsize int64 // 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 -func (m *FileMessage) To() string { +func (m *FileMessage) To() []string { return m.Fto } @@ -490,11 +490,24 @@ func (m *FileMessage) Close() error { return err } - // Only public fields are stored in gob - m.Ffrom = body.GetHeader("From") - m.Fto = body.GetHeader("To") + // Only public fields are stored in gob, hence starting with capital F + // Parse From address + 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") + // 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 err = m.mailbox.readIndex() if err != nil { diff --git a/smtpd/retention_test.go b/smtpd/retention_test.go index b7eeb16..1344498 100644 --- a/smtpd/retention_test.go +++ b/smtpd/retention_test.go @@ -126,9 +126,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 { diff --git a/swaks-tests/run-tests.sh b/swaks-tests/run-tests.sh index e747dde..f7c3564 100755 --- a/swaks-tests/run-tests.sh +++ b/swaks-tests/run-tests.sh @@ -31,7 +31,7 @@ export SWAKS_OPT_to="$to@inbucket.local" swaks $* --h-Subject: "Swaks Plain Text" --body text.txt # Multi-recipient test -swaks $* --to="$to@inbucket.local,alternate@inbucket.local" --h-Subject: "Swaks Multi-Recipient" \ +swaks $* --to="$to@inbucket.local,Alt User " --h-Subject: "Swaks Multi-Recipient" \ --body text.txt # HTML test diff --git a/themes/bootstrap/templates/mailbox/_show.html b/themes/bootstrap/templates/mailbox/_show.html index ada6fd8..474e0cf 100644 --- a/themes/bootstrap/templates/mailbox/_show.html +++ b/themes/bootstrap/templates/mailbox/_show.html @@ -53,7 +53,12 @@
From:
{{.message.From}}
To:
-
{{.message.To}}
+
+ {{range $i, $addr := .message.To}} + {{- if $i}},{{end}} + {{$addr -}} + {{end}} +
Date:
{{.message.Date}}
Subject:
diff --git a/themes/bootstrap/templates/mailbox/index.html b/themes/bootstrap/templates/mailbox/index.html index 6644fd4..2059562 100644 --- a/themes/bootstrap/templates/mailbox/index.html +++ b/themes/bootstrap/templates/mailbox/index.html @@ -15,9 +15,9 @@ $(document).ready(function() {