From 8b8e57b709aa418d5a2f1b3a0f57543db3e1740a Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 18 Oct 2017 15:30:08 +0200 Subject: [PATCH] net/smtp: added Noop to Client 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/smtp/smtp.go | 10 ++++++++++ src/net/smtp/smtp_test.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/net/smtp/smtp.go b/src/net/smtp/smtp.go index bf574aece1..3488e947a3 100644 --- a/src/net/smtp/smtp.go +++ b/src/net/smtp/smtp.go @@ -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 { diff --git a/src/net/smtp/smtp_test.go b/src/net/smtp/smtp_test.go index 9e7ed78f36..e050e2a9fa 100644 --- a/src/net/smtp/smtp_test.go +++ b/src/net/smtp/smtp_test.go @@ -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) { -- 2.48.1