Move compilation of allowed_recipients to ConfigLoad()

This has several benefits:
- Configuration errors are caught at startup rather than upon a connection
- recipientChecker() has less work to do for each connection
This commit is contained in:
Jonathon Reinhart
2021-03-14 12:26:40 -04:00
parent a896ab2847
commit 7c0ba34025
2 changed files with 24 additions and 22 deletions

15
main.go
View File

@@ -7,7 +7,6 @@ import (
"net/smtp"
"net/textproto"
"os"
"regexp"
"strings"
"time"
@@ -121,19 +120,13 @@ func senderChecker(peer smtpd.Peer, addr string) error {
}
func recipientChecker(peer smtpd.Peer, addr string) error {
if *allowedRecipients == "" {
if allowedRecipients == nil {
// Any recipient is permitted
return nil
}
re, err := regexp.Compile(*allowedRecipients)
if err != nil {
log.WithFields(logrus.Fields{
"allowed_recipients": *allowedRecipients,
}).WithError(err).Warn("allowed_recipients pattern invalid")
return smtpd.Error{Code: 451, Message: "Bad recipient address"}
}
if re.MatchString(addr) {
if allowedRecipients.MatchString(addr) {
// Permitted by regex
return nil
}