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

fix #15: correctly parse esmtp args on MAIL and RCPT #16

Merged
merged 2 commits into from
Oct 5, 2023
Merged
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
10 changes: 8 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ func (m *serverSession) Process(msg *wire.Message) (*Response, error) {
m.macros.DelStageAndAbove(StageRcpt)
from := wire.ReadCString(msg.Data)
msg.Data = msg.Data[len(from)+1:]
esmtpArgs := wire.ReadCString(msg.Data)

// the rest of the data are ESMTP arguments, separated by a zero byte.
esmtpArgs := strings.Join(wire.DecodeCStrings(msg.Data), " ")

return m.backend.MailFrom(RemoveAngle(from), esmtpArgs, newModifier(m, true))

case wire.CodeRcpt:
Expand All @@ -221,7 +224,10 @@ func (m *serverSession) Process(msg *wire.Message) (*Response, error) {
m.macros.DelStageAndAbove(StageData)
to := wire.ReadCString(msg.Data)
msg.Data = msg.Data[len(to)+1:]
esmtpArgs := wire.ReadCString(msg.Data)

// the rest of the data are ESMTP arguments, separated by a zero byte.
esmtpArgs := strings.Join(wire.DecodeCStrings(msg.Data), " ")

return m.backend.RcptTo(RemoveAngle(to), esmtpArgs, newModifier(m, true))

case wire.CodeData:
Expand Down
24 changes: 24 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ func Test_milterSession_Process(t *testing.T) {
}
},
}, &wire.Message{wire.CodeMail, []byte{'<', 'r', '>', 0, 'A', '=', 'B', 0}}, cont, false},
{"mail esmtp multi", fields{
backend: &processTestMilter{},
check: func(t *testing.T, s *serverSession) {
p := s.backend.(*processTestMilter)
if p.from != "r" {
t.Errorf("expected r, got %q", p.from)
}
if p.fromEsmtp != "A=B C=D" {
t.Errorf("expected A=B C=D, got %q", p.fromEsmtp)
}
},
}, &wire.Message{wire.CodeMail, []byte{'<', 'r', '>', 0, 'A', '=', 'B', 0, 'C', '=', 'D', 0}}, cont, false},
{"mail err", fields{
backend: &processTestMilter{},
}, &wire.Message{wire.CodeMail, []byte{}}, nil, true},
Expand Down Expand Up @@ -381,6 +393,18 @@ func Test_milterSession_Process(t *testing.T) {
}
},
}, &wire.Message{wire.CodeRcpt, []byte{'<', 'r', '>', 0, 'A', '=', 'B', 0}}, cont, false},
{"rcpt esmtp multi", fields{
backend: &processTestMilter{},
check: func(t *testing.T, s *serverSession) {
p := s.backend.(*processTestMilter)
if p.rcptTo != "r" {
t.Errorf("expected r, got %q", p.rcptTo)
}
if p.rcptEsmtp != "A=B C=D" {
t.Errorf("expected A=B C=D, got %q", p.rcptEsmtp)
}
},
}, &wire.Message{wire.CodeRcpt, []byte{'<', 'r', '>', 0, 'A', '=', 'B', 0, 'C', '=', 'D', 0}}, cont, false},
{"rcpt err", fields{
backend: &processTestMilter{},
}, &wire.Message{wire.CodeRcpt, []byte{}}, nil, true},
Expand Down