1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

chore: resolve error & string related lint warnings (#507)

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-02-20 12:47:27 -08:00
committed by GitHub
parent 5729a212ce
commit 2b174c8b0b
5 changed files with 22 additions and 19 deletions

View File

@@ -70,8 +70,7 @@ func main() {
} }
func baseURL() string { func baseURL() string {
return fmt.Sprintf("http://%s", return "http://%s" + net.JoinHostPort(*host, strconv.FormatUint(uint64(*port), 10))
net.JoinHostPort(*host, strconv.FormatUint(uint64(*port), 10)))
} }
func fatal(msg string, err error) subcommands.ExitStatus { func fatal(msg string, err error) subcommands.ExitStatus {

View File

@@ -2,6 +2,7 @@ package msghub
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"testing" "testing"
@@ -51,7 +52,7 @@ func (l *testListener) Receive(msg event.MessageMetadata) error {
close(l.overflow) close(l.overflow)
} }
if l.errorAfter > 0 && l.gotEvents > l.errorAfter { if l.errorAfter > 0 && l.gotEvents > l.errorAfter {
return fmt.Errorf("Too many messages") return errors.New("too many messages")
} }
return nil return nil
} }

View File

@@ -2,6 +2,7 @@ package policy
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"net" "net"
"net/mail" "net/mail"
@@ -136,7 +137,7 @@ func ParseEmailAddress(address string) (local string, domain string, err error)
return "", "", err return "", "", err
} }
if !ValidateDomainPart(domain) { if !ValidateDomainPart(domain) {
return "", "", fmt.Errorf("domain part validation failed") return "", "", errors.New("domain part validation failed")
} }
return local, domain, nil return local, domain, nil
} }
@@ -240,26 +241,26 @@ func extractDomainMailbox(address string) (string, error) {
// domain part is optional and not validated. // domain part is optional and not validated.
func parseEmailAddress(address string) (local string, domain string, err error) { func parseEmailAddress(address string) (local string, domain string, err error) {
if address == "" { if address == "" {
return "", "", fmt.Errorf("empty address") return "", "", errors.New("empty address")
} }
if len(address) > 320 { if len(address) > 320 {
return "", "", fmt.Errorf("address exceeds 320 characters") return "", "", errors.New("address exceeds 320 characters")
} }
// Remove forward-path routes. // Remove forward-path routes.
if address[0] == '@' { if address[0] == '@' {
end := strings.IndexRune(address, ':') end := strings.IndexRune(address, ':')
if end == -1 { if end == -1 {
return "", "", fmt.Errorf("missing terminating ':' in route specification") return "", "", errors.New("missing terminating ':' in route specification")
} }
address = address[end+1:] address = address[end+1:]
if address == "" { if address == "" {
return "", "", fmt.Errorf("address empty after removing route specification") return "", "", errors.New("address empty after removing route specification")
} }
} }
if address[0] == '.' { if address[0] == '.' {
return "", "", fmt.Errorf("address cannot start with a period") return "", "", errors.New("address cannot start with a period")
} }
// Loop over address parsing out local part. // Loop over address parsing out local part.
@@ -296,7 +297,7 @@ LOOP:
// A single period is OK. // A single period is OK.
if prev == '.' { if prev == '.' {
// Sequence of periods is not permitted. // Sequence of periods is not permitted.
return "", "", fmt.Errorf("sequence of periods is not permitted") return "", "", errors.New("sequence of periods is not permitted")
} }
err = buf.WriteByte(c) err = buf.WriteByte(c)
if err != nil { if err != nil {
@@ -319,7 +320,7 @@ LOOP:
if i == 0 { if i == 0 {
inStringQuote = true inStringQuote = true
} else { } else {
return "", "", fmt.Errorf("quoted string can only begin at start of address") return "", "", errors.New("quoted string can only begin at start of address")
} }
} }
case c == '@': case c == '@':
@@ -332,16 +333,16 @@ LOOP:
} else { } else {
// End of local-part. // End of local-part.
if i > 128 { if i > 128 {
return "", "", fmt.Errorf("local part must not exceed 128 characters") return "", "", errors.New("local part must not exceed 128 characters")
} }
if prev == '.' { if prev == '.' {
return "", "", fmt.Errorf("local part cannot end with a period") return "", "", errors.New("local part cannot end with a period")
} }
domain = address[i+1:] domain = address[i+1:]
break LOOP break LOOP
} }
case c > 127: case c > 127:
return "", "", fmt.Errorf("characters outside of US-ASCII range not permitted") return "", "", errors.New("characters outside of US-ASCII range not permitted")
default: default:
if inCharQuote || inStringQuote { if inCharQuote || inStringQuote {
err = buf.WriteByte(c) err = buf.WriteByte(c)
@@ -356,10 +357,10 @@ LOOP:
prev = c prev = c
} }
if inCharQuote { if inCharQuote {
return "", "", fmt.Errorf("cannot end address with unterminated quoted-pair") return "", "", errors.New("cannot end address with unterminated quoted-pair")
} }
if inStringQuote { if inStringQuote {
return "", "", fmt.Errorf("cannot end address with unterminated string quote") return "", "", errors.New("cannot end address with unterminated string quote")
} }
return buf.String(), domain, nil return buf.String(), domain, nil
} }
@@ -370,7 +371,7 @@ LOOP:
// quoted according to RFC3696. // quoted according to RFC3696.
func parseMailboxName(localPart string) (result string, err error) { func parseMailboxName(localPart string) (result string, err error) {
if localPart == "" { if localPart == "" {
return "", fmt.Errorf("mailbox name cannot be empty") return "", errors.New("mailbox name cannot be empty")
} }
result = strings.ToLower(localPart) result = strings.ToLower(localPart)
invalid := make([]byte, 0, 10) invalid := make([]byte, 0, 10)

View File

@@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@@ -310,7 +311,7 @@ func parseHelloArgument(arg string) (string, error) {
domain = arg[:idx] domain = arg[:idx]
} }
if domain == "" { if domain == "" {
return "", fmt.Errorf("invalid domain") return "", errors.New("invalid domain")
} }
return domain, nil return domain, nil
} }

View File

@@ -2,6 +2,7 @@ package file
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@@ -55,7 +56,7 @@ type Store struct {
func New(cfg config.Storage, extHost *extension.Host) (storage.Store, error) { func New(cfg config.Storage, extHost *extension.Host) (storage.Store, error) {
path := cfg.Params["path"] path := cfg.Params["path"]
if path == "" { if path == "" {
return nil, fmt.Errorf("'path' parameter not specified") return nil, errors.New("'path' parameter not specified")
} }
mailPath := getMailPath(path) mailPath := getMailPath(path)