diff --git a/.travis.yml b/.travis.yml index b9ea160..c820ee3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,12 @@ language: go sudo: false env: - - DEPLOY_WITH_MAJOR="1.9" + - DEPLOY_WITH_MAJOR="1.10" before_script: - go get github.com/golang/lint/golint go: - - 1.9.x - "1.10" deploy: diff --git a/Makefile b/Makefile index ae01ee8..c5104cc 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ SHELL = /bin/sh -SRC ::= $(shell find . -type f -name '*.go' -not -path "./vendor/*") -PKGS ::= $(shell go list ./... | grep -v /vendor/) +SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*") +PKGS := $(shell go list ./... | grep -v /vendor/) .PHONY: all build clean fmt lint simplify test -commands ::= client inbucket +commands = client inbucket all: clean test lint build diff --git a/pkg/log/logging.go b/pkg/log/logging.go index 89ab7e7..7a73e24 100644 --- a/pkg/log/logging.go +++ b/pkg/log/logging.go @@ -128,7 +128,7 @@ func openLogFile() error { var err error logf, err = os.OpenFile(logfname, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) if err != nil { - return fmt.Errorf("Failed to create %v: %v\n", logfname, err) + return fmt.Errorf("failed to create %v: %v", logfname, err) } golog.SetOutput(logf) Tracef("Opened new logfile") diff --git a/pkg/rest/model/apiv1_model.go b/pkg/rest/model/apiv1_model.go index f2d3e76..1e4f7f0 100644 --- a/pkg/rest/model/apiv1_model.go +++ b/pkg/rest/model/apiv1_model.go @@ -30,6 +30,7 @@ type JSONMessageV1 struct { Attachments []*JSONMessageAttachmentV1 `json:"attachments"` } +// JSONMessageAttachmentV1 contains information about a MIME attachment type JSONMessageAttachmentV1 struct { FileName string `json:"filename"` ContentType string `json:"content-type"` diff --git a/pkg/rest/socketv1_controller.go b/pkg/rest/socketv1_controller.go index 8bbf5a9..5ad2dbf 100644 --- a/pkg/rest/socketv1_controller.go +++ b/pkg/rest/socketv1_controller.go @@ -144,6 +144,8 @@ func (ml *msgListener) Close() { } } +// MonitorAllMessagesV1 is a web handler which upgrades the connection to a websocket and notifies +// the client of all messages received. func MonitorAllMessagesV1( w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Upgrade to Websocket @@ -167,6 +169,8 @@ func MonitorAllMessagesV1( return nil } +// MonitorMailboxMessagesV1 is a web handler which upgrades the connection to a websocket and +// notifies the client of messages received by a particular mailbox. func MonitorMailboxMessagesV1( w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) diff --git a/pkg/storage/file/fmessage.go b/pkg/storage/file/fmessage.go index 8d0fa3d..22de241 100644 --- a/pkg/storage/file/fmessage.go +++ b/pkg/storage/file/fmessage.go @@ -11,8 +11,8 @@ import ( "time" "github.com/jhillyerd/enmime" - "github.com/jhillyerd/inbucket/pkg/storage" "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/storage" ) // FileMessage implements Message and contains a little bit of data about a diff --git a/pkg/storage/file/fstore.go b/pkg/storage/file/fstore.go index 98341d0..7d7dd35 100644 --- a/pkg/storage/file/fstore.go +++ b/pkg/storage/file/fstore.go @@ -12,8 +12,8 @@ import ( "time" "github.com/jhillyerd/inbucket/pkg/config" - "github.com/jhillyerd/inbucket/pkg/storage" "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/storage" "github.com/jhillyerd/inbucket/pkg/stringutil" ) @@ -140,6 +140,7 @@ func (ds *FileDataStore) AllMailboxes() ([]datastore.Mailbox, error) { return mailboxes, nil } +// LockFor returns the RWMutex for this mailbox, or an error. func (ds *FileDataStore) LockFor(emailAddress string) (*sync.RWMutex, error) { name, err := stringutil.ParseMailboxName(emailAddress) if err != nil { diff --git a/pkg/storage/lock.go b/pkg/storage/lock.go index a08dacc..5247702 100644 --- a/pkg/storage/lock.go +++ b/pkg/storage/lock.go @@ -5,8 +5,12 @@ import ( "sync" ) +// HashLock holds a fixed length array of mutexes. This approach allows concurrent mailbox +// access in most cases without requiring an infinite number of mutexes. type HashLock [4096]sync.RWMutex +// Get returns a RWMutex based on the first 12 bits of the mailbox hash. Hash must be a hexidecimal +// string of three or more characters. func (h *HashLock) Get(hash string) *sync.RWMutex { if len(hash) < 3 { return nil diff --git a/pkg/storage/testing.go b/pkg/storage/testing.go index 8e0799c..aa6c3de 100644 --- a/pkg/storage/testing.go +++ b/pkg/storage/testing.go @@ -27,6 +27,7 @@ func (m *MockDataStore) AllMailboxes() ([]Mailbox, error) { return args.Get(0).([]Mailbox), args.Error(1) } +// LockFor mock function returns a new RWMutex, never errors. func (m *MockDataStore) LockFor(name string) (*sync.RWMutex, error) { return &sync.RWMutex{}, nil } diff --git a/pkg/webui/sanitize/html.go b/pkg/webui/sanitize/html.go index 475880f..cd7a7ae 100644 --- a/pkg/webui/sanitize/html.go +++ b/pkg/webui/sanitize/html.go @@ -18,6 +18,7 @@ var ( AllowAttrs("style").Matching(cssSafe).Globally() ) +// HTML sanitizes the provided html, while attempting to preserve inline CSS styling. func HTML(html string) (output string, err error) { output, err = sanitizeStyleTags(html) if err != nil {