make possible #91.

- add strict_sender bool configuration value
- if strict_sender set as true use for outgoing mail only SMTPs with sender matches to from address
This commit is contained in:
Sergey Zonov
2022-10-15 17:32:52 +07:00
parent 42d111695d
commit 5b5f738410
2 changed files with 16 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ var (
allowedUsers = flagset.String("allowed_users", "", "Path to file with valid users/passwords")
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")
// additional flags
_ = flagset.String("config", "", "Path to config file (ini format)")

18
main.go
View File

@@ -163,9 +163,21 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
"uuid": generateUUID(),
})
if *remotesStr == "" && *command == "" {
var envRemotes []*Remote
if *strictSender {
for _, remote := range remotes {
if remote.Sender == env.Sender {
envRemotes = append(envRemotes, remote)
}
}
} else {
envRemotes = remotes
}
if len(envRemotes) == 0 && *command == "" {
logger.Warning("no remote_host or command set; discarding mail")
return nil
return smtpd.Error{Code: 554, Message: "There are no appropriate remote_host or command"}
}
env.AddReceivedLine(peer)
@@ -190,7 +202,7 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
cmdLogger.Info("pipe command successful: " + stdout.String())
}
for _, remote := range remotes {
for _, remote := range envRemotes {
logger = logger.WithField("host", remote.Addr)
logger.Info("delivering mail from peer using smarthost")