Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XOORG Server Support #268

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ func (c *Conn) handleGreet(enhanced bool, arg string) {
if c.server.EnableDSN {
caps = append(caps, "DSN")
}
if c.server.EnableXOORG {
caps = append(caps, "XOORG")
}
if c.server.MaxMessageBytes > 0 {
caps = append(caps, fmt.Sprintf("SIZE %v", c.server.MaxMessageBytes))
} else {
Expand Down Expand Up @@ -339,6 +342,12 @@ func (c *Conn) handleMail(arg string) {
}

opts.Size = int64(size)
case "XOORG":
if !c.server.EnableXOORG {
c.writeResponse(504, EnhancedCode{5, 5, 4}, "EnableXOORG is not implemented")
return
}
opts.XOORG = value
case "SMTPUTF8":
if !c.server.EnableSMTPUTF8 {
c.writeResponse(504, EnhancedCode{5, 5, 4}, "SMTPUTF8 is not implemented")
Expand Down
4 changes: 4 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ type Server struct {
// Should be used only if backend supports it.
EnableDSN bool

// Advertise XOORG capability.
// Should be used only if backend supports it.
EnableXOORG bool

// The server backend.
Backend Backend

Expand Down
44 changes: 44 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,47 @@ func TestServerDSNwithSMTPUTF8(t *testing.T) {
t.Fatal("Invalid ORCPT address:", val)
}
}

func TestServerXOORG(t *testing.T) {
be, s, c, scanner, caps := testServerEhlo(t,
func(s *smtp.Server) {
s.EnableXOORG = true
})
defer s.Close()
defer c.Close()

for _, cap := range []string{"XOORG"} {
if _, ok := caps[cap]; !ok {
t.Fatal("Missing capability:", cap)
}
}

io.WriteString(c, "MAIL FROM:<[email protected]> XOORG=test.com\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid MAIL response:", scanner.Text())
}

io.WriteString(c, "RCPT TO:<[email protected]>\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid RCPT response:", scanner.Text())
}

// go on as usual
io.WriteString(c, "DATA\r\n")
scanner.Scan()
io.WriteString(c, "Hey <3\r\n")
io.WriteString(c, ".\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid DATA response:", scanner.Text())
}
if len(be.messages) != 0 || len(be.anonmsgs) != 1 {
t.Fatal("Invalid number of sent messages:", be.messages, be.anonmsgs)
}

if val := be.anonmsgs[0].Opts.XOORG; val != "test.com" {
t.Fatal("Invalid XOORG parameter value:", val)
}
}
3 changes: 3 additions & 0 deletions smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type MailOptions struct {
// Envelope identifier set by the client.
EnvelopeID string

// Accepted Domain from Exchange Online, e.g. from OutgoingConnector
XOORG string

// The authorization identity asserted by the message sender in decoded
// form with angle brackets stripped.
//
Expand Down