aboutsummaryrefslogtreecommitdiff
path: root/mta_recv.go
diff options
context:
space:
mode:
Diffstat (limited to 'mta_recv.go')
-rw-r--r--mta_recv.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/mta_recv.go b/mta_recv.go
index fe6139f..d5a14ed 100644
--- a/mta_recv.go
+++ b/mta_recv.go
@@ -5,6 +5,8 @@ import (
"bytes"
"slices"
"strings"
+
+ "go.lindenii.runxiyu.org/lindenii-common/mailkit"
)
type server_state_t uint
@@ -17,7 +19,13 @@ const (
)
func handle_incoming_server_connection(reader *bufio.Reader, writer *bufio.Writer) error {
- _, _ = writer.WriteString("220 " + config.Server_name + " " + VERSION + "\r\n")
+ var my_server_name string
+ var routes map[string]string
+ config_consistent_run(func() {
+ my_server_name = config.Server_name
+ routes = config.Routes
+ })
+ _, _ = writer.WriteString("220 " + my_server_name + " " + VERSION + "\r\n")
_ = writer.Flush()
server_state := server_state_begin
var remote_server_name string
@@ -51,7 +59,7 @@ func handle_incoming_server_connection(reader *bufio.Reader, writer *bufio.Write
remote_server_name = param
_ = remote_server_name // TODO
server_state = server_state_helo
- _, _ = writer.WriteString("250 " + config.Server_name + "\r\n")
+ _, _ = writer.WriteString("250 " + my_server_name + "\r\n")
_ = writer.Flush()
case "MAIL":
switch server_state {
@@ -88,7 +96,14 @@ func handle_incoming_server_connection(reader *bufio.Reader, writer *bufio.Write
_ = writer.Flush()
break
}
- current_rcpt_to = append(current_rcpt_to, param[len("TO:"):])
+ recipient, _, _ := mailkit.Strip_angle_brackets(param[len("TO:"):])
+ _, ok := routes[recipient]
+ if !ok {
+ _, _ = writer.WriteString("550 5.1.1 <" + recipient + ">: Recipient address rejected: User unknown in local recipient table\r\n")
+ _ = writer.Flush()
+ break switch_cmd
+ }
+ current_rcpt_to = append(current_rcpt_to, recipient)
server_state = server_state_rcpt
_, _ = writer.WriteString("250 2.1.5 Ok\r\n")
_ = writer.Flush()
@@ -129,11 +144,24 @@ func handle_incoming_server_connection(reader *bufio.Reader, writer *bufio.Write
if err != nil {
return err
}
- err = deliver_incoming(current_mail_from, current_rcpt_to, current_data)
+ {
+ inboxes_to_deliver_to := make(map[string]struct{})
+ for _, recipient := range current_rcpt_to {
+ inbox, ok := routes[recipient]
+ if !ok {
+ _, _ = writer.WriteString("550 5.1.1 <" + recipient + ">: Recipient address rejected: User unknown in local recipient table\r\n")
+ break switch_cmd
+ }
+ inboxes_to_deliver_to[inbox] = struct{}{}
+ }
+ for inbox := range inboxes_to_deliver_to {
+ err = deliver_incoming(current_mail_from, current_rcpt_to, current_data, inbox)
+ }
+ }
if err == nil {
_, _ = writer.WriteString("250 2.0.0 Ok: Accepted\r\n")
} else {
- _, _ = writer.WriteString("500 2.0.0 Error: "+err.Error()+"\r\n")
+ _, _ = writer.WriteString("500 2.0.0 Error: " + err.Error() + "\r\n")
}
_ = writer.Flush()
server_state = server_state_helo