"net/mail"
"os"
"path"
- "strings"
"github.com/uber-go/zap"
}
func (server *smtpServer) maildropForAddress(addr mail.Address) string {
- domainIdx := strings.LastIndex(addr.Address, "@")
- if domainIdx == -1 {
- return ""
- }
-
- domain := addr.Address[domainIdx+1:]
-
+ domain := smtp.DomainForAddress(addr)
for _, s := range server.config.Servers {
if domain == s.Domain {
return s.MaildropPath
"io"
"net"
"net/mail"
+ "strings"
"time"
)
ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
)
+func DomainForAddress(addr mail.Address) string {
+ domainIdx := strings.LastIndex(addr.Address, "@")
+ if domainIdx == -1 {
+ return ""
+ }
+ return addr.Address[domainIdx+1:]
+}
+
type Envelope struct {
RemoteAddr net.Addr
EHLO string
--- /dev/null
+package smtp
+
+import (
+ "net/mail"
+ "testing"
+)
+
+func TestDomainForAddress(t *testing.T) {
+ cases := []struct{
+ address, domain string
+ }{
+ {"foo@bar.com", "bar.com"},
+ {"abc", ""},
+ {"abc@one.two.three.four.net", "one.two.three.four.net"},
+ }
+ for i, c := range cases {
+ actual := DomainForAddress(mail.Address{Address: c.address})
+ if actual != c.domain {
+ t.Errorf("case %d, got %q, expected %q", i, actual, c.domain)
+ }
+ }
+}