mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
Minor code aesthetic improvements, based on vet+fmt+lint
This patch is the result of running go vet, go fmt -s and the linter, and fixing some of the things they noted/suggested. There shouldn't be any significant logic changes, it's mostly readability improvements.
This commit is contained in:
@@ -235,6 +235,7 @@ func mustReadDir(path string) []os.FileInfo {
|
||||
// We keep them distinct, as policies can differ between them.
|
||||
type SocketMode string
|
||||
|
||||
// Valid socket modes.
|
||||
const (
|
||||
ModeSMTP SocketMode = "SMTP"
|
||||
ModeSubmission SocketMode = "Submission"
|
||||
|
||||
@@ -28,7 +28,7 @@ func main() {
|
||||
|
||||
domain, err := idna.ToASCII(domain)
|
||||
if err != nil {
|
||||
log.Fatal("IDNA conversion failed: %v", err)
|
||||
log.Fatalf("IDNA conversion failed: %v", err)
|
||||
}
|
||||
|
||||
mxs, err := net.LookupMX(domain)
|
||||
|
||||
@@ -74,6 +74,7 @@ type Recipient struct {
|
||||
|
||||
type RType string
|
||||
|
||||
// Valid recipient types.
|
||||
const (
|
||||
EMAIL RType = "(email)"
|
||||
PIPE RType = "(pipe)"
|
||||
@@ -148,7 +149,7 @@ func (v *Resolver) resolve(rcount int, addr string) ([]Recipient, error) {
|
||||
|
||||
rcpts := v.aliases[addr]
|
||||
if len(rcpts) == 0 {
|
||||
return []Recipient{Recipient{addr, EMAIL}}, nil
|
||||
return []Recipient{{addr, EMAIL}}, nil
|
||||
}
|
||||
|
||||
ret := []Recipient{}
|
||||
@@ -285,7 +286,7 @@ func parseFile(domain, path string) (map[string][]Recipient, error) {
|
||||
|
||||
if rawalias[0] == '|' {
|
||||
cmd := strings.TrimSpace(rawalias[1:])
|
||||
aliases[addr] = []Recipient{Recipient{cmd, PIPE}}
|
||||
aliases[addr] = []Recipient{{cmd, PIPE}}
|
||||
} else {
|
||||
rs := []Recipient{}
|
||||
for _, a := range strings.Split(rawalias, ",") {
|
||||
|
||||
@@ -380,8 +380,9 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
|
||||
cmd := exec.CommandContext(ctx, c[0], c[1:]...)
|
||||
cmd.Stdin = bytes.NewReader(item.Data)
|
||||
return cmd.Run(), true
|
||||
}
|
||||
|
||||
} else {
|
||||
// Recipient type is EMAIL.
|
||||
if envelope.DomainIn(rcpt.Address, q.localDomains) {
|
||||
deliverAttempts.Add("email:local", 1)
|
||||
return q.localC.Deliver(item.From, rcpt.Address, item.Data)
|
||||
@@ -407,7 +408,6 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
|
||||
return q.remoteC.Deliver(from, rcpt.Address, item.Data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// countRcpt counts how many recipients are in the given status.
|
||||
func (item *Item) countRcpt(status Recipient_Status) int {
|
||||
|
||||
@@ -47,16 +47,16 @@ func (c *Client) cmd(expectCode int, format string, args ...interface{}) (int, s
|
||||
// It will check the addresses, decide if SMTPUTF8 is needed, and apply the
|
||||
// necessary transformations.
|
||||
func (c *Client) MailAndRcpt(from string, to string) error {
|
||||
from, from_needs, err := c.prepareForSMTPUTF8(from)
|
||||
from, fromNeeds, err := c.prepareForSMTPUTF8(from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
to, to_needs, err := c.prepareForSMTPUTF8(to)
|
||||
to, toNeeds, err := c.prepareForSMTPUTF8(to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
smtputf8Needed := from_needs || to_needs
|
||||
smtputf8Needed := fromNeeds || toNeeds
|
||||
|
||||
cmdStr := "MAIL FROM:<%s>"
|
||||
if ok, _ := c.Extension("8BITMIME"); ok {
|
||||
@@ -102,8 +102,8 @@ func (c *Client) prepareForSMTPUTF8(addr string) (string, bool, error) {
|
||||
user, domain := envelope.Split(addr)
|
||||
|
||||
if !isASCII(user) {
|
||||
return addr, true, &textproto.Error{599,
|
||||
"local part is not ASCII but server does not support SMTPUTF8"}
|
||||
return addr, true, &textproto.Error{Code: 599,
|
||||
Msg: "local part is not ASCII but server does not support SMTPUTF8"}
|
||||
}
|
||||
|
||||
// If it's only the domain, convert to IDNA and move on.
|
||||
@@ -112,8 +112,8 @@ func (c *Client) prepareForSMTPUTF8(addr string) (string, bool, error) {
|
||||
// The domain is not IDNA compliant, which is odd.
|
||||
// Fail with a permanent error, not ideal but this should not
|
||||
// happen.
|
||||
return addr, true, &textproto.Error{599,
|
||||
"non-ASCII domain is not IDNA safe"}
|
||||
return addr, true, &textproto.Error{
|
||||
Code: 599, Msg: "non-ASCII domain is not IDNA safe"}
|
||||
}
|
||||
|
||||
return user + "@" + domain, false, nil
|
||||
|
||||
@@ -17,10 +17,10 @@ func TestIsPermanent(t *testing.T) {
|
||||
err error
|
||||
permanent bool
|
||||
}{
|
||||
{&textproto.Error{499, ""}, false},
|
||||
{&textproto.Error{500, ""}, true},
|
||||
{&textproto.Error{599, ""}, true},
|
||||
{&textproto.Error{600, ""}, false},
|
||||
{&textproto.Error{Code: 499, Msg: ""}, false},
|
||||
{&textproto.Error{Code: 500, Msg: ""}, true},
|
||||
{&textproto.Error{Code: 599, Msg: ""}, true},
|
||||
{&textproto.Error{Code: 600, Msg: ""}, false},
|
||||
{fmt.Errorf("something"), false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
|
||||
@@ -30,9 +30,9 @@ import (
|
||||
|
||||
// Functions that we can override for testing purposes.
|
||||
var (
|
||||
lookupTXT func(domain string) (txts []string, err error) = net.LookupTXT
|
||||
lookupMX func(domain string) (mxs []*net.MX, err error) = net.LookupMX
|
||||
lookupIP func(host string) (ips []net.IP, err error) = net.LookupIP
|
||||
lookupTXT = net.LookupTXT
|
||||
lookupMX = net.LookupMX
|
||||
lookupIP = net.LookupIP
|
||||
)
|
||||
|
||||
// Results and Errors. Note the values have meaning, we use them in headers.
|
||||
|
||||
Reference in New Issue
Block a user