2
0
forked from drew/smtprelay

feat: add alias file support

This commit is contained in:
Aivars Sterns
2025-10-29 11:50:30 +02:00
committed by Bernhard Fröhlich
parent 6e9c00e171
commit 7b6be95125
5 changed files with 88 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ var (
allowedSenderStr = flagset.String("allowed_sender", "", "Regular expression for valid FROM EMail addresses")
allowedRecipStr = flagset.String("allowed_recipients", "", "Regular expression for valid TO EMail addresses")
allowedUsers = flagset.String("allowed_users", "", "Path to file with valid users/passwords")
aliasesFile = flagset.String("aliases_file", "", "Path to aliases file")
command = flagset.String("command", "", "Path to pipe command")
remotesStr = flagset.String("remotes", "", "Outgoing SMTP servers")
strictSender = flagset.Bool("strict_sender", false, "Use only SMTP servers with Sender matches to From")
@@ -59,12 +60,27 @@ var (
allowedSender *regexp.Regexp
allowedRecipients *regexp.Regexp
remotes = []*Remote{}
aliasesList = AliasMap{}
)
func localAuthRequired() bool {
return *allowedUsers != ""
}
func setupAliases() {
if *aliasesFile != "" {
aliases := make(AliasMap)
aliases, err := AliasLoadFile(*aliasesFile)
if err != nil {
log.Fatal().
Str("file", *aliasesFile).
Err(err).
Msg("cannot load aliases file")
}
aliasesList = aliases
}
}
func setupAllowedNetworks() {
for _, netstr := range splitstr(*allowedNetsStr, ' ') {
baseIP, allowedNet, err := net.ParseCIDR(netstr)
@@ -240,6 +256,7 @@ func ConfigLoad() {
setupAllowedNetworks()
setupAllowedPatterns()
setupAliases()
setupRemotes()
setupListeners()
setupTimeouts()