Skip to content

Commit

Permalink
Merge pull request #16 from hxdmp/main
Browse files Browse the repository at this point in the history
fix #15: correctly parse esmtp args on MAIL and RCPT
  • Loading branch information
d--j authored Oct 5, 2023
2 parents 30d4d62 + d824e79 commit 6cc737f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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

0 comments on commit 6cc737f

Please sign in to comment.