]> Cypherpunks repositories - gostls13.git/commitdiff
net/smtp: added Noop to Client
authorHenry <google@mindeco.de>
Wed, 18 Oct 2017 13:30:08 +0000 (15:30 +0200)
committerIan Lance Taylor <iant@golang.org>
Wed, 25 Oct 2017 20:13:18 +0000 (20:13 +0000)
This adds a Noop() function to the net/stmp client.

It allows for testing if a connaction is still healthy.

Fixes #22321

Change-Id: I023b613b1536ea21274cc36d41f5720c9bbdecbc
Reviewed-on: https://go-review.googlesource.com/71650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/smtp/smtp.go
src/net/smtp/smtp_test.go

index bf574aece1cfd15a70da3ede344c6a47df4c98c6..3488e947a3401dc4dab587c3b806bba2c7d42ed4 100644 (file)
@@ -398,6 +398,16 @@ func (c *Client) Reset() error {
        return err
 }
 
+// Noop sends the NOOP command to the server. It does nothing but check
+// that the connaction to the server is okay.
+func (c *Client) Noop() error {
+       if err := c.hello(); err != nil {
+               return err
+       }
+       _, _, err := c.cmd(250, "NOOP")
+       return err
+}
+
 // Quit sends the QUIT command and closes the connection to the server.
 func (c *Client) Quit() error {
        if err := c.hello(); err != nil {
index 9e7ed78f3655faed89417431956e7c6687999113..e050e2a9fa1e9f91fba019bf68c4f0d05360c23b 100644 (file)
@@ -478,6 +478,8 @@ func TestHello(t *testing.T) {
                                        t.Errorf("Want error, got none")
                                }
                        }
+               case 9:
+                       err = c.Noop()
                default:
                        t.Fatalf("Unhandled command")
                }
@@ -510,6 +512,7 @@ var helloServer = []string{
        "250 Reset ok\n",
        "221 Goodbye\n",
        "250 Sender ok\n",
+       "250 ok\n",
 }
 
 var baseHelloClient = `EHLO customhost
@@ -526,6 +529,7 @@ var helloClient = []string{
        "RSET\n",
        "QUIT\n",
        "VRFY test@example.com\n",
+       "NOOP\n",
 }
 
 func TestSendMail(t *testing.T) {