1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

Implement VRFY and EXPN commands

We implement the VRFY and EXPN commands, but as no-ops. The RFC allows this,
and most implementations seem to do it this way too.

While at it, merge the tests for simple commands like these into one.
This commit is contained in:
Alberto Bertogli
2016-05-07 01:34:12 +01:00
parent e32ba1ee86
commit 7e7c8073c4
2 changed files with 29 additions and 18 deletions

View File

@@ -325,6 +325,10 @@ loop:
code, msg = c.NOOP(params)
case "RSET":
code, msg = c.RSET(params)
case "VRFY":
code, msg = c.VRFY(params)
case "EXPN":
code, msg = c.EXPN(params)
case "MAIL":
code, msg = c.MAIL(params)
case "RCPT":
@@ -397,8 +401,22 @@ func (c *Conn) RSET(params string) (code int, msg string) {
return 250, msgs[rand.Int()%len(msgs)]
}
func (c *Conn) VRFY(params string) (code int, msg string) {
// 252 can be used for cases like ours, when we don't really want to
// confirm or deny anything.
// See https://tools.ietf.org/html/rfc2821#section-3.5.3.
return 252, "You have a strange feeling for a moment, then it passes."
}
func (c *Conn) EXPN(params string) (code int, msg string) {
// 252 can be used for cases like ours, when we don't really want to
// confirm or deny anything.
// See https://tools.ietf.org/html/rfc2821#section-3.5.3.
return 252, "You feel disoriented for a moment."
}
func (c *Conn) NOOP(params string) (code int, msg string) {
return 250, "noooooooooooooooooooop"
return 250, "You hear a faint typing noise."
}
func (c *Conn) MAIL(params string) (code int, msg string) {

View File

@@ -155,30 +155,23 @@ func TestRcptBeforeMail(t *testing.T) {
}
}
func TestHelp(t *testing.T) {
func simpleCmd(t *testing.T, c *smtp.Client, cmd string, expected int) {
if err := c.Text.PrintfLine(cmd); err != nil {
t.Fatalf("Failed to write %s: %v", cmd, err)
}
if _, _, err := c.Text.ReadResponse(expected); err != nil {
t.Errorf("Incorrect %s response: %v", cmd, err)
}
}
func TestSimpleCommands(t *testing.T) {
c := mustDial(t, false)
defer c.Close()
if err := c.Text.PrintfLine("HELP"); err != nil {
t.Fatalf("Failed to write HELP: %v", err)
}
if _, _, err := c.Text.ReadResponse(214); err != nil {
t.Errorf("Incorrect HELP response: %v", err)
}
}
func TestNoop(t *testing.T) {
c := mustDial(t, false)
defer c.Close()
if err := c.Text.PrintfLine("NOOP"); err != nil {
t.Fatalf("Failed to write NOOP: %v", err)
}
if _, _, err := c.Text.ReadResponse(250); err != nil {
t.Errorf("Incorrect NOOP response: %v", err)
}
simpleCmd(t, c, "HELP", 214)
simpleCmd(t, c, "NOOP", 250)
simpleCmd(t, c, "VRFY", 252)
simpleCmd(t, c, "EXPN", 252)
}
func TestReset(t *testing.T) {